Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

0 cse.usf.edu Conversations Shunno - Khachar B Khachar Vitor Ochin Discussions:

ID: 3681847 • Letter: 0

Question

0 cse.usf.edu Conversations Shunno - Khachar B Khachar Vitor Ochin Discussions: EGN44 Project 11: Car Class USF OASIS Schedu Maymester | Uni www.cse.usf.edu/-t.. Ellucian Degree Wor... Assignment Write a class called Car that holds information about an automobile: Make (e.g., Ford, Toyota, Fiat) Model (e.g., Fusion, Prius, 500) . Year (e.g., 2012) Define a constructor to initialize these values. -Define a toString method -Define a method called isAntique that returns true if the car is more than 25 years old, and false otherwise

Explanation / Answer

Hi, Please find the below classes implemented as per your requirement.

Car.java

import java.util.Calendar;

public class Car {
   private String automobile;
   private String model;
   private int year;
   Car(String autmobie, String model, int year){
       this.automobile = autmobie;
       this.model = model;
       this.year = year;
   }
   public String toString(){
       String s;
s = year +" "+automobile+" "+model;

       return s;
   }
   public boolean antique(){
       boolean flag;
   //determine current year
   Calendar today = Calendar.getInstance();
   int currentYear = today.get(Calendar.YEAR);
   if( (currentYear - year) > 25)
       flag = true;
   else
       flag = false;
      
       return flag;
   }
}

Car_Test.java


public class Car_Test {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       java.util.Scanner in = new java.util.Scanner(System.in);
       System.out.println("Please Enter Automobile: ");
       String autommobile = in.next();
       System.out.println("Please Enter Model: ");
       String model = in.next();
       System.out.println("Please Enter Year: ");
       int year = in.nextInt();
       Car c = new Car(autommobile, model, year);
       System.out.println(c.toString());
       boolean status = c.antique();

if(status == true)
       System.out.println("The car is an antique");

else

System.out.println("The car is not an antique");


   }

}

Output:

Please Enter Automobile:
Toyoto
Please Enter Model:
Camry
Please Enter Year:
1990 Toyoto Camry

The Car is an antique