Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. //Roadtrip
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class RoadTrip
  6. {
  7. ArrayList <GeoLocation> location = new ArrayList <GeoLocation>();
  8. // Create a GeoLocation and add it to the road trip
  9. public void addStop(String name, double latitude, double longitude)
  10. {
  11.  
  12. GeoLocation g = new GeoLocation(name,latitude,longitude);
  13. location.add(g);
  14.  
  15. }
  16.  
  17. // Get the total number of stops in the trip
  18. public int getNumberOfStops()
  19. {
  20. return location.size();
  21. }
  22.  
  23. // Get the total miles of the trip
  24. public double getTripLength()
  25. {
  26. double miles = 0;
  27. for(int i = 0; i<location.size() - 1; i++)
  28. {
  29. miles = miles + (location.get(i)).distanceFrom(location.get(i+1));
  30. }
  31. return miles;
  32. }
  33.  
  34.  
  35. // Return a formatted toString of the trip
  36. public String toString()
  37. {
  38. String s = "";
  39. for(int i = 0; i<location.size(); i++)
  40. {
  41. s = s + (i+1) + "." + " " + (location.get(i)).toString() + "\n";
  42. }
  43. return s;
  44. }
  45. }
  46.  
  47.  
  48. //Ticket Organizer (Airline Tickets)
  49.  
  50. import java.util.ArrayList;
  51.  
  52. public class TicketOrganizer
  53. {
  54. private ArrayList<AirlineTicket> tickets;
  55.  
  56. public TicketOrganizer(ArrayList<AirlineTicket> array)
  57. {
  58. tickets = array;
  59. }
  60.  
  61. public int getTickets()
  62. {
  63. return tickets.size();
  64. }
  65.  
  66. public void printPassengersByBoardingGroup()
  67. {
  68. System.out.println("Boarding Group 1:");
  69. for(int i = 0; i <= tickets.size() - 1; i++)
  70. {
  71. if(tickets.get(i).getBoardingGroup() == 1)
  72. {
  73.  
  74. System.out.println("Passenger " + (i + 1));
  75. }
  76. }
  77. System.out.println("Boarding Group 2:");
  78. for(int i = 0; i <= tickets.size() - 1; i++)
  79. {
  80. if(tickets.get(i).getBoardingGroup() == 2)
  81. {
  82.  
  83. System.out.println("Passenger " + (i + 1));
  84. }
  85. }
  86. System.out.println("Boarding Group 3:");
  87. for(int i = 0; i <= tickets.size() - 1; i++)
  88. {
  89. if(tickets.get(i).getBoardingGroup() == 3)
  90. {
  91.  
  92. System.out.println("Passenger " + (i + 1));
  93. }
  94. }
  95. System.out.println("Boarding Group 4:");
  96. for(int i = 0; i <= tickets.size() - 1; i++)
  97. {
  98. if(tickets.get(i).getBoardingGroup() == 4)
  99. {
  100.  
  101. System.out.println("Passenger " + (i + 1));
  102. }
  103. }
  104. System.out.println("Boarding Group 5:");
  105. for(int i = 0; i <= tickets.size() - 1; i++)
  106. {
  107. if(tickets.get(i).getBoardingGroup() == 5)
  108. {
  109.  
  110. System.out.println("Passenger " + (i + 1));
  111. }
  112. }
  113. }
  114.  
  115. public void canBoardTogether()
  116. {
  117. for(int i = 0; i < tickets.size() - 1; i++)
  118. {
  119. if(tickets.get(i).getRow() == tickets.get(i + 1).getRow() && tickets.get(i).getBoardingGroup() == tickets.get(i).getBoardingGroup())
  120. {
  121. System.out.println("Passenger " + i + " can board with Passenger " + (i + 1));
  122. }
  123. else
  124. {
  125. System.out.println("There are no passengers with the same row and boarding group.");
  126. break;
  127. }
  128. }
  129. }
  130. }
  131.  
  132. //Billboard
  133. import java.util.ArrayList;
  134. public class Billboard
  135. {
  136. private ArrayList<Musician> top10 = new ArrayList<Musician>();
  137.  
  138. public void replace(Musician musician)
  139. {
  140. int least = 0;
  141. for(int i = 1; i < top10.size(); i++)
  142. {
  143. if(top10.get(i).getWeeksInTop40() < top10.get(least).getWeeksInTop40())
  144. {
  145. least = i;
  146. }
  147. }
  148. if(top10.get(least).getWeeksInTop40() < musician.getWeeksInTop40())
  149. {
  150. String b = top10.get(least).getName();
  151. top10.remove(least);
  152. top10.add(least, musician);
  153. System.out.println("The musician " + b + " has been replaced by " + musician.getName() + ".");
  154. }
  155. else
  156. {
  157. System.out.println("Sorry, " + musician.getName() + " has less weeks in the Top 40 than the other musicians.");
  158. }
  159. }
  160.  
  161. public void add(Musician musician)
  162. {
  163. if(musician.getIsPlatinum())
  164. {
  165. if(top10.size() < 10)
  166. {
  167. top10.add(musician);
  168. }
  169. else
  170. {
  171. replace(musician);
  172. }
  173. }
  174. else
  175. {
  176. System.out.println("Sorry, " + musician.getName() + " does not qualify for Top 10");
  177. }
  178.  
  179.  
  180. }
  181.  
  182.  
  183.  
  184. //Don't make alterations to this method!
  185. public void printTop10()
  186. {
  187. System.out.println(top10);
  188. }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement