John Delmark Aguilar

Delmark - Profiling
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 InputStream

View previous topic View next topic Go down 
AuthorMessage
dElmARk
Admin
Admin
avatar

Posts : 92
Join date : 09/04/2012

PostSubject: InputStream   Sat Feb 23, 2013 4: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();
         }
      }
   }
}
Back to top Go down
View user profile http://delmark.meabout.com
dElmARk
Admin
Admin
avatar

Posts : 92
Join date : 09/04/2012

PostSubject: Re: InputStream   Sat Feb 23, 2013 4:25 pm

Menulist.txt

Code:
001 , Spaghetti , Pasta , 75
002 , Pancit , Noodles , 100
003 , Coke , Drinks , 30
Back to top Go down
View user profile http://delmark.meabout.com
 
InputStream
View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
John Delmark Aguilar :: dElmARk Productions :: Java Programs :: Tutorials-
Jump to: