Tuesday 17 March 2009

Calculate Cost X

import java.util.Scanner;
class calculateCost {
public static void main (String args[]) {
Scanner s = new Scanner(System.in);


int weight=0;
String method=null;
double cost=0.0;

System.out.println("Choose the selected shipping method");
System.out.println("A=Air");
System.out.println("T=Truck");
System.out.println("M=Mail");
String choice=s.next();

if(choice.equals("A"))
{
method="Air";
System.out.println("Enter weight :");
weight=s.nextInt();

if (weight <=8)
cost=2.00;
else if (weight<=16)
cost=3.00;
else
cost=4.50;
}
else if(choice.equals("T"))
{
method="Truck";
System.out.println("Enter weight :");
weight=s.nextInt();

if (weight <=8)
cost=1.50;
else if (weight<=16)
cost=2.35;
else
cost=3.25;
}

else if(choice.equals("M"))
{
method="Mail";
System.out.println("Enter weight :");
weight=s.nextInt();

if (weight <=8)
cost=0.50;
else if (weight<=16)
cost=1.50;
else
cost=2.15;
}
else
System.out.println("Thank You");

System.out.println("Method\tWeight\tCost");
System.out.println("=====================");
Package p = new Package(weight,method,cost);
System.out.println( p.display());




}
}

No comments: