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
Which decimal number is equivalent to this hexadecimal number?<br> F8
emmainna [20.7K]

Explanation: The numbers in a hex are the same as decimal numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The big difference between a hex and a decimal is that a hex also contains letters. These letters are: A, B, C, D, E, F. A hex number can be represented using a subscript of 16.

3 0
3 years ago
Read 2 more answers
A popular encryption method used to protect data that travel over a wireless network is ___
ddd [48]

Answer:

The most serious threat to offshore industrial systems is external access to control systems. Unwanted access to the human/machine interface (HMI) can allow third parties full control of a system. Zybersafe provides protection of the integrity of data that traverses the Ethernet connection between a company’s headquarters and a remote system.

4 0
3 years ago
The primary stream fed by tributaries within a dendritic drainage network is termed a ________ stream
a_sh-v [17]
<span>TRUNK. In a dendritic system, there are many smaller rivers or streams (the "twigs" of the tree), which are then merged into the tributaries of the main river (the branches and the trunk of the tree, respectively). They tend to develop in V-shaped valleys</span>
6 0
3 years ago
Select the best option that should be considered when preparing these images to.be used for the web
DerKrebs [107]
The answer is 1) JPEG  2) TIFF   3) BMP.  
<span>The best option that should be considered when preparing these images to.be used for the web :
</span>1) JPG (jpeg) - Used to compress web images to a small file size without
    sacrificing quality
2) TIFF (tiff) - Used for professional print images to save in a uncompressed 
     file format at high resolution.
3) BMP - Used for either web or print because of the ability to save high
    quality images ether compressed or uncompressed.
6 0
3 years ago
Anthony is deciding between different savings accounts at his bank. He has four options, based on how frequently interest compou
leonid [27]
Depends is the answer multiple choice
7 0
3 years ago
Read 2 more answers
Other questions:
  • _____ is a valuable tool that enables you to find information on the web by specifying words or phrases know as keywords- which
    14·1 answer
  • The Active Directory Users and Computers tool can be used to:______.
    11·1 answer
  • you just finished creating an expense report table, but your boss tells you to create an extra column representing non-productio
    5·1 answer
  • What two protocols are used for remote access to a server, using unencrypted and encrypted transmissions respectively? answer
    13·1 answer
  • Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (a
    14·1 answer
  • The goal of a system is to
    6·1 answer
  • My phone takes forever to load the ads, does anyone else have this problem? Is there a way to fix it? I’ve tried getting another
    12·2 answers
  • Why isn't image display working on wacom tablet.
    8·1 answer
  • What is a circular network.​
    6·2 answers
  • Write a program that takes in an integer in the range 10 to 100 as input. Your program should countdown from that number to 0, p
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!