\"using eclipse \" Given the structure in Figure for the Interface and the class
ID: 3611885 • Letter: #
Question
"using eclipse "
Given the structure in Figurefor the Interface and the classes, write ajava program that implements the given structure. Add a driver,create atleast one object of each class and use the Interfaceto reference them. Print all related information for each object bycalling methods GetInfo() and GetValue().
Method Description:
GetInfo(): Will print allrelated data members for any class.
GetValue():
Constructors(): Must setall related data members.
OutputSample:
Object 1
Type: Invoice
Quantity: 10
Price: 550
Calculated Value: 5500
-----------------------------
Object 2
Type: Benz
Production Year: 2005
Used Years: 4
Original Price: 12500
Calculated Value: 10000
Explanation / Answer
/* save the below code in "Driver.java" compile using "javac Driver.java" reun using "java Driver" */ import java.io.*; interface Information{ public void getInfo(); public void getValue(); } class Invoice implements Information { public int quantity; public double price; public Invoice(int quantity, double price) { this.quantity = quantity; this. price = price; } public void setQuantity(int quantity) { this.quantity = quantity; } public void setPrice (double price) { this.price = price; } public int getQuantity() { return quantity; } public double getPrice() { return price; } public void getInfo() { System.out.println("Type: " +"Invoice"); System.out.println("Quantity:" + quantity); System.out.println("Price:" +price); } public void getValue() { System.out.println("Calculated Value: " + (quantity* price)); } }//end of Invoice class class Vehicle implements Information { public String type; public int productionYear; public int usedYears; public double originalPrice; public Vehicle( String type, intproductionYear, int usedYears, double originalPrice) { this.type =type; this.productionYear=productionYear; this.usedYears =usedYears; this.originalPrice = originalPrice; } public void setType(String type) { this.type = type; } public void setProductionYear(intproductionYear) { this.productionYear =productionYear ; } public void setUsedYears(int usedYears) { this.usedYears =usedYears ; } public void setOriginalPrice (doubleoriginalPrice ) { this.originalPrice = originalPrice ; } public String getType() { return type; } public int getProductionYear() { return productionYear; } public int getUsedYears() { return usedYears ; } public double getOriginalPrice() { return originalPrice ; } public void getInfo() { System.out.println("Type: " +type); System.out.println("productionYear:" + productionYear); System.out.println("usedYears: " + usedYears); System.out.println("originalPrice: " + originalPrice); } public void getValue() { System.out.println("Calculated Value: " + (originalPrice - ( (0.05* originalPrice) * usedYears))); } }//end of Vehicle class public class Driver { public static void main(String[] args){ Invoice in = new Invoice(10, 550); System.out.println("---------------------------------------------------"); System.out.println("Object 1"); in.getInfo(); in.getValue(); System.out.println("---------------------------------------------------"); Vehicle vh = new Vehicle("Benz" , 2005, 4, 12500); System.out.println("Object 2"); vh.getInfo(); vh.getValue(); }//end of main }//end of class Driver
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.