programa de los cochis - ayuda porfa
Publicado por jose (1 intervención) el 03/06/2010 08:53:07
ya esta ordenado solo necesito que me muestre en resumen la informacion
los archivos de catalogo y de los productos yo los tengo contactene pero ya
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pf;
/**
*
* @author PEpe
*/
import java.io.*;
import java.util.Arrays;
import javax.swing.*;
class LeeFichero {
public JFrame ventana;
public static void main(String [] arg) {
File archivo = null;
FileReader fr = null;
BufferedReader br = null;
int k=0;
String [] subject= new String [2000];
String [] resultado= new String [2000];
String [] ordenado= new String [2000];
int mas=0;
Integer menu;
do{
menu=Integer.parseInt(JOptionPane.showInputDialog(" Proyecto Final \n\nAutor: José de Jesús Gastélum Peña \n\n Reportes de Cargas de \n Producto Porcino \n a Transporte\n\n ****** Menú Principal ****** \n\n1.- Teclee el numero 1 para ver el reporte\n2.- Teclee el numero 2 para salir \n\n"));
switch(menu){
case 1:
try {
// Apertura del fichero y creacion de BufferedReader para poder
// hacer una lectura comoda (disponer del metodo readLine()).
// archivo = new File ("C:\\DATOS\\3121444.txt");
// Lectura del fichero
String first="C:\\DATOS\\";
String second=".txt";
String nombre=JOptionPane.showInputDialog("Escribe el nombre del archivo: ");
String nombre_archivo=first+nombre+second;
archivo = new File (nombre_archivo);
// archivo = new File ("C:\\DATOS\\04091402.txt");
fr = new FileReader (archivo);
br = new BufferedReader(fr);
int cajas=0;
double kilos=0;
double producto=0;
// Lectura del fichero
String linea;
while((linea=br.readLine())!=null){
String clave= linea.substring(3, 10);
String peso=linea.substring(10, 16);
float entero;
double primero;
int segundo;
entero=Integer.parseInt(peso.substring(0, 2));
primero= Double.valueOf("0."+peso.substring(2, 3)).doubleValue();
segundo=Integer.parseInt(peso.substring(3, 4));
//para sacar los kilos
if (segundo>5){
primero=primero+.10;
}
producto=entero+primero;
//para sacar los kilos
kilos=kilos+producto;
cajas++;
///------------
File catalogo = null;
FileReader jr = null;
BufferedReader gr = null;
try {
// Apertura del fichero y creacion de BufferedReader para poder
// hacer una lectura comoda (disponer del metodo readLine()).
catalogo = new File ("C:\\DATOS\\CATALOGO_ARTICULOS.txt");
jr = new FileReader (catalogo);
gr = new BufferedReader(jr);
int incremento=0;
int numero, cla ;
cla= Integer.parseInt(clave);
// Lectura del fichero
String cat;
while((cat=gr.readLine())!=null){
incremento++;
String be=cat.substring(0,7);
String produ=cat.substring(7);
String pro="1"+" "+be+" "+produ;
numero= Integer.parseInt(be);
if (numero==cla){
resultado[incremento]=pro;
String numerobox=resultado[incremento].substring(0,1);
String codfin=resultado[incremento].substring(2,9);
String produfin=resultado[incremento].substring(10);
String pesofin= String.valueOf(producto);
ordenado[mas]=" "+codfin+" "+numerobox+" "+produfin+" "+pesofin;
mas++;
}
}
}
catch(Exception e){
e.printStackTrace();
}finally{}
///----------------
}
kilos= ((double)Math.round(kilos*100)/100);
subject[2]= "Total de Kilos: "+String.valueOf(kilos)+" kg";
subject[1]= "Total de Cajas: "+String.valueOf(cajas);
subject[0]="ARCHIVO: " + nombre+ ".txt";
subject[3]=" CODIGO CAJAS PRODUCTO PESO";
int tamaño=0;
for (int i=0; i<2000; i++){
if(ordenado[i]==null){}
else{
tamaño++;
}
}
String [] redimenzion= new String [tamaño];
for(int j=0; j<tamaño; j++){
redimenzion[j]=ordenado[j];
}
Arrays.sort(redimenzion);
int s=7;
for(String listaOrdenada:redimenzion){
subject[s]=listaOrdenada;
s++;
}
JFrame frame = new JFrame("Reporte de Transporte");
JPanel panel = new JPanel();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JList list = new JList(subject);
JScrollPane scroll = new JScrollPane();
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
panel.add(list);
frame.add(panel);
frame.getContentPane().add(scroll);
scroll.setViewportView(list);
frame.setSize(500,500);
frame.setVisible(true);
}
catch(Exception e){
e.printStackTrace();
}finally{
// En el finally se cierra el fichero
try{
if( null != fr ){
fr.close();
}
}catch (Exception e2){
e2.printStackTrace();
}
}
break;
}
} while(menu!=2);
System.exit(0);
}
}
los archivos de catalogo y de los productos yo los tengo contactene pero ya
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pf;
/**
*
* @author PEpe
*/
import java.io.*;
import java.util.Arrays;
import javax.swing.*;
class LeeFichero {
public JFrame ventana;
public static void main(String [] arg) {
File archivo = null;
FileReader fr = null;
BufferedReader br = null;
int k=0;
String [] subject= new String [2000];
String [] resultado= new String [2000];
String [] ordenado= new String [2000];
int mas=0;
Integer menu;
do{
menu=Integer.parseInt(JOptionPane.showInputDialog(" Proyecto Final \n\nAutor: José de Jesús Gastélum Peña \n\n Reportes de Cargas de \n Producto Porcino \n a Transporte\n\n ****** Menú Principal ****** \n\n1.- Teclee el numero 1 para ver el reporte\n2.- Teclee el numero 2 para salir \n\n"));
switch(menu){
case 1:
try {
// Apertura del fichero y creacion de BufferedReader para poder
// hacer una lectura comoda (disponer del metodo readLine()).
// archivo = new File ("C:\\DATOS\\3121444.txt");
// Lectura del fichero
String first="C:\\DATOS\\";
String second=".txt";
String nombre=JOptionPane.showInputDialog("Escribe el nombre del archivo: ");
String nombre_archivo=first+nombre+second;
archivo = new File (nombre_archivo);
// archivo = new File ("C:\\DATOS\\04091402.txt");
fr = new FileReader (archivo);
br = new BufferedReader(fr);
int cajas=0;
double kilos=0;
double producto=0;
// Lectura del fichero
String linea;
while((linea=br.readLine())!=null){
String clave= linea.substring(3, 10);
String peso=linea.substring(10, 16);
float entero;
double primero;
int segundo;
entero=Integer.parseInt(peso.substring(0, 2));
primero= Double.valueOf("0."+peso.substring(2, 3)).doubleValue();
segundo=Integer.parseInt(peso.substring(3, 4));
//para sacar los kilos
if (segundo>5){
primero=primero+.10;
}
producto=entero+primero;
//para sacar los kilos
kilos=kilos+producto;
cajas++;
///------------
File catalogo = null;
FileReader jr = null;
BufferedReader gr = null;
try {
// Apertura del fichero y creacion de BufferedReader para poder
// hacer una lectura comoda (disponer del metodo readLine()).
catalogo = new File ("C:\\DATOS\\CATALOGO_ARTICULOS.txt");
jr = new FileReader (catalogo);
gr = new BufferedReader(jr);
int incremento=0;
int numero, cla ;
cla= Integer.parseInt(clave);
// Lectura del fichero
String cat;
while((cat=gr.readLine())!=null){
incremento++;
String be=cat.substring(0,7);
String produ=cat.substring(7);
String pro="1"+" "+be+" "+produ;
numero= Integer.parseInt(be);
if (numero==cla){
resultado[incremento]=pro;
String numerobox=resultado[incremento].substring(0,1);
String codfin=resultado[incremento].substring(2,9);
String produfin=resultado[incremento].substring(10);
String pesofin= String.valueOf(producto);
ordenado[mas]=" "+codfin+" "+numerobox+" "+produfin+" "+pesofin;
mas++;
}
}
}
catch(Exception e){
e.printStackTrace();
}finally{}
///----------------
}
kilos= ((double)Math.round(kilos*100)/100);
subject[2]= "Total de Kilos: "+String.valueOf(kilos)+" kg";
subject[1]= "Total de Cajas: "+String.valueOf(cajas);
subject[0]="ARCHIVO: " + nombre+ ".txt";
subject[3]=" CODIGO CAJAS PRODUCTO PESO";
int tamaño=0;
for (int i=0; i<2000; i++){
if(ordenado[i]==null){}
else{
tamaño++;
}
}
String [] redimenzion= new String [tamaño];
for(int j=0; j<tamaño; j++){
redimenzion[j]=ordenado[j];
}
Arrays.sort(redimenzion);
int s=7;
for(String listaOrdenada:redimenzion){
subject[s]=listaOrdenada;
s++;
}
JFrame frame = new JFrame("Reporte de Transporte");
JPanel panel = new JPanel();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JList list = new JList(subject);
JScrollPane scroll = new JScrollPane();
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
panel.add(list);
frame.add(panel);
frame.getContentPane().add(scroll);
scroll.setViewportView(list);
frame.setSize(500,500);
frame.setVisible(true);
}
catch(Exception e){
e.printStackTrace();
}finally{
// En el finally se cierra el fichero
try{
if( null != fr ){
fr.close();
}
}catch (Exception e2){
e2.printStackTrace();
}
}
break;
}
} while(menu!=2);
System.exit(0);
}
}
Valora esta pregunta


0