Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. private double time;
  2. private String atheleteName;
  3. private String nationality;
  4. private String date;
  5. private String location;
  6.  
  7. public Runner(double time, String atheleteName, String nationality, String date, String location) {
  8. this.time = time;
  9. this.atheleteName = atheleteName;
  10. this.nationality = nationality;
  11. this.date = date;
  12. this.location = location;
  13. }
  14.  
  15. public double getTime() {
  16. return time;
  17. }
  18.  
  19. public String getAtheleteName() {
  20. return atheleteName;
  21. }
  22.  
  23. public String getNationality() {
  24. return nationality;
  25. }
  26.  
  27. public String getDate() {
  28. return date;
  29. }
  30.  
  31. public String getLocation() {
  32. return location;
  33. }
  34.  
  35. public void setTime(double time) {
  36. this.time = time;
  37. }
  38.  
  39. public void setAtheleteName(String atheleteName) {
  40. this.atheleteName = atheleteName;
  41. }
  42.  
  43. public void setNationality(String nationality) {
  44. this.nationality = nationality;
  45. }
  46.  
  47. public void setDate(String date) {
  48. this.date = date;
  49. }
  50.  
  51. public void setLocation(String location) {
  52. this.location = location;
  53. }
  54.  
  55. public String toString() {
  56. return
  57. time + atheleteName + nationality + date + location;
  58.  
  59. }
  60.  
  61. public static void main(String[] args) {
  62.  
  63. ArrayList<Runner> runners = new ArrayList<>();
  64.  
  65. runners.add(new Runner( 9.58," Usain Bolt "," Jamaica "," 16 August 2009 "," Berlin "));
  66. runners.add(new Runner( 9.69," Tyson Gray "," USA "," 20 September 2009 "," Shanghai "));
  67. runners.add(new Runner( 9.69," Yohan Blake "," Jamaica "," 23 August 2012 "," Lausanne"));
  68. runners.add(new Runner( 9.72," Asafa Powell "," Jamaica "," 02 September 2008 "," Lausanne "));
  69. runners.add(new Runner( 9.78," Nesta Carter "," Jamaica "," 29 August 2010 "," Rieti "));
  70. runners.add(new Runner( 9.79," Maurice Greene "," USA "," 16 June 1999 "," Athens "));
  71. runners.add(new Runner( 9.79," Justin Gatlin "," USA "," 05 August 2012 "," London "));
  72. runners.add(new Runner( 9.80," Steve Mullings "," Jamaica "," 04 June 2011 "," Eugene "));
  73. runners.add(new Runner( 9.84," Donovan Bailey "," Canada "," 27 July 1996 "," Atlanta "));
  74. runners.add(new Runner(9.84," Bruny Surin "," Canada "," 22 August 1999 "," Seville "));
  75. System.out.println("nOriginal Array- ");
  76. System.out.println("");
  77. System.out.println("Time(sec): Name: Nationality: Date: Location:");
  78. System.out.println("---------------------------------------------------------------------------");
  79. printRunners(runners);
  80. updateLocation(runners);
  81. System.out.println("nUpdate Runners- ");
  82. System.out.println("");
  83. System.out.println("Time(sec): Name: Nationality: Date: Location:");
  84. System.out.println("---------------------------------------------------------------------------");
  85. printRunners(runners);
  86. insertName(runners,10.49," Florence (G.) Joyner ","USA "," 06 July 1988 "," Indianapolis, Indiana ");
  87. System.out.println("nUpdate Runners- ");
  88. System.out.println("");
  89. System.out.println("Time(sec): Name: Nationality: Date: Location:");
  90. System.out.println("---------------------------------------------------------------------------");
  91. printRunners(runners);
  92. replaceName(runners," Bruny Surin "," Carl Lewis ", 9.86 ," USA "," 23 August 1991 "," Tokyo, Japan ");
  93. System.out.println("nUpdate Runners- ");
  94. System.out.println("");
  95. System.out.println("Time(sec): Name: Nationality: Date: Location:");
  96. System.out.println("---------------------------------------------------------------------------");
  97. printRunners(runners);
  98.  
  99. }
  100.  
  101. public static void printRunners(ArrayList<Runner> runners){
  102. for(Runner runner:runners)
  103. System.out.println(runner);
  104. }
  105.  
  106. public static void updateLocation(ArrayList<Runner> runners){
  107. for(Runner runner : runners){
  108. if(runner.getLocation().equalsIgnoreCase("Berlin")){
  109. runner.setLocation("Berlin, Germany");
  110. }else if(runner.getLocation().equalsIgnoreCase("Shanghai")){
  111. runner.setLocation("Shanghai, China");
  112. }else if(runner.getLocation().equalsIgnoreCase("London")){
  113. runner.setLocation("London, England");
  114. }else if(runner.getLocation().equalsIgnoreCase("Athens")){
  115. runner.setLocation("Athens, Greece");
  116. } else if(runner.getLocation().equalsIgnoreCase("Eugene")){
  117. runner.setLocation("Eugene, South Africa");
  118. } else if(runner.getLocation().equalsIgnoreCase("Seville")){
  119. runner.setLocation("Seville, France");
  120. }else if(runner.getLocation().equalsIgnoreCase("Lausanne")){
  121. runner.setLocation("Lausanne, Spain");
  122. }else if(runner.getLocation().equalsIgnoreCase("Rieti")){
  123. runner.setLocation("Rieti, Australia");
  124. }else if(runner.getLocation().equalsIgnoreCase("Atlanta")){
  125. runner.setLocation("Atlanta, USA");
  126. }
  127. }
  128. }
  129.  
  130. public static void insertName(ArrayList<Runner> runners, double time, String atheleteName, String nationality, String date, String location){
  131. Runner runner = new Runner(time,atheleteName,nationality,date,location);
  132. runners.add(runner);
  133. }
  134.  
  135. public static void replaceName(ArrayList<Runner> runners, String searchName, String replaceName, double time, String nationality, String date, String location){
  136. for(Runner runner: runners){
  137. if(runner.getAtheleteName().equalsIgnoreCase(searchName)){
  138. runner.setTime(time);
  139. runner.setAtheleteName(replaceName);
  140. runner.setNationality(nationality);
  141. runner.setDate(date);
  142. runner.setLocation(location);
  143. }
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement