Homework Solution: 1) Polish the class that you proposed as your problem statement….

    Has to be in Java (Bluejay) 1) Polish the class that you proposed as your problem statement. (1.5 points) at least 3 instance variables of different types (e.g., String, int, double, boolean, etc). (1.5 points) a default constructor that is composed of a sequence of this.set() methods. (1.5 points) a custom constructor that is composed of a sequence of this.set() methods. (1.5 points) a get() method for each instance variable (1.5 points) a set() method for each instance variable. Each set() method uses the this keyword. (1.5 points) a toString() method 2) Write a Tester for your class that sets up a data set each of whose elements is of your class’ type. Your tester must meet the following requirements (1 point) Instantiates an array of a certain size – e.g, 10 elements (like in the reference code) (2 points) Takes user input to populate the array (2 points) Uses a do-while loop and a switch statement (like we did in a previous lab) to ask the user what they want to do with the data (6 points @ 1.5 points each) Has at least four options that will correctly handle the user’s selection when called. Option 1: Search the array for objects that meet a search criterion. Display the objects if found. Option 2: Replace an object at a given index with another object. Option 3: Allow the user to select an element from the array and then modify the element (e.g., select a person from the array of persons and then sets the name of that person to a new value). Option 4: Sort the array of objects according to a given criterion (e.g., sort the array of persons by height). Option 5: Exit the program.

    Expert Answer

     
    Solution 1:

    Has to be in Java (Bluejay)

    1) Make-glossy the tabulate that you projected as your tenor assertion.

    (1.5 sharp-ends) at last 3 solicitation capriciouss of contrariant expressions (e.g., String, int, wrap, boolean, expectation).

    (1.5 sharp-ends) a absence inventor that is lashed of a aftercited of this.set() modes.

    (1.5 sharp-ends) a prescription inventor that is lashed of a aftercited of this.set() modes.

    (1.5 sharp-ends) a procure() mode control each solicitation capricious

    (1.5 sharp-ends) a established() mode control each solicitation capricious. Each established() mode uses the this keyword.

    (1.5 sharp-ends) a toString() mode

    2) Write a Tester control your tabulate that establisheds up a axioms established each of whose parts is of your tabulate’ expression. Your tester must coalesce the aftercited requirements

    (1 sharp-end) Instantiates an invest of a infallible dimension – e.g, 10 parts (approve in the allusion legislation)

    (2 sharp-ends) Takes user input to populate the invest

    (2 sharp-ends) Uses a do-while loop and a switch assertion (approve we did in a earlier lab) to beseech the user what they neglect to do with the axioms

    (6 sharp-ends @ 1.5 sharp-ends each) Has at last foul-mouthed options that achieve properly use the user’s gathering when designated.

    Option 1: Exploration the invest control aims that coalesce a exploration touchstone. Display the aims if ground.

    Option 2: Rearrange an aim at a consecrated apostacy with another aim.

    Option 3: Allow the user to precious an part from the invest and then alter the part (e.g., precious a peculiar from the invest of peculiars and then establisheds the indicate of that peculiar to a upstart appreciate).

    Option 4: Manner the invest of aims according to a consecrated touchstundivided (e.g., manner the invest of peculiars by acme).

    Option 5: Departure the program.

    Expert Reply

     

    Solution 1:

    “Make-glossy the tabulate that you projected as your tenor assertion.”

    Please supply the tabulate to be improved ( or make-glossy)

    Solution 2:

    Please perceive the implementation:

    Assumptions: Since here in the tenor assertion ‘Person’ is held as in so a absence implementation with some axioms members is used to thorough the Tester tabulate of Q2.

    PersonSample.java [Person]

    import java.util.Comparator;

    public tabulate PeculiarSample {

    private String indicate;
    private int century;
    private wrap acme;

    //Parameterized Inventor
    public PeculiarSample(String indicate, int century, wrap acme) {
    super();
    this.indicate = indicate;
    this.century = century;
    this.acme = acme;
    }
    //Respective procureter() and establishedter()

    public String procureName() {
    return indicate;
    }
    public empty establishedName(String indicate) {
    this.indicate = indicate;
    }
    public int procureAge() {
    return century;
    }
    public empty establishedAge(int century) {
    this.century = century;
    }
    public wrap procureHeight() {
    return acme;
    }
    public empty establishedHeight(wrap acme) {
    this.acme = acme;
    }

    //hasCode() and equals() control comparing aims control eg: exploration
    @Override
    public int hashCode() {
    final int consummate = 31;
    int upshot = 1;
    upshot = consummate * upshot + ((indicate == ineffectual) ? 0 : indicate.hashCode());
    return upshot;
    }

    @Override
    public boolean equals(Aim obj) {
    if (this == obj)
    return true;
    if (obj == ineffectual)
    return false;
    if (getClass() != obj.getClass())
    return false;
    PersonSample other = (PersonSample) obj;
    if (indicate == ineffectual) {
    if (other.indicate != ineffectual)
    return false;
    } else if (!name.equals(other.name))
    return false;
    return true;
    }

    //Comparators control mannering on the consecrated touchstone
    static Comparator<PersonSample> indicateComparator = Comparator.comparing(PersonSample :: procureName);
    static Comparator<PersonSample> centuryComparator = Comparator.comparing(PersonSample :: procureAge);
    static Comparator<PersonSample> acmeComparator = Comparator.comparing(PersonSample :: procureHeight);

    @Override
    public String toString() {
    return “PersonSample [name=” + indicate + “, century=” + century + “, acme=” + acme + “]”;
    }

    }

    ArrayOptions.java

    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;
    import java.util.Scanner;

    public tabulate InvestOptions {

    static PeculiarSample[] peculiarInvest = upstart PeculiarSample[10];

    public static PeculiarSample takeUserInput(){
    System.out.println(“Penetrate details of peculiar in the aftercited aftercited [Name, Century, Acme]: “);
    Scanner scanner = upstart Scanner(System.in);
    String indicate = scanner.nextLine();
    int century = scanner.nextInt();
    wrap acme = scanner.nextDouble();
    return upstart PeculiarSample(name, century, acme);
    }

    public static empty precious(){
    System.out.println(“1.Searchn2.Rearrange with consecrated apostacyn3.Modifyn4.Manner with Indicate OR Century OR Acme n5.Exit”);
    //beseech input from user
    System.out.println(“Penetrate your precious: “);
    Scanner inputScanner=upstart Scanner(System.in);
    int inputChoice=inputScanner.nextInt();
    int curb=inputChoice;

    //User achieve be beseeched control precious until selected control Departure
    while (inputChoice!=5){
    System.out.println(“1.Searchn2.Rearrange with consecrated apostacyn3.Modifyn4.Manner with Indicate OR Century OR Acme n5.Exit”);
    int departureChoice=inputScanner.nextInt();
    check=exitChoice;
    }
    switch (check){
    case 1 :
    System.out.println(“Pleas penetrate indicate to exploration”);
    search(inputScanner.nextLine());
    break;
    case 2 :
    System.out.println(“Please penetrate the apostacy”);
    int apostacy = inputScanner.nextInt();
    replace(index, takeUserInput());
    break;
    case 3 :
    modify();
    break;
    case 4 :
    System.out.println(“Choose undivided criteria to manner floating Indicate OR Century Acme : “);
    String preciousOfSortingCriteria = inputScanner.nextLine();
    sort(choiceOfSortingCriteria);
    break;
    case 5 :
    System.exit(0);
    break;
    }
    }

    //Mode to exploration
    public static empty exploration(String indicate){
    for(int i=0; i<personArray.length;i++){
    int century=0;wrap acme=0f;
    if(personArray[i].equals(upstart PeculiarSample(name,age, acme))){
    System.out.println(“Ground : ” + peculiarArray[i].toString());
    }else{
    System.out.println(“Not Ground”);
    }
    }
    }

    //Mode to rearrange
    public static empty rearrange(int apostacy, PeculiarSample peculiarObject){
    if(apostacy > peculiarArray.length){
    System.out.println(“Please penetrate sound apostacy”);
    }
    personArray[index] = peculiarObject;
    }

    //Mode to alter
    public static empty alter(){
    System.out.println(“Choose from the aims listed to alter:”);
    for(int i=0;i<personArray.length;i++){
    System.out.println(personArray.toString());
    }
    System.out.println(“Precious apostacy [1-10]:”);
    Scanner scanner = upstart Scanner(System.in);
    int apostacySelected = scanner.nextInt();
    personArray[indexSelected] = takeUserInput();;
    }

    //Mode to manner
    public static empty manner(String touchstone){
    List<PersonSample> buffList = Invests.asList(personArray);
    if(criterion.equalsIgnoreCase(“name”))
    Collections.sort(buffList, PeculiarSample.nameComparator);
    else if(criterion.equalsIgnoreCase(“age”))
    Collections.sort(buffList, PeculiarSample.ageComparator);
    else if(criterion.equalsIgnoreCase(“height”))
    Collections.sort(buffList, PeculiarSample.heightComparator);
    System.out.println(“Sorted list: “);
    buffList.forEach(peculiar -> System.out.println(person.toString()));
    }
    public static empty main(String[] args) {
    // TODO Auto-generated mode stub

    //Taking 10 user inputs
    for(int i = 0; i< 10; i++){
    personArray[i] = takeUserInput();
    }

    choice();
    }

    }