Makes class The Makes class describes information of the makes of a car . It has
ID: 667622 • Letter: M
Question
Makes class
The Makes class describes information of the makes of a car. It has following attributes:
Attribute name
Attribute type
Description
country
String
The country of the car where it's made
manufacturer
String
The car manufacturer's name
brandName
String
The car brand's name, for example Explorer
The default value of country, manufacturer, brandName is "?". Provide a constructor to set these default values.
public Makes( )
The following accessor methods should be provided to get the attributes:
public String getCountry()
public String getManufac()
public String getBrand()
The following modifier(mutator) methods should be provided to set the attributes:
public void setCountry(String nCountry)
public void setManufac(String nManufac)
public void setBrand(String nBrand)
The following method must be defined:
public String toString()
toString method should return a string of a "Makes" object in the following format:
Country: USA
Manufacturer: Ford
Brand:t Explorer
Car class
The Pet class describes a pet that an owner can have. It has the following attributes:
Attribute name
Attribute type
Description
year
String
Year of the car is produced
color
String
The color of the car
makes
Makes
The makes information of a car (see class Makes)
The following accessor methods should be provided to get the attributes:
public String getYear( )
public String getColor( )
public double getPrice( )
public Makes getMakes( )
The following modifier(mutator) methods should be provided to change the attributes:
public void setYear(String nYear)
public void setColor(String nColor)
public void setPrice(double nPrice)
public void setMakes(String nCountry, String nManufac, String nBrand)
The following method must be defined:
public String toString()
The toString() method constructs a string of the following format:
Country: USA
Manufacturer: Ford
Brand: Explorer
Year: 2015
Color: Silver
Price: 30700.95
Assignment4
In this assignment, download Assignment4.java file by clicking the link, and use it for your assignment. You do not need to change Assignment4.java file. You only need to write Car.java and Makes.java files.
The following is the description of Assignment4 class.
The driver program will allow the user to interact with your other class modules. The purpose of this module is to handle all user input and screen output. The main method should start by displaying the following menu in this exact format:
Choice Action
------ ------
A Add Car
D Display Car
Q Quit
? Display Help
Next, the following prompt should be displayed:
What action would you like to perform?
Read in the user input and execute the appropriate command. After the execution of each command, re-display the prompt. Commands should be accepted in both lowercase and uppercase.
Add Car
Your program should display the following prompt:
Please enter the car information:
Who is the car's manufacturer?
Read in the user input. Then the following prompt:
What is the car's brand?
Read in the user input. Then the following prompt:
Which country is the car made?
Read in the user input and set country, manufacturer and brandName on the makes object. Then the following prompt:
what year was the car made?
Read in the user input and set year attribute of the car object. Then the following prompt:
What color is the car?
Read in the user input and set color attribute of the car object. Then the following prompt:
How much was the car's price?
Read in the user input and set the price attibute of the car object.
Note that there is only one Car object in this assignment. Thus when "Add Car" option is selected more than once, the new one overwrites the old Car object information.
Display Car
Your program should display the pet information in the following format:
Country: USA
Manufacturer: Ford
Brand: Explorer
Year: 2015
Color: Silver
Price: 30700.95
Make use of the toString( ) method of the Makes class to display this information. The toString method is used together with System.out.print method.
(System.out is NOT to be used within the toString method.)
Quit
Your program should stop executing and output nothing.
Display Help
Your program should redisplay the "choice action" menu.
Invalid Command
If an invalid command is entered, display the following line:
Unknown action
Attribute name
Attribute type
Description
country
String
The country of the car where it's made
manufacturer
String
The car manufacturer's name
brandName
String
The car brand's name, for example Explorer
Explanation / Answer
ase 'A': //Add Pet
System.out.print("Please enter the pet information: ");
System.out.print("Enter a pet name: ");
name = scan.nextLine();
pet1.setPetName(name);
System.out.print("Enter its type: ");
type = scan.nextLine();
pet1.setType(type);
System.out.print("Enter its birth date: ");
date = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth month: ");
month = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth year: ");
year = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth place: ");
place = scan.nextLine();
pet1.setBirthInfo(date, month, year, place);
break;
case 'D': //Display course
System.out.print(pet1);
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown action ");
break;
}
}
else
{
System.out.print("Unknown action ");
}
} while (input1 != 'Q' || line.length() != 1);
}
/** The method printMenu displays the menu to a user **/
public static void printMenu()
{
System.out.print("Choice Action " +
"------ ------ " +
"A Add Pet " +
"D Display Pet " +
"Q Quit " +
"? Display Help ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.