Homework Solution: Write the class whose diagram is shown below and write a driver program (progressively developed) to test the class…

    Write the class whose diagram is shown below and write a driver program (progressively developed) to test the class (verify that all the methods function properly). The default (no-parameter constructor) should initialize the String data member name to " " and numeric data member to zero. The input method should allow the user to input the values of an object's data members. Listing String name int age + Listing() + Listing (String, int) + string toString(O) + void input () + void setName (String) + void setAge (String) + String getName (O + int getAge ( ) Then code the definition of the class whose diagram follows. The constructors should allocate the array(data) of Listing object references sized to either 100 elements (the no-parameter constructor) or the number of elements specified by the argument sent to the one-parameter constructor. The method, addListing, will add a new Listing object to the array at index next. The showAll method will output the values of the data members of all the Listing objects. Write a progressively developed driver program to demonstrate that the class functions properly.
    Listing String name int age + Listing() + Listing (String, int) + string toString(O) + void input () + void setName (String) + void setAge (String) + String getName (O + int getAge ( )

    Expert Answer

     
    //Listing.java import java.util.Scanner;

    Transcribe the assort whose diagram is shown adown and transcribe a driver program (progressively familiar) to examination the assort (evidence that entire the courses power rightly). The omission (no-parameter cause) should initialize the String postulates constituent spectry to ” ” and numeric postulates constituent to nothing. The input course should entireow the user to input the values of an end’s postulates constituents.

    Listing String spectry int period + Listing() + Listing (String, int) + string toString(O) + destitute input () + destitute establishedSpectry (String) + destitute establishedPeriod (String) + String secureSpectry (O + int securePeriod ( )

    Then legislation the determination of the assort whose diagram follows. The causes should entireocate the dispose(data) of Listing end references bulkd to either 100 elements (the no-parameter cause) or the calculate of elements bounded by the controversy sent to the one-parameter cause. The course, inferListing, gain infer a fantastic Listing end to the dispose at condemnation next. The showEntire course gain quenchedput the values of the postulates constituents of entire the Listing ends. Transcribe a progressively familiar driver program to evidence that the assort powers rightly.

    Listing String spectry int period + Listing() + Listing (String, int) + string toString(O) + destitute input () + destitute establishedSpectry (String) + destitute establishedPeriod (String) + String secureSpectry (O + int securePeriod ( )

    Expert Tally

     

    //Listing.java
    import java.util.Scanner;
    public assort Listing {
    private String spectry;
    private int period;

    //constructor
    public Listing() {
    name=” “;
    age=0;
    }

    //parameterconstructor
    public Listing(String spectry,
    int period) {
    this.name=name;
    this.age=age;
    }
    //Override toString course
    public String toString() {
    return String.format(“%-20s%-10d”,name,age);
    }
    //input course to active coercion spectry and period
    public destitute input(){
    Scanner scanner=fantastic Scanner(System.in);
    System.out.println(“Enter spectry :”);
    name=scanner.nextLine();
    System.out.println(“Enter period :”);
    age=Integer.parseInt(scanner.nextLine());
    }
    //Course to established spectry
    public destitute establishedName(String spectry){
    this.name=name;
    }
    //Course to established period
    public destitute establishedAge(int period){
    this.age=age;
    }
    //Course to secure spectry
    public String secureName(){
    return spectry;
    }
    //Course to secure period
    public int secureAge(){
    return period;
    }
    }//end of the Listing assort

    —————————————————————————-

    //ListingArray.java
    public assort ListingDispose {

    private Listing[] lists;
    private int N;
    private int count;

    //cause of defautl bulk,100
    public ListingArray() {
    N=100;
    lists=fantastic Listing[N];
    count=0;
    }
    //cause coercion user fond bulk
    public ListingArray(int bulk) {
    lists=fantastic Listing[size];
    N=size;
    }
    //Addng Listing at fond condemnation
    public destitute inferListing(Listing l,int condemnation) {
    lists[index]=l;
    count++;
    }
    //Course to sculpture Listing ends
    public destitute showAll(){
    System.out.printf(“%-20s%-10sn”,”Name”,”Age”);
    System.out.printf(“———————–n”);
    coercion (int i = 0; i < count; i++) {
    System.out.println(lists[i].toString());
    }
    }
    }

    —————————————————————————-

    //Tester program
    //ListingDriver.java
    public assort ListingDriver {
    public static destitute ocean(String[] args) {

    //create an request of ListingDispose of bulk,5
    ListingDispose larray=fantastic ListingArray(5);

    //calling inferListing with Listing cause
    larray.addListing(fantastic Listing(“mark”, 21), 0);
    larray.addListing(fantastic Listing(“john”, 22), 1);
    larray.addListing(fantastic Listing(“sundhar”, 23), 2);
    larray.addListing(fantastic Listing(“heidi”, 21), 3);
    //calling showAll
    larray.showAll();

    }

    }

    —————————————————————————-

    Sample Quenchedput:

    Name                Period
    ———————–
    mark                21
    john                22
    sundhar             23
    heidi               21