View Single Post
  #5 (permalink)  
Old 10-14-2008, 03:27 AM
javaseek javaseek is offline
Member
 
Join Date: Oct 2008
Posts: 4
javaseek is on a distinguished road
Hi, guys I done my first java program...I am so happy

Code:
public class Pizza { private int totalAmount = 0; //total sales amount per day private int totalQuantity = 0; //total ordered pies quantity per day private int totalOrder = 0; //total number of order per day final int price = 4; //pizza pies price $4. public static void main(String[] args) { new Pizza(); } /** * Constructor for objects of class Pizza */ public Pizza() { // get the input data welcome(); //print welcome and instruction message int quantity = 1; while(quantity != -1) { switch(quantity) { case 0: output("0 pies ordered"); quantity = 1; break; case 1: case 2: case 3: case 4: quantity = inputInt("Enter number of pies: "); if((quantity > 4) || (quantity == 0) || (quantity < 0))break; int customerPrice = (quantity * this.price); //customer price calculation output("Total price : $"+customerPrice+".00"); this.totalQuantity += quantity; this.totalAmount += customerPrice; this.totalOrder += 1; break; default: output("Error: You entered an invalid number of pies"); quantity = 1; break; }//end switch }//end while SummaryRun(); //call method summaryRun }//end Pizza public void SummaryRun() { String msg ="\n\nToday's sales summary report\n"; msg += "===============================================\n"; msg += "Total number of order: "+this.totalOrder+"\n"; msg += "Total number of ordered pizza pies : "+this.totalQuantity+"\n"; msg += "Total amount of sales : $"+this.totalAmount+".00\n"; msg += "Good bye\n"; msg += "===============================================\n"; System.out.print(msg); }//end SummaryRun method static void output(String info) { System.out.println(info); } public void welcome(){ String msg ="Welcome to Pizza pies order program\n"; msg += "===============================================\n"; msg += "The valid range number of pies is 1 to 4\n"; msg += "The price is $"+this.price+".00 dollars per pies\n"; msg += "To close this program, you need to enter -1\n"; msg += "===============================================\n"; System.out.print(msg); }//end welcome message static int inputInt(String Prompt) { int result=0; try{result=Integer.parseInt(input(Prompt).trim());} catch (Exception e){result = -2;} return result; } //handle Input type static String input(String prompt) { String inputLine = ""; System.out.print(prompt); try { java.io.InputStreamReader sys = new java.io.InputStreamReader(System.in); java.io.BufferedReader inBuffer = new java.io.BufferedReader(sys); inputLine = inBuffer.readLine(); } catch (Exception e) { String err = e.toString(); System.out.println(err); } return inputLine; }//end input method }//end Pizza class
My program is running in command line based. There is one thing is left, I need to do. I was wondering if there any built-in method in java that can round the double number to two decimal places. I need it for the pies price. I want to change the price data type to double.

Last edited by javaseek : 10-14-2008 at 03:38 AM.
Reply With Quote