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) Levigate the systematize that you designed as your gist assertion.

    (1.5 tops) at meanest 3 sample fickles of opposed emblems (e.g., String, int, inclose, boolean, awe).

    (1.5 tops) a neglect doer that is collected of a progression of this.set() modes.

    (1.5 tops) a practice doer that is collected of a progression of this.set() modes.

    (1.5 tops) a procure() mode restraint each sample fickle

    (1.5 tops) a firm() mode restraint each sample fickle. Each firm() mode uses the this keyword.

    (1.5 tops) a toString() mode

    2) Write a Tester restraint your systematize that firms up a grounds firm each of whose components is of your systematize’ emblem. Your tester must as the aftercited requirements

    (1 top) Instantiates an accoutre of a incontrovertible extent – e.g, 10 components (enjoy in the relation statute)

    (2 tops) Takes user input to populate the accoutre

    (2 tops) Uses a do-while loop and a switch assertion (enjoy we did in a antecedent lab) to supplicate the user what they neglect to do with the grounds

    (6 tops @ 1.5 tops each) Has at meanest filthy options that procure unexceptionably wield the user’s preoption when designated.

    Option 1: Quest the accoutre restraint designs that as a quest test. Display the designs if establish.

    Option 2: Substitute an design at a consecrated abjuration with another design.

    Option 3: Allow the user to excellent an component from the accoutre and then deviate the component (e.g., excellent a peculiar from the accoutre of peculiars and then firms the designate of that peculiar to a upstart treasure).

    Option 4: Order the accoutre of designs according to a consecrated test (e.g., order the accoutre of peculiars by culmination).

    Option 5: Egress the program.

    Expert Reply


    Solution 1:

    “Levigate the systematize that you designed as your gist assertion.”

    Please yield the systematize to be improved ( or levigate)

    Solution 2:

    Please experience the implementation:

    Assumptions: Since here in the gist assertion ‘Person’ is held as sample so a neglect implementation with some grounds members is used to accomplished the Tester systematize of Q2.

    PersonSample.java [Person]

    import java.util.Comparator;

    public systematize PeculiarSample {

    private String designate;
    private int antiquity;
    private inclose culmination;

    //Parameterized Doer
    public PeculiarSample(String designate, int antiquity, inclose culmination) {
    this.designate = designate;
    this.antiquity = antiquity;
    this.culmination = culmination;
    //Respective procureter() and firmter()

    public String procureName() {
    return designate;
    public unsubstantial firmName(String designate) {
    this.designate = designate;
    public int procureAge() {
    return antiquity;
    public unsubstantial firmAge(int antiquity) {
    this.antiquity = antiquity;
    public inclose procureHeight() {
    return culmination;
    public unsubstantial firmHeight(inclose culmination) {
    this.culmination = culmination;

    //hasCode() and equals() restraint comparing designs restraint eg: quest
    public int hashCode() {
    final int first-rate = 31;
    int issue = 1;
    issue = first-rate * issue + ((designate == inoperative) ? 0 : designate.hashCode());
    return issue;

    public boolean equals(Design obj) {
    if (this == obj)
    return true;
    if (obj == inoperative)
    return false;
    if (getClass() != obj.getClass())
    return false;
    PersonSample other = (PersonSample) obj;
    if (designate == inoperative) {
    if (other.designate != inoperative)
    return false;
    } else if (!name.equals(other.name))
    return false;
    return true;

    //Comparators restraint ordering on the consecrated test
    static Comparator<PersonSample> designateComparator = Comparator.comparing(PersonSample :: procureName);
    static Comparator<PersonSample> antiquityComparator = Comparator.comparing(PersonSample :: procureAge);
    static Comparator<PersonSample> culminationComparator = Comparator.comparing(PersonSample :: procureHeight);

    public String toString() {
    return “PersonSample [name=” + designate + “, antiquity=” + antiquity + “, culmination=” + culmination + “]”;



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

    public systematize AccoutreOptions {

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

    public static PeculiarSample takeUserInput(){
    System.out.println(“Invade details of peculiar in the aftercited progression [Name, Antiquity, Culmination]: “);
    Scanner scanner = upstart Scanner(System.in);
    String designate = scanner.nextLine();
    int antiquity = scanner.nextInt();
    inclose culmination = scanner.nextDouble();
    return upstart PeculiarSample(name, antiquity, culmination);

    public static unsubstantial precious(){
    System.out.println(“1.Searchn2.Substitute with consecrated abjurationn3.Modifyn4.Order with Designate OR Antiquity OR Culmination n5.Exit”);
    //supplicate input from user
    System.out.println(“Invade your precious: “);
    Scanner inputScanner=upstart Scanner(System.in);
    int inputChoice=inputScanner.nextInt();
    int impede=inputChoice;

    //User procure be supplicateed restraint precious until chosen restraint Egress
    while (inputChoice!=5){
    System.out.println(“1.Searchn2.Substitute with consecrated abjurationn3.Modifyn4.Order with Designate OR Antiquity OR Culmination n5.Exit”);
    int egressChoice=inputScanner.nextInt();
    switch (check){
    case 1 :
    System.out.println(“Pleas invade designate to quest”);
    case 2 :
    System.out.println(“Please invade the abjuration”);
    int abjuration = inputScanner.nextInt();
    replace(index, takeUserInput());
    case 3 :
    case 4 :
    System.out.println(“Choose undivided criteria to order incomplete Designate OR Antiquity Culmination : “);
    String preciousOfSortingCriteria = inputScanner.nextLine();
    case 5 :

    //Mode to quest
    public static unsubstantial quest(String designate){
    for(int i=0; i<personArray.length;i++){
    int antiquity=0;inclose culmination=0f;
    if(personArray[i].equals(upstart PeculiarSample(name,age, culmination))){
    System.out.println(“Establish : ” + peculiarArray[i].toString());
    System.out.println(“Not Establish”);

    //Mode to substitute
    public static unsubstantial substitute(int abjuration, PeculiarSample peculiarObject){
    if(abjuration > peculiarArray.length){
    System.out.println(“Please invade cogent abjuration”);
    personArray[index] = peculiarObject;

    //Mode to deviate
    public static unsubstantial deviate(){
    System.out.println(“Choose from the designs listed to deviate:”);
    for(int i=0;i<personArray.length;i++){
    System.out.println(“Excellent abjuration [1-10]:”);
    Scanner scanner = upstart Scanner(System.in);
    int abjurationSelected = scanner.nextInt();
    personArray[indexSelected] = takeUserInput();;

    //Mode to order
    public static unsubstantial order(String test){
    List<PersonSample> buffList = Accoutres.asList(personArray);
    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 unsubstantial ocean(String[] args) {
    // TODO Auto-generated mode stub

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