Question

In: Computer Science

Create a short program in Java which contains the below information: - Has one abstract and...

Create a short program in Java which contains the below information:

- Has one abstract and two regular classes

- Has two interfaces (the two regular classes have to implement at least one interface

- At least one regular class must implement both interfaces

- The two classes have to extend the abstract class

- The abstract class must have a method

- At least one interface must have a method

- At least two fields in each class, this includes the superclass

- All the fields are instantiated within the constructor

Solutions

Expert Solution

interface 1 :

Vehicle.java


public interface Vehicle {

// mothod inside interface

   void getManufacturer();
}

------------------------------------------------------------------------------------------------------------

interface 2 :

VehicleParts.java

public interface VehicleParts {

// two methods inside interface

   void getNumberOfWheels();
   void getVehicleBodyDetails();
  
}

-------------------------------------------------------------------------------------------------------------

abstract class

Offer.java


public abstract class Offer {
// variable inside abstract class
   boolean isOffer;
// abstract method inside abstract class
   abstract void getOfferDetails();
  
}
-------------------------------------------------------------------------------------------------------------------------------

regular class 1:

Car.java


public class Car extends Offer implements Vehicle, VehicleParts {

// variables in the class

String varient;
   double price;
   Offer offer;

// parameterised constructor and is instantiated

   public Car(String varient, double price, Offer offer) {
  
       this.varient = varient;
       this.price = price;
       this.offer = offer;
   }

// default constructor

   public Car() {
       super();
   }

// abstract class method implementation

@Override
   void getOfferDetails() {
       System.out.println("No offers available !");

   }

// method inside interface vehicleParts and locally implemented

   @Override
   public void getNumberOfWheels() {
       System.out.println("This is a car and have 4 wheels.");

   }

// method inside interface vehicleParts and locally implemented

   @Override
   public void getVehicleBodyDetails() {
       System.out.println("High quality Metal Body.");

   }

// method inside interface vehicle and locally implemented

   @Override
   public void getManufacturer() {
       System.out.println("This Car is manufactured by TOYOTA.");

   }

}
----------------------------------------------------------------------------------------------------

regular class2

Bike.java


public class Bike extends Offer implements Vehicle {

// variables in the class  

String model;
   String brakeSystem;
   Offer offer;

// parameterised constructor and is instantiated

   public Bike(String model, String brakeSystem, Offer offer) {
       this.model = model;
       this.brakeSystem = brakeSystem;
       this.offer = offer;
   }

//default constructor

   public Bike() {
       super();
   }

// abstract class method implementation

   @Override
   void getOfferDetails() {
       System.out.println("Get 5000* offer. Expire soon !");

   }

// method inside interface vehicle and locally implemented

   @Override
   public void getManufacturer() {
       System.out.println("This is manufactured by 'ROYAL ENFIELD'");

   }

}
-------------------------------------------------------------------------------------------------

test class

Showroom.java


public class Showroom {

   public static void main(String[] args) {
       Car newCar = new Car();
       Bike newBike = new Bike();

       // set values to the fields in Car
       newCar.varient = "XZPlus";
       newCar.price = 1000000;
       newCar.isOffer = false;

       // set values to the fields in bike
       newBike.model = "Thunder";
       newBike.brakeSystem = "ABS";
       newBike.isOffer = true;

       // print car details
       newCar.getManufacturer();
       newCar.getNumberOfWheels();
       newCar.getOfferDetails();

       System.out.println("\n");

       // print bike details
       newBike.getManufacturer();
       newBike.getOfferDetails();

   }

}


Related Solutions

Java program Create two classes based on the java code below. One class for the main...
Java program Create two classes based on the java code below. One class for the main method (named InvestmentTest) and the other is an Investment class. The InvestmentTest class has a main method and the Investment class consists of the necessary methods and fields for each investment as described below. 1.The Investment class has the following members: a. At least six private fields (instance variables) to store an Investment name, number of shares, buying price, selling price, and buying commission...
IN JAVA create a program that has 8 players and ranks them randomly and contains 3...
IN JAVA create a program that has 8 players and ranks them randomly and contains 3 rounds. For each round the highest ranked player plays the lowest ranked one i.e., in quarter-final round, player ranked 1 plays player ranked 8, player ranked 2 plays player ranked 7 and so on. Report the winner of each match, simulating using random values of your choice USING JAVA COLLECTIONS IS NOT ALLOWED
Create a program in java with the following information: Design a program that uses an array...
Create a program in java with the following information: Design a program that uses an array with specified values to display the following: The lowest number in the array The highest number in the array The total of the numbers in the array The average of the numbers in the array Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51 example...
Create a program in Java for storing the personal information of students and teachers of a...
Create a program in Java for storing the personal information of students and teachers of a school in a .csv (comma-separated values) file. The program gets the personal information of individuals from the console and must store it in different rows of the output .csv file. Input Format User enters personal information of n students and teachers using the console in the following format: n Position1 Name1 StudentID1 TeacherID1 Phone1 Position2 Name2 StudentID2 TeacherID2 Phone2 Position3 Name3 StudentID3 TeacherID3 Phone3...
Create a catchy and short title for this blog down below. It has to be short,...
Create a catchy and short title for this blog down below. It has to be short, catchy and creative. Where would anyone get the most up-to-date news on their favorite restaurants, public schools or local shops during the Coronavirus? If I were to take an actual poll (which will be run through my social media), most would likely say it would be on Instagram, Twitter, and Facebook. I was following one of my favorite bands on Instagram one day, I...
can you give me short summary abstract and conclusion on the below which is taken from...
can you give me short summary abstract and conclusion on the below which is taken from chapters 5,6 in Strategic Market Management, 9th Edition, by David A. Aaker Environmental Analysis and Strategic Uncertainty Environmental Analysis • Technology Trends – To what extent are existing technologies maturing? – What technological developments or trends are affecting or could affect the industry? • Government/Economic Trends – What changes in regulation are possible? What will their impact be?   – What are the political risks...
This Code Is Supposed To Be Performed In JAVA 1.) Create an abstract class DiscountPolicy. It...
This Code Is Supposed To Be Performed In JAVA 1.) Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost. Create a driver class that tests this class and provide the UML. 2.) In a separate program, define DiscountPolicy as an interface instead of the abstract class. Create a driver class that tests...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in English (dictionary), to find the number of misspelled words in a story file called Alcott-little-261.txt. Please note that the dictionary words are all lower-cased and there are no punctuation symbols or numbers. Hence it is important that you eliminate anything other than a-z and A-Z and then lower case story words for valid comparisons against the WordList file. When you read each line of...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in English (dictionary), to find the number of misspelled words in a story file called Alcott-little-261.txt. Please note that the dictionary words are all lower-cased and there are no punctuation symbols or numbers. Hence it is important that you eliminate anything other than a-z and A-Z and then lower case story words for valid comparisons against the WordList file. When you read each line of...
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class....
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class. The vehicle class should contain at least 2 variables that could pertain to ANY vehicle and two methods. The truck class should contain 2 variables that only apply to trucks and one method. Create a console program that will instantiate a truck with provided member information then call one method from the truck and one method contained from the inherited vehicle class. Have these...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT