
Cambiar de estructurada a Poo
Publicado por Alejandro (14 intervenciones) el 06/03/2016 01:48:44
Hola buen dia, vengo a solicitar su ayuda ó guía para cambiar este codigo estructurado a orientado a objetos, estoy aprediendo como hacerlo, pero me salto la duda de como dividirlo en clases para que cada una asuma una responsabilidad dada. Agradecería su ayuda
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Prueba {
public static void main(String args[]){
Properties propiedades = new Properties();
InputStream entrada = null;
String texto;
try {
entrada = new FileInputStream("Propiedades.properties");
// cargamos el archivo de propiedades
propiedades.load(entrada);
Scanner archivo;
archivo = new Scanner(new File(propiedades.getProperty("Datos")));
List<String>dulces,frutas;
dulces = new ArrayList<String>();
frutas = new ArrayList<String>();
String lineaEntrada;
while(archivo.hasNextLine()){
lineaEntrada = archivo.nextLine();
lineaEntrada = lineaEntrada.trim().toUpperCase();
if(lineaEntrada.charAt(0)=='D'){
dulces.add(lineaEntrada);
}else{
frutas.add(lineaEntrada);
}
}
int totalDulces = 0;
int totalFrutas = 0;
int i;
for(i = 0; i<dulces.size();i++){
int totalVentaActual = obtenerVentaArticulo(dulces.get(i));
System.out.println("venta= "+totalVentaActual);
totalDulces += totalVentaActual;
}
for(i = 0; i<frutas.size(); i++){
int totalVentaActual = obtenerVentaArticulo(frutas.get(i));
System.out.println("venta= "+totalVentaActual);
totalFrutas += totalVentaActual;
}
JOptionPane.showMessageDialog(null, "El total de frutas"+" "+totalFrutas+"\n"+"El total de dulces"+" "+totalDulces);
System.exit(0);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (entrada != null) {
try {
entrada.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static int obtenerVentaArticulo(String lineaVenta) {
int i;
int posicionComa = -1;
int salida = 0;
String textoEntero ="";
for(i=0; i<lineaVenta.length();i++){
if(lineaVenta.charAt(i)==','){
posicionComa =i;
break;
}
}
if(posicionComa != -1){
for(i=(posicionComa +1); i<lineaVenta.length();i++){
textoEntero =textoEntero + lineaVenta.charAt(i);
}
}
try{
// the String to int conversion happens here
salida = Integer.parseInt(textoEntero.trim());
}catch (NumberFormatException nfe){
System.out.println("NumberFormatException: " + nfe.getMessage());
}
return salida;
}
}
Valora esta pregunta


0