Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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());

} }

image text in transcribed Expert output to his code
image text in transcribed picture for question
- Viroyy uuuy Textbook Solutions Expert Q&A Study Pack Practice Search "Here Is result or output/ C\Windows\system32\cmd.exe Cherr\Javajavac Listing.java :\Chegg\Java>java Listing Result with default constructor Name: Age: 0 Result with parameterized constructor Name: Amit Age: 22 betting value with input method() and array of three listing Enter Name: Kiran Enter Age: 15 Enter Name: Raj Enter Age: 45 Enter Name: Thakur Enter Age: 72 All 3 listings in reverse order are following Name: Thakur Age: 72 Name: Raj Age: 45 Name: Kiran Age: 15 Result with get and set method Name = Raj Age = 55 Listing String name - int age + Listing() + Listing (String, int) + String toString(). void input(). + void setName(String) + void setAge(String) + String getName() + int getAge(

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions