Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the Project Car Class to Do the Following Modifications: 1) Modify the Car project to add 'color' property to the Car private fields. 2)

Modify the Project "Car Class" to Do the Following Modifications:
1) Modify the Car project to add 'color' property to the Car private fields.
2) Modify the Car project to add 'price' property to the Car private fields.
3) Modify the Car Class Java project to accept only the following cars Make (Chevy, Ford and Toyota)
 

 

 

 

 

 

package cartest;

import java.util.Scanner;

public class CarTest {


   public static void main(String[] args) {
       // 1) Call print Headings() method
       printHeadings();
       // 2) Call create the Car Class Objects method
       createCarClass();
        // 3) Call printFootings() method
        printFootings();
       } // End of the main() method
       // 5) Define and Code All the Methods Below the main() method
       // 1) Define and Code the printHeadings() method
       public static void printHeadings() {
       System.out.println("*************************************");
       System.out.println("*******/*** Car Class project ************");
       System.out.println("*************************************");
       }
       // 2) Define and Code the create Car class() method
       public static void createCarClass() {
       // 1) Declare the Local variables to be used in the project
       boolean quit = false;
       String model, make;
       int year;
       String toQuit;
       //2) Create an object 'input' from the Class Scanner
       Scanner input = new Scanner (System.in);
       // 3) Create a Constructor of empty objects " "
       Car myCar = new Car ("", "", 0);
       // 4) Use while statement to loop until the user press 'Q' to Quit
       while (!quit) {
       // 5) Prompt the user to Enter Data about Car and Read them
       System.out.print ("Please, Enter car Make: ");
       make = input.nextLine();
       System.out.print ("Please, Enter car Model: ");
       model = input.nextLine();
       System.out.print ("Please, Enter car Year: ");
       year = input.nextInt();
       // 6) Call set methods and passing the parameters to Assign Data to objects
       myCar.setMake (make);
       myCar.setModel (model);
       myCar.setYear (year);
       input.nextLine(); // Read the empty return key of the year
       // 7) Print the Information about the car entered by user
       System.out.println ("The following are information about the car:" + myCar);
       System.out.print ("Press 'Q' to Quit or any other key to continue: ");
       toQuit = input.nextLine();
       // 8) Check if the user entered 'Q' to quit
       if (toQuit.equalsIgnoreCase ("Q")) {
       quit = true;
       }
       }
       }
       // Define and Code the printFooting() method
       public static void printFootings(){
       System.out.println("***************************************");

}

}

package cartest;

import java.util.Scanner;

public class Car {
   // 1) Declare private instance fields or attributes
private String make;
private String model;
private int year;
// 2) Create an object 'input' from the class Scanner
Scanner input = new Scanner (System.in);
// 3) Create a Car constructor passing 3 parameters
public Car (String make, String model, int year) {
this.model = model; // use this keyword for current object
this.make = make;
this.year = year;
}
// 5) Define and Code All get and set Methods that belong to Class 'Car'
// 4) Define and code the getMake() method
public String getMake() {
return this.make;
}
// 5) Define and code the getModel() method
public String getModel() {
return this.model;
}
// 6) Define and code the getYear() method
public int getYear () {
return this.year;
}// 7) Define and code the setModel() method
public void setModel(String model) {
this.model = model;
}
// 8) Define and code the setMake() method
public void setMake(String make) {
this.make = make;
}
// 9) Define and code the setYear() method
public void setYear(int year) {
// Check for invalid year < 2000 and > 2021
while (year < 2000 || year >2021) {
System.out.print("Please enter valid year (Between 2000 and 2021: ");
year = input.nextInt();
}
this.year = year; // Assign the valid year
}
// 10) Use the toString() method to print formatted string
public String toString(){
System.out.println();
return this.make + " " + this.model + " " + Integer.toString(this.year);

}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Modified Car class package cartest import javautilScanner public class CarTest public static void ma... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

=+a) What time series components do you observe in this series?

Answered: 1 week ago

Question

Bonus shares can be issued out of revenue reserves. True/False?

Answered: 1 week ago