1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lubov Fominskaja [6]
2 years ago
15

Write a class called Car that contains instance data that represents the make, model, and year of the car. Define the Car constr

uctor to initialize these values. Include getter and setter methods for all instance data, and a toString method that returns a one-line description of the car. Add a method called isAntique that returns a Boolean indicating if the car is an antique (if it is more than 45 years old). Create a driver class called CarTest, whose main method instantiates and updates several Car objects.
Computers and Technology
1 answer:
liq [111]2 years ago
5 0

Answer:

Java Code example

Explanation:

Java Code

import java.util.Calendar;

public class CarTest {

   public static void main(String [] args){

       Car car1 = new Car("Honda","Civic", 2015);

       System.out.println(car1.toString());

       System.out.println("Car 1 is antique : "+car1.isAntique());

       Car car2 = new Car("Toyota","A", 1945);

       System.out.println(car2.toString());

       System.out.println("Car 2 is antique : "+car2.isAntique());

       Car car3 = new Car("Lamborghini","Model A", 2019);

       System.out.println(car3.toString());

       System.out.println("Car 3 is antique : "+car3.isAntique());

   }

}

class Car{

   private String model;

   private String  make;

   private int year;

   public Car( String make,String model, int year) {

       this.model = model;

       this.make = make;

       this.year = year;

   }

   public String getModel() {

       return model;

   }

   public void setModel(String model) {

       this.model = model;

   }

   public String getMake() {

       return make;

   }

   public void setMake(String make) {

       this.make = make;

   }

   public int getYear() {

       return year;

   }

   public void setYear(int year) {

       this.year = year;

   }

   public boolean isAntique(){

       return Calendar.getInstance().get(Calendar.YEAR)-year>45;

   }

   @Override

   public String toString() {

       return "Car{" +

               "model='" + model + '\'' +

               ", make='" + make + '\'' +

               ", year=" + year +

               '}';

   }

}

Code Explanation

Declaring the instance variable and initializing those in constructor. Defining there getter setter and create a toString method, toString method will return the overall object representation.

To check whether car is antique or not, we will use java.util.Calendar class, This class will return the current date year from which we can compare the car year to check whether the car is antique or not.

Output

Output of above TestCar is given below.

__________________________________

Car{model='Civic', make='Honda', year=2015}

Car 1 is antique : false

Car{model='A', make='Toyota', year=1945}

Car 2 is antique : true

Car{model='Model A', make='Lamborghini', year=2019}

Car 3 is antique : false

You might be interested in
What term describes the process of transferring information from one computer to another
Flauer [41]

Syncing or maybe FTP or connection

5 0
3 years ago
It is important organic mineral that is found in the soil as ash​
loris [4]

Answer:

Calcium is the most abundant element in wood ash and gives ash properties similar to agricultural lime. Ash is also a good source of potassium, phosphorus, and magnesium.

7 0
2 years ago
Read 2 more answers
Why do you think a business would set the price of their product above the competition
Flauer [41]

because a business wants you to buy their product. Its like gas prices, when one gas price is lower than another stores, people tend to go to the one with the lower price.

6 0
2 years ago
Read 2 more answers
The only item on the desktop of a new Mac is the hard-drive icon. <br><br> True or false?
Andre45 [30]

Answer:

False

There are many more items on the desktop of a new Mac than the hard-drive icon.

3 0
3 years ago
When a value is placed in a memory location, the previous value in that location is moved to the next available location in memo
Illusion [34]

Answer:

B. False

Explanation:

When a value is placed in a memory location, the previous value in that location is not moved to the next available location in memory. Rather than that happening, the previous value is totally discarded or removed from memory. In other words, the previous value is over-written. To prevent this from happening, the programmer has to explicitly or expressly move the previous value to another location in memory.

4 0
3 years ago
Other questions:
  • Normal view
    10·2 answers
  • Alison is entering text in a Word document. As she is entering data, where will the cursor move in relation to the text she is t
    6·1 answer
  • Erick, who is taking an online course, sent an e-mail to his
    14·2 answers
  • Write statements that output variable numComputers as follows. End with a newline
    14·1 answer
  • Mary, Tim, John, and Jenn each sold three million dollars worth of product within six months. Each month one of them was awarded
    12·2 answers
  • What is the default junk email protection in Outlook 2016?
    7·2 answers
  • What should be done if a system cannot boot from the hard drive?
    14·1 answer
  • A store sells rope only in whole-foot increments. Given three lengths of rope, in feet, the following code segment is intended t
    6·1 answer
  • Which decimal number is equivalent to this hexadecimal number?<br> F8
    6·2 answers
  • A(n) __________ prevents outsiders from accessing corporate information the user does not want others to see.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!