dElmARk Admin
Posts : 92 Join date : 09/04/2012
| Subject: InputStream Sat Feb 23, 2013 11:24 pm | |
| - Code:
-
import java.io.*; import java.util.*; public class FastFood { public static void main(String[]ecs)throws IOException { Scanner sc = new Scanner(System.in); FileWriter fw = new FileWriter("Receipt.txt",true); System.out.print("Enter Item Code: "); String code = sc.nextLine(); fw.write("Item Code: " + code);
FileInputStream fis = new FileInputStream("Menulist.txt"); DataInputStream dis = new DataInputStream(fis); BufferedReader bf = new BufferedReader(new InputStreamReader(dis)); String itemcode=""; String element[]; while((itemcode=bf.readLine())!=null) { element = itemcode.split(" , "); if(code.equals(element[0])) { System.out.println("Description: "+element[1]); fw.write("\r\nDescription: "+element[1]); System.out.println("Type: "+element[2]); fw.write("\r\nType: "+element[2]); System.out.println("Cost: "+element[3]); fw.write("\r\nCost: "+element[3]); System.out.print("Enter Quantity: "); double qty = sc.nextDouble(); fw.write("\r\nQuantity: "+qty); double totalcost = Double.parseDouble(element[3])*qty; System.out.println("Total Cost: "+totalcost); fw.write("\r\nTotal Cost: "+totalcost); System.out.print("Enter Payment: "); double cash = sc.nextDouble(); fw.write("\r\nCash Paid: "+cash); double vat = totalcost*0.12; double lessvat = totalcost-vat; double change = cash-totalcost; System.out.println("Change: "+change); fw.write("\r\nChange: "+change); System.out.println("12% vat: "+vat); fw.write("\r\n12% VAT: "+vat); System.out.println("Less VAT: "+lessvat); fw.write("\r\nLess VAT: "+lessvat); fw.write("\r\n*****THANK YOU!!*****\r\n\r\n"); fw.close(); } } } } | |
|
dElmARk Admin
Posts : 92 Join date : 09/04/2012
| Subject: Re: InputStream Sat Feb 23, 2013 11:25 pm | |
| Menulist.txt - Code:
-
001 , Spaghetti , Pasta , 75 002 , Pancit , Noodles , 100 003 , Coke , Drinks , 30 | |
|