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
Make a program that prints each line of its input that mentions fred. (It shouldn’t do anything for other lines of input.) Does
Vitek1552 [10]

Answer:

See Explaination

Explanation:

This assume that input is a file and is given on command line. Please note this will ot print lines with frederick as thats what I feel question is asking for

#!/usr/bin/perl -w

open(FILE, $ARGV[0]) or die("Could not open the file $ARGV[0]");

while ($line = <FILE>){

if($line=~/\s+fred\s+/)

{

print $line;

}

}

close(FILE);

8 0
3 years ago
The Securities and Exchange Commission (SEC) was created to develop and approve a set of common international accounting rules.
Dennis_Churaev [7]

Answer:  

Idk search it on google chrome

Explanation:

3 0
3 years ago
Which cell address indicates the intersection of the first row and the first column in worksheet?
Rzqust [24]

Answer:

A. A1

Explanation:

Worksheet's Columns are named with Alphabets. i.e. A,B,C,D,E....

And Worksheet's rows are named with numbers. i.e. 1,2,3,4,5....

So the intersection of first row number as "1" and First Column name as "A" is A1 as worksheet displays column name first and then row number.

8 0
3 years ago
Read 2 more answers
Which internet technology allows businesses to make presentations and share visual aids such as charts and graphs ?
Akimi4 [234]

Web conferencing is an internet technology that allows people in remote locations collaborate in a virtual conference room by making presentations and sharing visual aids.

Let me know if you have any questions.

8 0
3 years ago
Read 2 more answers
Critical Thinking Questions
nydimaria [60]
You’re profile is so cute hope this helps :)
5 0
2 years ago
Other questions:
  • Trevor got home from work and suddenly realized that he needed to edit a certain file stored in the company network's server. ho
    11·1 answer
  • How to write a program that prompts the user to input two POSITIVE numbers — a dividend (numerator) and a divisor (denominator).
    13·1 answer
  • Create a Rational number class in Java using the same style as the Complex number class created in class.(The in class example c
    12·1 answer
  • Pamela finds that she is constantly spelling the word “color” as “colour” when she is typing. Even though this is how the word i
    11·1 answer
  • A(n) is the tool that will help you the most when developing the content you will use in your presentation.
    10·1 answer
  • Jason Has A Science Video Project, As He Creats His Project, He Saves, Then Comes Back A Minute Later. The File Is Now Unreadabl
    8·2 answers
  • When you use the 3 bits 100 what color will it produce?<br><br> Computer Science
    11·1 answer
  • Zybook C++ 3.21 answer
    9·1 answer
  • Discussion Topic
    11·1 answer
  • You find a picture of a famous department store online that would be great to include in a project of yours. What should you do
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!