Question
Write an application that declares an array of three Listings (defined in one of the two previous examples) whose contents are input by the user.
Write an application that declares an array of three Listings
(defined in one of the two previous examples) whose contents are
input by the user. After being input, the listings should be output in
reverse order.
This is the previous question (example) with the same picture:
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.
This is what the first expert gave me and I and I do not know what Il am input even though he wrote notes my output is not coming like the out put he posted:::
Expert code with notes:
/* Please read all the comments and see the result*/
import java.io.*; public class Listing { //Main Class named Listing String name; //Data member name int age; //Data Member age Listing(){ //Default constructor name =""; age = 0; } Listing(String n,int a){ //Parameterized constructor this.name = n; this.age =a; } @Override public String toString(){ // OVerrided toString() method return String.format("Name: " + this.name + " Age: "+this.age); } void input() throws Exception{ //Input of data member through input() Listing list[] = new Listing[3]; //an array of three Listings for(int i=0;i
//Showing result in reverse manner System.out.println("All 3 listings in reverse order are following"); for(int i=2;i>=0;i--){ System.out.println(list[i].toString()); } } void setName(String n){ //setName method() this.name=n; } void setAge(String age){ //setAge method() this.age = Integer.parseInt(age); } String getName(){ //getName() function return this.name; } int getAge(){ //getAge function() return this.age; } public static void main(String[] args) throws Exception { //Driver method Listing listing1 = new Listing(); //Object for default constructor System.out.println("Result with default constructor"); System.out.println(listing1.toString()); //Showing result with default constructor Listing listing2 = new Listing("Amit",22); //Object for parameterized constructor System.out.println("Result with parameterized constructor"); System.out.println(listing2.toString()); Listing listing3 = new Listing(); //Object for input method() for initilized object System.out.println("Setting value with input method() and array of three listing"); listing3.input(); //Calling input() method with object Listing listing4 = new Listing(); //Object for getter and setter method System.out.println("Result with get and set method"); listing4.setName("Raj"); //first set name with "Raj" listing4.setAge("55"); // Then set age as "55" //Now show the result System.out.println("Name = " + listing4.getName() + " Age = " + listing4.getAge());
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started