Question

In: Computer Science

Problem Statement A car dealer wants to use a software to display his or her cars’...

Problem Statement
A car dealer wants to use a software to display his or her cars’ information. As a software
developer, you are going to develop a simple program for the dealer. You will have a Car class
which has the following member variables:
 Car’s Brand
 Car’s Color
 Car’s MPG (Mile Per Gallon)
This class has setters and getter for all member variables.
This class has four different constructors:
1. A constructor with no argument.
2. A constructor with only one argument which is brand
3. A constructor with only two arguments which are brand and color
4. A constructor with only three argument which are brand, color and MPG.
If the caller of the constructor does not give a value for a particular member variable, a default
value should be assigned when a constructor is called:
The default value for brand is Ford.
The default value for color is Red.
The default value for MPG is 30.
This class (Car Class) has one public method named DisplayCarInformation(). When the method
is called, it prints the car’s brand, color, and MPG values.
In another class named CarTest, you will have a main() method. Within the main(), you need to
create at least 4 car instances. You must call the four different constructors in your program.
Since you have 4 or more Car objects, you MUST use ArrayList data structure to store them.
For each object, you need to call its DisplayCarInformation() method which will print the brand,
color, and MPG on the console and write to an actual file named carInfo.txt. Your output
format should be easy to understand.
Sample Output
“Ford, Red color, 30 mpg”
“Chevy, Red color, 30 mpg”
“Tesla, Green color, 30 mpg”
“Toyota, Blue color, 28 mpg”
Input
None
Output
Print cars’ information on console and to an actual file named carInfo.txt

WRITE JAVA SOURCE CODE

Solutions

Expert Solution

**I request you to Please Provide the positive Rating**

SOURCE CODE:

package sampleproject;

public class Car {
private String brand="Ford";
private String color="Red";
private int MPG=30;
  
   public Car() {
       super();
   }
  

   public Car(String brand) {
       super();
       this.brand = brand;
   }
  
  


   public Car(String brand, String color) {
       super();
       this.brand = brand;
       this.color = color;
   }

  
   public Car(String brand, String color, int MPG) {
       super();
       this.brand = brand;
       this.color = color;
       this.MPG = MPG;
   }


   public String getBrand() {
       return brand;
   }

   public void setBrand(String brand) {
       this.brand = brand;
   }

   public String getColor() {
       return color;
   }

   public void setColor(String color) {
       this.color = color;
   }

   public int getMPG() {
       return MPG;
   }

   public void setMPG(int MPG) {
       this.MPG = MPG;
   }
  
@Override
   public String toString() {
       return "Car [brand=" + brand + ", color=" + color + ", MPG=" + MPG + "]";
   }


void DisplayCarInformation()
{
   System.out.println(" " +brand+", "+color+"color , "+MPG+"mpg");
}
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Car c1=new Car();
       System.out.println(c1.toString());
       c1.DisplayCarInformation();
       Car c2=new Car("Chevy","Red", 30);
       Car c3=new Car("Tesla","Green", 30);
       Car c4=new Car("Toyota", "Blue", 28 );
       System.out.println(c1.toString());
       c1.DisplayCarInformation();
       System.out.println(c2.toString());
       c2.DisplayCarInformation();
       System.out.println(c3.toString());
       c3.DisplayCarInformation();
       System.out.println(c4.toString());
       c4.DisplayCarInformation();
  
   }

}
OUTPUT:

Car [brand=Ford, color=Red, MPG=30]
Ford, Redcolor , 30mpg
Car [brand=Ford, color=Red, MPG=30]
Ford, Redcolor , 30mpg
Car [brand=Chevy, color=Red, MPG=30]
Chevy, Redcolor , 30mpg
Car [brand=Tesla, color=Green, MPG=30]
Tesla, Greencolor , 30mpg
Car [brand=Toyota, color=Blue, MPG=28]
Toyota, Bluecolor , 28mpg


Related Solutions

A car dealer wants to use a software to display his or her cars’ information. As...
A car dealer wants to use a software to display his or her cars’ information. As a software developer, you are going to develop a simple program for the dealer. You will have a Car class which has the following member variables:  Car’s Brand  Car’s Color  Car’s MPG (Mile Per Gallon) This class has setters and getter for all member variables. This class has four different constructors: 1. A constructor with no argument. 2. A constructor with...
ASAP PLEASE Problem Statement A car dealer wants to use a software to display his or...
ASAP PLEASE Problem Statement A car dealer wants to use a software to display his or her cars’ information. As a software developer, you are going to develop a simple program for the dealer. You will have a Car class which has the following member variables:  Car’s Brand  Car’s Color  Car’s MPG (Mile Per Gallon) This class has setters and getter for all member variables. This class has four different constructors: 1. A constructor with no argument....
C# A car dealer wants an application that calculates the cost of a car. The GUI...
C# A car dealer wants an application that calculates the cost of a car. The GUI application should link the “BuildYourCar.accdb” database and display all the data in four different “ListBox” based on the category. Each “ListBox” should display all the items in that category. The user can only choose one item from each “ListBox” to add an item to a car. As each item is selected, the application displays the item in a separate “ListBox” to display. If user...
A car dealer leases a small computer with software for $5,000 per year. As an alterative...
A car dealer leases a small computer with software for $5,000 per year. As an alterative he could buy the computer for $7,500 and lease the software for $3,500 per year. Any time he would decide to switch to some other computer he could cancel software lease and sell the computer for $500.   A. If he buys the computer and leases the software, what is the payback period? B. If he kept the computer and software for 8 years, what...
Description of problem domain: the customer goes to the car dealer to purchase a car. First,...
Description of problem domain: the customer goes to the car dealer to purchase a car. First, the customer works with the salesperson who lists available cars from the dealer’s stock. If the customer selects a car, he may test-drive the car. If he feels satisfied with the car, he will negotiate the price with the salesperson. The customer may bring his old vehicle for trade-in. If the customer and the salesperson agree upon the final price (including the trade-in price...
Use computer software packages, such as Excel, to solve this problem. The Jacobs Chemical Company wants...
Use computer software packages, such as Excel, to solve this problem. The Jacobs Chemical Company wants to estimate the mean time (minutes) required to mix a batch of material on machines produced by three different manufacturers. To limit the cost of testing, four batches of material were mixed on machines produced by each of the three manufacturers. The times needed to mix the material follow. Manufacturer 1 Manufacturer 2 Manufacturer 3 17 29 17 23 27 16 21 32 20...
The owner of a car wash wants to see if the arrival rate of cars follows...
The owner of a car wash wants to see if the arrival rate of cars follows a Poisson distribution. In order to test the assumption of a Poisson distribution, a random sample of 150 ten-minute intervals was taken. You are given the following observed frequencies: Number of Cars Arriving in a 10-Minute Interval Frequency 0 3 1 10 2 15 3 23 4 30 5 24 6 20 7 13 8 8 9 or more 4 150 The calculated value...
Peter wants to sell one of his cars that has a diesel motor to his nephew...
Peter wants to sell one of his cars that has a diesel motor to his nephew Brett. Brett is eager to purchase the car but Brett does not realise that one of his uncle’s cars is diesel. Peter writes a letter to Brett as follows:          “Dear Brett, I know that you are interested in buying one of my cars. I would like to give it to you but I know that you won’t accept charity. Therefore I will offer...
Peter wants to sell one of his cars that has a diesel motor to his nephew...
Peter wants to sell one of his cars that has a diesel motor to his nephew Brett. Brett is eager to purchase the car but Brett does not realise that one of his uncle’s cars is diesel. Peter writes a letter to Brett as follows:          “Dear Brett, I know that you are interested in buying one of my cars. I would like to give it to you but I know that you won’t accept charity. Therefore I will offer...
A car manufacturer recognizes the sale of 40,000 cars in its income statement. All cars have...
A car manufacturer recognizes the sale of 40,000 cars in its income statement. All cars have been prepaid but not yet shipped to the customer. Assuming that sale is profitable, the accelerated recognition of this sale as revenue is likely to lead to the distortions in the following ratios: • Net Income higher – no effect – lower • Asset turnover higher – no effect- lower • Debt-to-equity higher – no effect - lower
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT