forked from stiers/COPRO2_SampleJavaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Change.java
54 lines (42 loc) · 1.5 KB
/
Change.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Project Name: Change
* Project Description: Simple emulation of Cash Register
* Project Author: Ephramar A. Telog, CK
*/
import java.io.*;
public class Change {
public static void main( String[] arguments ) throws IOException {
BufferedReader input = new BufferedReader( new InputStreamReader( System.in ) );
double numberOfItems[] = new double[100];
double payment = 0, total = 0, tax = 0, cost = 0;
System.out.print( "Number of Item(s): " );
int items = Integer.parseInt( input.readLine() );
System.out.print( "\n" );
for( int i = 0; i < items; i ++ ) {
System.out.print( "Item Price: " );
numberOfItems[i] = Double.parseDouble( input.readLine() );
total += numberOfItems[i];
}
tax = total * 0.06;
cost = tax + total;
System.out.println( "\n"+ items +" Item(s)" );
System.out.println( "Total Sale: " + total );
System.out.println( "VAT (6%): " + tax );
System.out.println( "Total Amount: " + cost );
System.out.println( "____________________________" );
while( payment < cost ) {
System.out.print( "\nPlease Enter Your Cash: " );
payment = Double.parseDouble( input.readLine() );
if( payment < cost ) {
System.out.println( "\nInsufficient Fund!" );
}
else {
System.out.println( "____________________________" );
System.out.println( "\nCash: " + payment );
System.out.println( "Change: " + ( payment - cost ) );
System.out.println( "\nThank You!" );
System.out.println( "Please Come Again!" );
}
}
}
}