Question: 13 - 23 - ARRAYS AND ARRAYLISTS ... 1 public class Candidate 2.1 3 //STATIC VARIABLES 4 private static int candidates - @; //Total #

13 - 23 - ARRAYS AND ARRAYLISTS ... 1 public class Candidate 2.1 3 //STATIC VARIABLES 4 private static int candidates - @; //Total # of candidates 5 private static double ratings - 0; //Sum of all ratings 6 7 //Fields 8 private String name; 9 private int age; 10 private double rating; //Between 0.8 and 108.0 (inclusive) 11 12 public Candidate(String name, int age, double rating) 14 this.name = name; 15 this.age - age; 16 this.rating = rating; 17 18 candidates += 1; 19 ratings += this.rating; 20 } 21 22 public String getName() { 24 return this.name; 25 } 26 27 public int getAge() { 29 return this. age; 30 > 31 32 public double getRating() 33. 34 return this.getRating(); 35 } 36 37 public void increaseRating(double amt) 38 { 39 this.rating + amt; 40 ratings += amt; 41 } 42 43 @Override 44 public String toString() 45 { 46 Strings - this.name.toupperCase(); 47 S + " Age: " + this.age; 48 S + " Rating: + this.rating + " "; 49 return s; 50 } 51 52 53 ) // end class 54 28 - Practice ARRAYS AND ARRAYLISTS ... 1 NOTE: code the solutions. Only code a nethod if it asks you tol 2 3 import java.util.ArrayList; //Done for you! 4 5 1. Create three Candidate objects. Name then ci, c2, c3. 6 7 8 2. Create an ArrayList of Candidate objects. Capacity is 3. 9 Name the pointer 'candidateList. 10 Then, add all three Candidate objects to the ArrayList. 11 12 13 3. Create an array of known Candidate objects (ci, c2 and c3). 14 Name the pointer candidates. One line of code. 15 16 17 4. Swap the positions of ci and c3 in the candidates array. 18 19 20 5. Method: highRatings 21 @param: an array of Candidate objects 22 paran: rating (a double) -- the rating to compare to 23 @return: an ArrayList of Candidate objects 24 It puts all Candidate objects from the array parameter that hava a rating the 25 rating parameter, into an ArrayList, and returns the ArrayList. 26 Could be called like this: ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
