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
In Criminal justice, the type of evidence which contradicts a given theory is known as?​
irina [24]

Answer:

In general, scientific evidence are the results of scientific tests used to prove or disprove a theory or hypothesis. In criminal cases, scientific evidence is used to help jurors understand and determine the facts of a case. Explanation:

3 0
2 years ago
Any one know how to fix forzas camera bc it shutters to much
igomit [66]

Answer:

LEDs are powered by alternating current AC.

Explanation:

The electricity will move in and out of cycles.

When the FPS won't math it'll flicker. Try switching to your camera's shutter speed instead. ( May be times your camera won't support it.)

6 0
2 years ago
I have science project competition. From where can i buy the parts i dont know any nearby place
dangina [55]
Uuuhh how bouut Walmart or anywere u want really

6 0
3 years ago
Who wrote the first computer program after floppy disc and dos
s2008m [1.1K]

<em>Alan Shugart assigned David L. Noble to lead the development of "a reliable and inexpensive system for loading microcode into IBM System/370 mainframes" using a process called Initial Control Program Load (ICPL). </em>

7 0
3 years ago
A graphic on-screen image representing an object or an idea is called a(n) A. menu. B. image. C. graphic. D. icon.
kap26 [50]
It's called D. icon
We often see these icons on our desktop page as soon as we logged on to our personal computer.
The icon on the destkop will acted as a short-cut that will opened up and connected us with the program simply by clicking the icon.
8 0
3 years ago
Read 2 more answers
Other questions:
  • ________ is a method for addressing, creating, updating, or querying relational databases.
    9·1 answer
  • The inventory tracking system shows that 12 laptop were on hand before a customer brings two laptops to the register for purchas
    9·1 answer
  • Class CTRivers describes collection of CT rivers. It has no data, and it provides the following service methods. None of the met
    13·1 answer
  • Software as a Service (SaaS) refers to the use of computing resources, including software and data storage, on the Internet rath
    13·1 answer
  • JavaBeans are?A special Java classfileServletsAppletsA Special form of JSPNone of Given
    8·1 answer
  • Is the jane austen pride and prejudie a primary source
    6·1 answer
  • "What technology will examine the current state of a network device before allowing it can to connect to the network and force a
    13·1 answer
  • Free points if you name undertale character start with T
    14·2 answers
  • Which source would provide the best way to find valid information about climate change
    8·1 answer
  • What must your motherboard have to use bitlocker encryption in windows 7 which will ensure that your hard drive cannot be used i
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!