mercredi 25 mars 2015

new java learner,simple question [on hold]


import java.util.Scanner;


public class Q1 {



public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner input = new Scanner (System.in);

System.out.print(" Item 1 : ");
String item1 = input.nextLine();

System.out.print(" Quantity : ");
int quantity1 = input.nextInt();

System.out.print(" Unit Price : ");
double price1 = input.nextDouble();

double amount1 = quantity1 * price1;

System.out.printf(" Amount : %.2f" , amount1);
System.out.println("");
System.out.println("---------------------------");

System.out.print("");


System.out.print(" Item 2 : ");
String item2 = input.next();

System.out.print(" Quantity : ");
int quantity2 = input.nextInt();

System.out.print(" Unit Price : ");
double price2 = input.nextDouble();

double amount2 = quantity2 * price2;

System.out.printf(" Amount is %1.2f",amount2);


double subtotal =0;
subtotal= amount1 + amount2;

double govTax = subtotal * 0.06;

double serviceCharge = subtotal * 0.1;

double total = subtotal + govTax + serviceCharge;

System.out.printf("Subtotal is %1.2f",subtotal);

System.out.printf("Government tax (6%) is %1.2f",govTax);

System.out.printf("Service charge (10%) is %1.2f",serviceCharge);

System.out.printf("Total is %1.2f" ,total);
}


} enter image description here





Aucun commentaire:

Enregistrer un commentaire