Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

pls help me to execute this code for pert analysis..

807588May 7 2009 — edited May 7 2009
hi friend;
i m new in java and i have downloaded some code for pert analysis which is giving some exception called run time .so,pls tell how to give the i/p..bcoz i faceing some at tha time. aur if u have pls send me pert analysis code..
the code is below.......
thanks

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Proyecto {

/**
* @param args
*/
public static void main(String[] args) {
String texto = null;
int n = 0, t = 0;
Tarea tareas[] = null, inicio = null, fin = null;

try {
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
texto = in.readLine();
n = Integer.parseInt(texto);

tareas = new Tarea[n];
inicio = new TareaInicio();
fin = new TareaFinal();
inicio.setNombre("Inicio");
inicio.setTiempo(0);
fin.setNombre("Fin");
fin.setTiempo(0);

for (int i = 0; i < n; i++) {
texto = in.readLine();
tareas[i] = new Tarea();
StringTokenizer st = new StringTokenizer(texto, ",");
String nombre, tipo, tiempo;
nombre = st.nextToken();
tipo = st.nextToken();
tareas.setNombre(nombre);
if (tipo.equals("F")) {
tiempo = st.nextToken();
tareas[i].setTiempo(Integer.parseInt(tiempo));
} else if (tipo.equals("A") || tipo.equals("P")) {
tareas[i].setTiempo(0);
}
}
texto = in.readLine();
t = Integer.parseInt(texto);
for (int i = 0; i < t; i++) {
String org, des;
Tarea torg = null, tdes = null;
texto = in.readLine();
StringTokenizer st = new StringTokenizer(texto, ",");
org = st.nextToken();
des = st.nextToken();
if (org.equals(inicio.getNombre())) {
torg = inicio;
} else {
for (int j = 0; j < n; j++) {
if (org.equals(tareas[j].getNombre())) {
torg = tareas[j];
break;
}
}
}

if (des.equals(fin.getNombre())) {
tdes = fin;
} else {
for (int j = 0; j < n; j++) {
if (des.equals(tareas[j].getNombre())) {
tdes = tareas[j];
break;
}
}
}
if (torg == null || tdes == null) {
}
torg.addConcecuente(tdes);
tdes.addAntecedente(torg);
}
} catch (IOException e) {
System.out.println("Error en entrada de datos");
}
fin.terminacionRapida();
inicio.inicioTardio();
System.out.print("Ruta Critica: Inicio, ");
for (int i = 0; i < n; i++) {
if (tareas[i].isCritico()) {
System.out.print(tareas[i].getNombre() + ", ");
}
}
System.out.print(" Fin\n");
System.out.println("Tiempo: " + fin.inicioTardio());
System.out.println(inicio.getNombre() + " holgura: "
+ inicio.getHolgura());
for (int i = 0; i < n; i++) {
System.out.println(tareas[i].getNombre() + " holgura: "
+ tareas[i].getHolgura());
}
System.out.println(fin.getNombre() + " holgura: " + fin.getHolgura());

}

}
////////////////////////

import java.util.ArrayList;

public class Tarea {
private String nombre;
private int tiempo;
private int holgura;
private ArrayList antecedentes;
private ArrayList consecuentes;

private int iniciomasrapido;
private int terminacionmasrapida;
private int iniciomastarde;
private int terminaciontarde;

Tarea(){
this.antecedentes = new ArrayList();
this.consecuentes = new ArrayList();
}

void setNombre(String nombre){
this.nombre=nombre;
}

void setTiempo(int tiempo){
this.tiempo=tiempo;
}

public String getNombre() {
return nombre;
}

public int getTiempo() {
return tiempo;
}

public int terminacionRapida(){
this.iniciomasrapido=0;
for (int i = 0; i < antecedentes.size(); i++) {
if(((Tarea)antecedentes.get(i)).terminacionRapida()>this.iniciomasrapido){
this.iniciomasrapido=((Tarea)antecedentes.get(i)).terminacionRapida();
}
}
this.terminacionmasrapida=this.iniciomasrapido+this.tiempo;
return (this.terminacionmasrapida);
}

public int inicioTardio(){
this.terminaciontarde=999999;
for (int i = 0; i < consecuentes.size(); i++) {
if(((Tarea)consecuentes.get(i)).inicioTardio()<this.terminaciontarde){
this.terminaciontarde=((Tarea)consecuentes.get(i)).inicioTardio();
}
}
this.iniciomastarde=this.terminaciontarde-this.tiempo;
return (this.iniciomastarde);
}

int getHolgura(){
this.holgura=this.iniciomastarde-this.iniciomasrapido;
return this.holgura;
}

@SuppressWarnings("unchecked")
public void addAntecedente(Tarea t){
this.antecedentes.add(t);
}

@SuppressWarnings("unchecked")
public void addConcecuente(Tarea t){
this.consecuentes.add(t);
}

boolean isCritico(){
return (this.getHolgura()==0);
}

}

/////////////////////////


public class TareaFinal extends Tarea {


public int inicioTardio(){
return this.terminacionRapida();
}

public int getHolgura(){
return 0;
}
}

///////////////////


public class TareaInicio extends Tarea {



public int terminacionRapida(){
return 0;
}

public int getHolgura(){
return 0;
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 4 2009
Added on May 7 2009
12 comments
189 views