Write down in you own word what the task at hand is and then write it from top-down in pseudo code. Only then start to code.
E.g.
menu:
forever do
display menu
ask for selection
stop if end selected
do the selected action
end
The needed data structures:
class travel:
field: route
field: ship
field: captain
field: price_first_class
field: price_second_class
field: passengers_first_class
field: passengers_second_class
method: static read_from_file(file) returns new travel or null
method: static read_from_keyboard() returns new travel or null
method: display() to console
end
class maritime_station:
field: travels (container for max 25 travel elements)
method: reset()
method: read_from_file(path)
method: read_from_keyboard()
method: add(travel)
method: display() to console
method: display_filtered(predicate) to console
end
Some implementations:
method maritime_station::read_from_file(path)
file = open(path for read)
forever do
travel = travel::read_from_file(file)
if travel equals null, then go to end loop
add(travel)
end loop
close(file)
end
method maritime_station::read_from_keyboard()
forever do
travel = travel::read_from_keyboard()
if travel equals null, then go to end loop
add(travel)
end loop
end
method maritime_station::display_filtered(predicate)
foreach travel in travels do
if predicate(travel) travel.display()
end loop
end
method maritime_station::display()
foreach travel in travels do
travel.display()
end loop
end
Cheers
Andi