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]
3 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]3 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 will the following code display? int numbers[4] = { 99, 87 }; cout << numbers[3] << endl; a. 87 b.0 d. 34. What
pishuonlain [190]

Answer:

1. The output is 0

2. Each element in the array is initialized to 0.0

Explanation:

Solving (a): The output of the code

We have:

<em>int numbers[4] = { 99, 87 }; </em>

<em>cout << numbers[3] << endl;</em>

<em />

The first line initializes the 0 and 1 index of the array to 99 and 87, respectively.

Other elements will be 0, by default.

So, the following code segment will output 0

<em>cout << numbers[3] << endl; </em>

<em />

Solving (b): What the given code will do?

The first and second line declares an array of 5 elements

However, the following iteration will only initialize the array with 0.0 starting from the second

<em>for(int i = 2; i <= SIZE; i++) { x[i] = 0.0; }</em>

<em />

Because, the counter is initialized to start from the second index.

7 0
3 years ago
Several users on the second floor of your company's building are reporting that the network is down. You go to the second floor
Juliette [100K]

The troubleshooting step that you should take next is to Question User.

<h3>What is Troubleshooting?</h3>

This refers to the diagnostics that is run on a computer program or system in order to find the problem that is causing it to malfunction or misbehave.

Hence, we can see that based on the fact that several users on the second floor of your company's building are reporting that the network is down and go to the second floor to investigate and find that you are able to access the network, the troubleshooting step that you should take next is to Question User.

Read more about troubleshooting here:

brainly.com/question/13818690

#SPJ1

3 0
2 years ago
Consider a situation where we have a file shared between many people.  If one of the people tries editing the file, no other pe
Sergeu [11.5K]

Explanation:

I am a collection of this process from Trash on the computer system and the program that included a new twist on the computer and the skin that appears after loading and the Windows operating system it was much that appear on identifying long horizontal bar at the bottom of the screen and water pollution and its control car parts of the computer with enough letters and adware if for the collection of the fat calculation in the complete committee that in the water method is a product of a screensaver been disciplined displayed at the subject of the right click an icon To Number Sau new file getting opened on you can getting opened on a forgiving of an operational effectiveness of the program is a false false false

7 0
3 years ago
¿Qué importancia tiene conocer el escudo y lema de la Universidad Autónoma de Sinaloa? Porfa
satela [25.4K]
Conocer sobre su escudo y lema forma parte de la orientación básica inicial que nos permite comprender y entender cuales son los valores de nuestra casa de estudio y poder conocer a profundidad todo el esfuerzo e historia que la rodea, lo cual nos sirve como motivación e inspiración.
8 0
3 years ago
Print("Student" == "Teachers" or 99 != 88) will output False<br><br> true or false
ioda

Answer:

it will output True, so the statement is false

Explanation:

6 0
3 years ago
Other questions:
  • A machine called a centrifuge is used in _____.
    8·1 answer
  • While traveling in India, Sabina notes all of her daily expenses in rupees in her spreadsheet. At the end of the day, she wants
    8·1 answer
  • Question 4 of 5
    5·2 answers
  • Which of these is an application to control
    12·1 answer
  • A(n) ________ software installation copies all the most commonly used files to your computer's hard drive.
    10·1 answer
  • Suppose users share a 1-Gbps link. Also, suppose each user requires 200 Mbps when transmitting, but each user only transmits 30
    5·1 answer
  • there are these numbers that I've seen before but I don't know what they mean can someone help. I will give brainiest
    8·2 answers
  • Write a pseudocode algorithm to ask the user to input the name of a student, the marks he/she received in a test and the worth o
    10·1 answer
  • How to tell if your cell phone is being tracked tapped or monitored by spy software?
    12·1 answer
  • Why should you delete files from your computer
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!