Question

-please use java 3. Interface: Implement a program that creates an Interfacecalled Vehiclewith the following abstract...

-please use java

3. Interface: Implement a program that creates an Interfacecalled Vehiclewith the following abstract methods(getters): getMake(), getModel(), getYear(), and creates a Classcalled Carthatimplements the Vehicleinterface. The Carclass also contains instance data that represents the make, model, and year of the carand the constructor to initialize these values.Create a driver class called CarTest, whose main method instantiates a Carobject with the following information: Chevrolet, Impala, 2019, and test the getter methods you implement.

4. Abstract Class: Implement the above problem 3 by defining Vehicleas an Abstract Classinstead of an Interface.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

interface Vehicle {
   String getMake();
   String getModel();
   int getYear();
}

class Car implements Vehicle {

   private String make;
   private String model;
   private int year;
  
  
   public Car(String aMake, String aModel, int aYear) {
       super();
       make = aMake;
       model = aModel;
       year = aYear;
   }
   @Override
   public String getMake() {
       return null;
   }
   @Override
   public String getModel() {
       // TODO Auto-generated method stub
       return null;
   }
   @Override
   public int getYear() {
       // TODO Auto-generated method stub
       return 0;
   }
   @Override
   public String toString() {
       return "Car [make=" + make + ", model=" + model + ", year=" + year + "]";
   }

}

public class TestVehicle {
   public static void main(String[] args) {
       Car c = new Car("Honda", "City", 2014);
       System.out.println(c);
      
   }
}

Answer 2:

abstract class Vehicle {
   public abstract String getMake();
   public abstract String getModel();
   public abstract int getYear();
}

class Car extends Vehicle {

   private String make;
   private String model;
   private int year;
  
  
   public Car(String aMake, String aModel, int aYear) {
       super();
       make = aMake;
       model = aModel;
       year = aYear;
   }
   @Override
   public String getMake() {
       return null;
   }
   @Override
   public String getModel() {
       // TODO Auto-generated method stub
       return null;
   }
   @Override
   public int getYear() {
       // TODO Auto-generated method stub
       return 0;
   }
   @Override
   public String toString() {
       return "Car [make=" + make + ", model=" + model + ", year=" + year + "]";
   }

}

public class TestVehicle {
   public static void main(String[] args) {
       Car c = new Car("Honda", "City", 2014);
       System.out.println(c);
      
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
-please use java 3. Interface: Implement a program that creates an Interfacecalled Vehiclewith the following abstract...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name

    Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight objects.

  • Write a class called Shelf that contains instance data that represents the length, breadth, and capacity...

    Write a class called Shelf that contains instance data that represents the length, breadth, and capacity of the shelf. Also include a boolean variable called occupied as instance data that represents whether the shelf is occupied or not. Define the Shelf constructor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant (the constructor should initialize occupied to false). Include getter and setter methods for all instance data. Include a toString method...

  • In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a...

    In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...

  • JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...

    JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...

  • cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher,...

    cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher, price, and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Write another class called Bookshelf, which has name and array of Book objects. Bookself capacity is maximum of five books. Includes method for Bookself that adds, removes,...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively:...

    Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively: a. An interface called Printable with a void print() method. b. An interface called EmployeeType with FACULTY and CLASSIFIED integer data. The value of FACULTY is 1 and CLASSIFIED is 2. a. A class called Employee to implement the two interfaces. Its constructor will initialize three instance data as name, employeeType, and salary. Implementation of method print() will display name, employeeType, and salary; salary...

  • JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees....

    JAVA Problem:  Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...

  • In Java Create an interface called Amount that includes a method called setPrice (). Create an a...

    In Java Create an interface called Amount that includes a method called setPrice (). Create an abstract class named Book that inherits from the interface Amount. Include a String field for the book’s title and a double field for the book’s Price . Within the class, include a constructor that requires the book title and add two getter methods — one that returns the title and one that returns the price. Include an abstract method named setPrice (). Create a...

  • Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement...

    Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement a constructor that takes the balance (float). –Provide abstract methods deposit(amount) and withdraw(amount) •Design a class called SavingsAccount which extends BankAccount. –Implement a constructor that takes the balance as input. –It should store a boolean flag active. If the balance at any point falls below $25, it sets the active flag to false. It should NOT allow the balance to fall below $0. –If...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT