Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
SeishinryokuFPS

basic cashier program problem

Recommended Posts

Posted · Original PosterOP

so the output is, after i'm done with inputting an item in item number 1 its price and quantity

the second item skips and lets me input the price and quantity

 

 

 

here's the output:

         Zero DEGREE MALL
999 HDS BUILDING, Butuan City
09096082036
Current date is  9/13/2014
Current time is  6 : 54 : 15
 
Enter Item Number 1: 
Logitech G502
Enter Price: 
3100.00
Enter Quantity: 
1
Enter Item Number 2: 
Enter Price: 
3600
Enter Quantity: 
1
Enter Item Number 3: 
Enter Price: 
1000
Enter Quantity: 
1
Enter Item Number 4: 
Enter Price: 
2000
Enter Quantity: 
1
Enter Item Number 5: 
Enter Price: 
1000
Enter Quantity: 
1
Payment: 
20000
Enter Item Number 1: Logitech G502
Enter Price: 3100.0
Enter Quantity 1
Enter Item Number 2: 
Enter Price: 3600.0
Enter Quantity 1
Enter Item Number 33: 
Enter Price: 1000.0
Enter Quantity 1
Enter Item Number 4: 
Enter Price: 2000.0
Enter Quantity 1
Enter Item Number 5: 
Enter Price: 1000.0
Enter Quantity: 1
Payment: 20000.0
Total: 10700.0
Payment: 20000.0
Here's your Change: 9300.0
THANK YOU!!!!
 
 
here's the code:
import java.io.*;import java.util.*;import java.util.stream.*;public class ReceiptProgram { public static Scanner Sei = new Scanner(System.in); public static void main(String[] args) throws FileNotFoundException{int day, month, year;     int second, minute, hour;     GregorianCalendar date = new GregorianCalendar();      day = date.get(Calendar.DAY_OF_MONTH);     month = date.get(Calendar.MONTH);     year = date.get(Calendar.YEAR);      second = date.get(Calendar.SECOND);     minute = date.get(Calendar.MINUTE);     hour = date.get(Calendar.HOUR);     System.out.println("       Zero DEGREE MALL ");     System.out.println(" 999 HDS BUILDING, Butuan City ");     System.out.println(" 09096082036 ");          System.out.println("Current date is  "+(month+1)+"/"+day+"/"+year);     System.out.println("Current time is  "+hour+" : "+minute+" : "+second);     System.out.println(" ");  input();} public static Object Seishin;public static void input()throws FileNotFoundException{PrintWriter Seishinryoku = new PrintWriter("Receipt.txt");String item1;String item2;String item3;String item4;String item5;int number1;int number2;int number3;int number4;int number5;double price1;double price2;double price3;double price4;double price5;double payment;double total;double change;  System.out.println("Enter Item Number 1: ");item1 = Sei.nextLine();System.out.println("Enter Price: ");price1 = Sei.nextDouble();System.out.println("Enter Quantity: ");number1 = Sei.nextInt(); System.out.println("Enter Item Number 2: ");item2 = Sei.nextLine();System.out.println("Enter Price: ");price2 = Sei.nextDouble();System.out.println("Enter Quantity: ");number2 = Sei.nextInt(); System.out.println("Enter Item Number 3: ");item3 = Sei.nextLine();System.out.println("Enter Price: ");price3 = Sei.nextDouble();System.out.println("Enter Quantity: ");number3 = Sei.nextInt(); System.out.println("Enter Item Number 4: ");item4 = Sei.nextLine();System.out.println("Enter Price: ");price4 = Sei.nextDouble();System.out.println("Enter Quantity: ");number4 = Sei.nextInt(); System.out.println("Enter Item Number 5: ");item5 = Sei.nextLine();System.out.println("Enter Price: ");price5 = Sei.nextDouble();System.out.println("Enter Quantity: ");number5 = Sei.nextInt();System.out.println("Payment: ");payment = Sei.nextDouble(); System.out.println("Enter Item Number 1: " +item1);System.out.println("Enter Price: " +price1);System.out.println("Enter Quantity " +number1); System.out.println("Enter Item Number 2: " +item2);System.out.println("Enter Price: " +price2);System.out.println("Enter Quantity " +number2); System.out.println("Enter Item Number 33: " +item3);System.out.println("Enter Price: " +price3);System.out.println("Enter Quantity " +number3); System.out.println("Enter Item Number 4: " +item4);System.out.println("Enter Price: " +price4);System.out.println("Enter Quantity " +number4);System.out.println("Enter Item Number 5: " +item5); System.out.println("Enter Price: " +price5);System.out.println("Enter Quantity: " +number5);System.out.println("Payment: " +payment);  Seishinryoku.println(" " +item1);Seishinryoku.println(" " +price1);Seishinryoku.println(" " +number1); Seishinryoku.println(" " +item2);Seishinryoku.println(" " +price2);Seishinryoku.println(" " +number2); Seishinryoku.println(" " +item3);Seishinryoku.println(" " +price3);Seishinryoku.println(" " +number3); Seishinryoku.println(" " +item4);Seishinryoku.println(" " +price4);Seishinryoku.println(" " +number4); Seishinryoku.println(" " +item5);Seishinryoku.println(" " +price5);Seishinryoku.println(" " +number5);total = price1 * number1 + price2 * number2 + price3 * number3 + price4 * number4 + price5 * number5;System.out.println("Total: " +total);System.out.println("Payment: " +payment);change = payment - total;System.out.println("Here's your Change: " +change); Seishinryoku.flush();Seishinryoku.close();System.out.println("THANK YOU!!!!"); }  }
Link to post
Share on other sites
Sei.nextLine();

Put this after number1 = Sei.nextInt();, number2 = Sei.nextInt();, etc.

The reason why item2 and the rest are not displaying is that they contain the new line value ('/n') instead of the intended string.

So just put a nextLine() method to get read the new line char.

Link to post
Share on other sites

Have you learnt loops and arrays yet? That code could be 1/5th of what it is now


Axios! - Yes that's not a typo, its a 660 (for now) 2 980Ti s arriving soon



Intel i7-5820k | GTX 660 | Corsair Dominator Platinums 16GB | Asus X99-Pro | Corsair 760T | 2x ASUS PB278QR | NZXT X61 Kraken | EVGA SuperNOVA 1000G2 | Samsung 850 Pro

Link to post
Share on other sites

what is the program called to run the code?


Intel 4790k | Asus Z97 Maximus VII Impact | Corsair Vengeance Pro Series 16 GB 1866Mhz | Asus Strix GTX 980 | CoolerMaster G550 |Samsung Evo 250GB | Synology DS215j (NAS) | Logitech G502 |

 

Link to post
Share on other sites

Have you learnt loops and arrays yet? That code could be 1/5th of what it is now

Most likely yes :) I had to do something similar when learning to code. 


[ Cruel Angel ]:     Exterior  -   BENQ XL2420T   |   SteelSeries MLG Sensei   |   Corsair K70 RED   |   Corsair 900D  |                                                                                                    CPU:    -   4.7Ghz @ 1.425v             |

                             Interior    -   i7 4770k   |    Maximus VI Formula    |   Corsair Vengeance Pro 16GB    |   ASUS GTX 980 Strix SLIx2  |  840 Pro 512Gb    |    WD Black 2TB  |           RAM:   -   2400Mhz OC @ 1.650v    |

                             Cooling   -   XSPC 120mm x7 Total Radiator Space   |   XSPC RayStorm    |    PrimoChill Tubing/Res  |                                                                                             GPU:   -   1000Mhz @ 1.158            |

Link to post
Share on other sites

Here is just your code above but using loops and I also implemented the solution reiderj8 said.
 

import java.io.*;import java.util.*;public class ReceiptProgram { 	public static Scanner Sei = new Scanner(System.in); 	public static void main(String[] args) throws FileNotFoundException{		int day, month, year;		int second, minute, hour;		GregorianCalendar date = new GregorianCalendar(); 		day = date.get(Calendar.DAY_OF_MONTH);		month = date.get(Calendar.MONTH);		year = date.get(Calendar.YEAR); 		second = date.get(Calendar.SECOND);		minute = date.get(Calendar.MINUTE);		hour = date.get(Calendar.HOUR);		System.out.println("Zero DEGREE MALL ");		System.out.println(" 999 HDS BUILDING, Butuan City ");		System.out.println(" 09096082036 ");     		System.out.println("Current date is  "+(month+1)+"/"+day+"/"+year);		System.out.println("Current time is  "+hour+" : "+minute+" : "+second);		System.out.println(" ");  		input();	} 	public static Object Seishin;		public static void input()throws FileNotFoundException{		PrintWriter Seishinryoku = new PrintWriter("Receipt.txt");		String[][] item = new String[5][80];		int[] number = new int[5];		double[] price = new double[5];		double payment;		double total;		double change;	 		for ( int i = 0; i < 5; i++ ) {			System.out.println("Enter Item Number " + (i+1) + ": ");			item[i][0] = Sei.nextLine();			System.out.println("Enter Price: ");			price[i] = Sei.nextDouble();			Sei.nextLine();			System.out.println("Enter Quantity: ");			number[i] = Sei.nextInt();			Sei.nextLine();		}				for (int i = 0; i < 5; i++ ) {			System.out.println("Enter Item Number 1: " + item[i]);			System.out.println("Enter Price: " + price[i]);			System.out.println("Enter Quantity " + number[i]);		}	 		for ( int i = 0; i < 5; i++ ) {			Seishinryoku.println(" " +item[i]);			Seishinryoku.println(" " +price[i]);			Seishinryoku.println(" " +number[i]);		}				total = price[0] * number[0] + price[1] * number[1] + price[2] * number[2] + price[3] * number[3] + price[4] * number[4];		System.out.println("Total: " + total);		System.out.println("Enter Payment: ");		payment = Sei.nextDouble();		System.out.println("Payment: " + payment);		change = payment - total;		if ( change < 0 ) {			System.out.println("You have not given enough money");		} else if ( change > 0 ) {			System.out.println("Here's your Change: " + change);		} else {			System.out.println("You don't require change");		}	 		Seishinryoku.flush();		Seishinryoku.close();		System.out.println("THANK YOU!!!!");	 	}}
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

Newegg

×