/* Shipping corporation using inheritance */
import java.io.*;
class Smartphone
{
protected String brand;
protected double screenSize;
public Smartphone(String br, double ss)
{
brand = br;
screenSize = ss;
}
}
class SmartphoneStorage extends Smartphone
{
protected int storage;
public SmartphoneStorage(String br, double ss, int st)
{
super(br,ss);
storage = st;
}
}
class SmartphoneCamera extends SmartphoneStorage
{
protected int camera;
public SmartphoneCamera(String br, double ss, int st, int cm)
{
super(br,ss,st);
camera = cm;
}
}
class SmartphoneOS extends SmartphoneCamera
{
protected String operatingSystem;
public SmartphoneOS(String br, double ss, int st, int cm, String os)
{
super(br,ss,st,cm);
operatingSystem = os;
}
}
class Shipment extends SmartphoneOS
{
protected double cost;
protected int totalAmount;
public Shipment(String br, double ss, int st, int cm, String os, double cst, int tAmount)
{
super(br,ss,st,cm,os);
cost = cst;
totalAmount=tAmount;
}
public double shipmentCost()
{
return totalAmount*cost;
}
}
class Main
{
public static void main(String args[])
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter number of shipments: ");
int n = Integer.parseInt(br.readLine());
Shipment spmt[]=new Shipment[n];
for(int i=0; i<n; i++)
{
System.out.println("Enter shipment "+i+1+" details");
System.out.print("\tEnter Brand: ");
String brand = br.readLine();
System.out.print("\tEnter Screen Size: ");
double ss = Double.valueOf(br.readLine());
System.out.print("\tEnter Storage Capacity: ");
int st = Integer.parseInt(br.readLine());
System.out.print("\tEnter Camera: ");
int cm = Integer.parseInt(br.readLine());
System.out.print("\tEnter Operating System: ");
String os = br.readLine();
System.out.print("\tEnter Cost per phone: ");
double cst = Double.valueOf(br.readLine());
System.out.print("\tEnter total amount: ");
int tAmount = Integer.parseInt(br.readLine());
spmt[i]=new Shipment(brand,ss,st,cm,os,cst,tAmount);
}
for(int i=0; i<n; i++)
{
System.out.println("\nShipment "+i+1+" details");
System.out.println("\tBrand: "+spmt[0].brand);
System.out.println("\tScreen Size: "+spmt[0].screenSize+" Inch");
System.out.println("\tStorage Capacity: "+spmt[0].storage+" Gb");
System.out.println("\tCamera: "+spmt[0].camera+" Megapixel");
System.out.println("\tOperating System: "+spmt[0].operatingSystem);
System.out.println("\tCost per phone: "+spmt[0].cost+" Rupees");
System.out.println("\tTotal Shipment Amount: "+spmt[0].totalAmount);
System.out.println("\n\tTotal Shipment Cost: "+spmt[0].shipmentCost()+" Rupees");
System.out.println();
}
}
catch(Exception e)
{
System.err.println(e);
}
}
}
No comments:
Post a Comment