-
Notifications
You must be signed in to change notification settings - Fork 0
/
laboratorio3.java
69 lines (58 loc) · 2.29 KB
/
laboratorio3.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package programacion3;
/**
*
* @author tguca-L01
*/
public class laboratorio3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
/**
* Creamos un arr para cada una de las variables en las cuales
* podremosn iterar dentro de un bucle for.
*/
String cp[] = {"P01","P02","P03","P04","P05"};
String np[] = {"QUESO","PAPAS","MARGARINA","HUEVOS","CHILE(4oz)"};
int c[] = {3,2,1,2,3};
double p[] = {47.50,8.45,9.30,45.00,7.20};
boolean g[] = {false,false,true,false,true};
double st[] = {0,0,0,0,0};
double imp[] = {0,0,0,0,0};
double t[] = {0,0,0,0,0};
double tp = 0;
//definiendo formatos para print System.out.format
String f1, f2, f3, f4, f5, f6, f7, f8, fg;
f1 = "%-8s";
f2 = "%-15s";
f3 = "%-10d";
f4 = "%-16.2f";
f5 = "%-15b";
f6 = "%-17.2f";
f7 = "%-15.2f";
f8 = "%-9.2f";
fg = f1+f2+f3+f4+f5+f6+f7+f8+"\n";
System.out.println("=================================================");
System.out.println("COD\tPRODUCTO CANTIDAD\tPRECIO\t\tGRABABILIDAD"
+ "\tSUBTOTAL\tIMPUESTO\tTOTAL");
System.out.println("=================================================");
/**
* Creamos un ciclo For que calcule todas subTotal, determine si g es
* t/f para calcular el impuesto, total & total productos.
*/
for(int i =0; i<5; i++){
st[i] = p[i]*c[i];
if(g[i])imp[i]= st[i]*0.15; else imp[i]=0;
t[i] = st[i] * imp[i];
tp = tp + t[i];
System.out.format(fg,cp[i],np[i],c[i],p[i],g[i],st[i],imp[i],t[i]);}
System.out.println("=================================================");
System.out.println("Total a pagar " + tp);
System.out.println("=================================================");
}
}