Showing posts with label Input and Output statements. Show all posts
Showing posts with label Input and Output statements. Show all posts

Monday, June 17, 2013

Java Program Constants, Variable Declarations, Arithmetic Expressions, Assignments, Input, and Format Output.



Programming Project for Eclipse

Assignment
A convenience store sells T-shirt, potato chips, and Coke. The list prices are: $18.95 for T-shirt, $1.79 for a bag of potato chips, and $2.99 for a 12-pack Coke ($1.20 deposit as well). All merchandise except Coke is on sale with 15% off the list price. T-shirt is also charged a 6% Michigan sales tax. A customer shops at the store to buy these items. Write a Java program to simulate the shopping process — interact with the custom and prints a receipt.





Code





import java.util.Scanner;

public class a {

/**
 * 
 */
 
public static void main(String[] args) {
 //TODO Audto-generated method stub
 
 
Scanner keyboard = new Scanner(System.in);
 
double shirts = 18.95;
int numOfShirts;
int numOfChips;
int numOfCoke;
double cokeTotal;
double chips = 1.79;
double coke = 2.99;
double subTotal;
double deposit = 1.20;
double preTotal;  
double MItax = 0.06; 
double totalTax; 
double total; 
double payment; 
String name;

//Prompt for the name
System.out.print("What's your name?");
name = keyboard.nextLine();
System.out.println("Welcome to Denny's Market" + name + "! We have the following items for sale:\n");
System.out.println("T-shirt $ " + shirts + " 15% off");
System.out.println("Chips $ " + chips + " 15% off");
System.out.println("Coke $ " + coke + "\n");


//Prompt for number of the shirts 
System.out.println("How many T-shirts do you want?");
numOfShirts = keyboard.nextInt(); 
System.out.println("How many bags of chips would you like?");
numOfChips = keyboard.nextInt();
System.out.println("What about 12-pack Coke?");
numOfCoke = keyboard.nextInt();

//Calculations for the program
cokeTotal = (numOfCoke * deposit) + (numOfCoke * coke);
subTotal = (((shirts * numOfShirts) + (chips * numOfChips) + (coke * numOfCoke) + (deposit * numOfCoke)));
total = (numOfShirts * shirts) *.85 + (numOfChips * chips) *.85 + cokeTotal;
preTotal = (numOfShirts *shirts) + (numOfChips * chips) + cokeTotal;
totalTax = total * MItax; 
total = total + totalTax;

System.out.println("Your total is: $" + total);
System.out.println("Please enter your payment:");
payment = keyboard.nextDouble(); 
System.out.println("\n");

System.out.println(name + ", here is your receipt:");
System.out.println("");
System.out.println("\tItem \tUnit Price \tHow Many \tCost" + "\t");
System.out.println("-----------------------------------------------------------");

System.out.println("\tT-shirt" + "\t" + shirts + "\t" + numOfShirts + "\t" + (shirts * numOfShirts));
System.out.println("\tChips" + "\t" + chips + "\t" + numOfChips + "\t" + (chips * numOfChips)); 
System.out.println("\tCoke" + "\t" + coke + "\t" + numOfCoke + "\t" + (coke * numOfCoke));
System.out.println("\tDeposit" + "\t\t" + "\t" +  + (deposit * numOfCoke));
System.out.println("\n");

System.out.println("\tSubtotal" + "\t\t" + + subTotal);
System.out.println("\tDiscount" + "\t\t" + "-" + (preTotal-total));
System.out.println("\tTax" + "\t\t" + "\t" + + totalTax);
System.out.println("\t" + "\t\t" + "\t" + "---------\n");
System.out.println("\tTotal" + "\t\t" + "\t" + + total + "\n");

//Payment
System.out.println("\tPayment" + "\t\t" + "\t" +  + payment);

//Doing the change
System.out.println("\tYourChange"+ "\t\t" + + ((payment - total)) + "\n");
System.out.println("Than you. Come Again!");
}
}