Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Roadtrip
- import java.util.ArrayList;
- public class RoadTrip
- {
- ArrayList <GeoLocation> location = new ArrayList <GeoLocation>();
- // Create a GeoLocation and add it to the road trip
- public void addStop(String name, double latitude, double longitude)
- {
- GeoLocation g = new GeoLocation(name,latitude,longitude);
- location.add(g);
- }
- // Get the total number of stops in the trip
- public int getNumberOfStops()
- {
- return location.size();
- }
- // Get the total miles of the trip
- public double getTripLength()
- {
- double miles = 0;
- for(int i = 0; i<location.size() - 1; i++)
- {
- miles = miles + (location.get(i)).distanceFrom(location.get(i+1));
- }
- return miles;
- }
- // Return a formatted toString of the trip
- public String toString()
- {
- String s = "";
- for(int i = 0; i<location.size(); i++)
- {
- s = s + (i+1) + "." + " " + (location.get(i)).toString() + "\n";
- }
- return s;
- }
- }
- //Ticket Organizer (Airline Tickets)
- import java.util.ArrayList;
- public class TicketOrganizer
- {
- private ArrayList<AirlineTicket> tickets;
- public TicketOrganizer(ArrayList<AirlineTicket> array)
- {
- tickets = array;
- }
- public int getTickets()
- {
- return tickets.size();
- }
- public void printPassengersByBoardingGroup()
- {
- System.out.println("Boarding Group 1:");
- for(int i = 0; i <= tickets.size() - 1; i++)
- {
- if(tickets.get(i).getBoardingGroup() == 1)
- {
- System.out.println("Passenger " + (i + 1));
- }
- }
- System.out.println("Boarding Group 2:");
- for(int i = 0; i <= tickets.size() - 1; i++)
- {
- if(tickets.get(i).getBoardingGroup() == 2)
- {
- System.out.println("Passenger " + (i + 1));
- }
- }
- System.out.println("Boarding Group 3:");
- for(int i = 0; i <= tickets.size() - 1; i++)
- {
- if(tickets.get(i).getBoardingGroup() == 3)
- {
- System.out.println("Passenger " + (i + 1));
- }
- }
- System.out.println("Boarding Group 4:");
- for(int i = 0; i <= tickets.size() - 1; i++)
- {
- if(tickets.get(i).getBoardingGroup() == 4)
- {
- System.out.println("Passenger " + (i + 1));
- }
- }
- System.out.println("Boarding Group 5:");
- for(int i = 0; i <= tickets.size() - 1; i++)
- {
- if(tickets.get(i).getBoardingGroup() == 5)
- {
- System.out.println("Passenger " + (i + 1));
- }
- }
- }
- public void canBoardTogether()
- {
- for(int i = 0; i < tickets.size() - 1; i++)
- {
- if(tickets.get(i).getRow() == tickets.get(i + 1).getRow() && tickets.get(i).getBoardingGroup() == tickets.get(i).getBoardingGroup())
- {
- System.out.println("Passenger " + i + " can board with Passenger " + (i + 1));
- }
- else
- {
- System.out.println("There are no passengers with the same row and boarding group.");
- break;
- }
- }
- }
- }
- //Billboard
- import java.util.ArrayList;
- public class Billboard
- {
- private ArrayList<Musician> top10 = new ArrayList<Musician>();
- public void replace(Musician musician)
- {
- int least = 0;
- for(int i = 1; i < top10.size(); i++)
- {
- if(top10.get(i).getWeeksInTop40() < top10.get(least).getWeeksInTop40())
- {
- least = i;
- }
- }
- if(top10.get(least).getWeeksInTop40() < musician.getWeeksInTop40())
- {
- String b = top10.get(least).getName();
- top10.remove(least);
- top10.add(least, musician);
- System.out.println("The musician " + b + " has been replaced by " + musician.getName() + ".");
- }
- else
- {
- System.out.println("Sorry, " + musician.getName() + " has less weeks in the Top 40 than the other musicians.");
- }
- }
- public void add(Musician musician)
- {
- if(musician.getIsPlatinum())
- {
- if(top10.size() < 10)
- {
- top10.add(musician);
- }
- else
- {
- replace(musician);
- }
- }
- else
- {
- System.out.println("Sorry, " + musician.getName() + " does not qualify for Top 10");
- }
- }
- //Don't make alterations to this method!
- public void printTop10()
- {
- System.out.println(top10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement