Ver Mensaje Individual
  #6 (permalink)  
Antiguo 11/01/2012, 10:48
Kyokatallama
 
Fecha de Ingreso: enero-2012
Ubicación: Madrid
Mensajes: 15
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: Fallo en crear objeto de una clase.

Como cambio el IDE? Aunque con estando todo en el mismo paquete, deberían verse sin necesidad de mas, no?

Te pongo el código (hoy no avance nada...):

package Practica;

public class edificio {
int inicio;
int fin;
int altura;

public edificio(int inicio, int fin, int altura) {
super();
this.inicio = inicio;
this.fin = fin;
this.altura = altura;
}

public int getInicio() {
return inicio;
}
public void setInicio(int inicio) {
this.inicio = inicio;
}
public int getFin() {
return fin;
}
public void setFin(int fin) {
this.fin = fin;
}
public int getAltura() {
return altura;
}
public void setAltura(int altura) {
this.altura = altura;
}
}



package Practica;

public class TipoSkyline {
int cambio;
int altura;

public TipoSkyline(int cambio, int altura) {
super();
this.cambio = cambio;
this.altura = altura;
}

public int getCambio() {
return cambio;
}
public void setCambio(int cambio) {
this.cambio = cambio;
}
public int getAltura() {
return altura;
}
public void setAltura(int altura) {
this.altura = altura;
}
}



package Practica;

import java.io.*;
import java.util.*;

public class Main {

public static void main(String[] args) throws IOException {

String[] edificio;
ArrayList<edificio> ciudad = new ArrayList<edificio>();
ArrayList<TipoSkyline> linea = new ArrayList<TipoSkyline>();
int temp;

Scanner fin = new Scanner(new File("src/skyline.in"));

while (fin.hasNextLine()) {
String line = fin.nextLine();
edificio = line.split(" ");
ciudad.add(new edificio(Integer.valueOf(edificio[0]),Integer.valueOf(edificio[1]),Integer.valueOf(edificio[2])));
}

for (edificio e :ciudad){
System.out.println("inicio:"+" "+e.inicio+" "+"fin:"+" "+e.fin+" "+"altura:"+" "+e.altura);
}

temp = ciudad.size();

linea = DyV(ciudad, 0, temp);
salida1(linea);
}

private static void salida1(ArrayList<TipoSkyline> linea) {
for (TipoSkyline sky :linea){
System.out.println(sky.getAltura() +" "+sky.getCambio());
}
}
public static ArrayList<TipoSkyline> DyV(ArrayList<edificio> c, int i, int j) {

int m,n;
ArrayList<TipoSkyline> s = new ArrayList<TipoSkyline>();
ArrayList<TipoSkyline> s1 = new ArrayList<TipoSkyline>();
ArrayList<TipoSkyline> s2 = new ArrayList<TipoSkyline>();


m = (i + j)/2;
n = j - i;

if (n == 1) {
s.add(new TipoSkyline((c.get(i).getInicio()), (c.get(i).getAltura())));
return s;
}
else {
s1 = DyV(c, i, m);
s2 = DyV(c, m+1, j);
s = Combinar(s1, s2);
return s;
}
}

public static ArrayList<TipoSkyline> Combinar (ArrayList<TipoSkyline> s1c, ArrayList<TipoSkyline> s2c) {

int ic, jc, k, x, i1, i2;
int nc, mc, maximo;
int z, v;
ArrayList<Integer> s1x, s1h, s2x, s2h, sx, sh;
ArrayList<TipoSkyline> sc = new ArrayList<TipoSkyline>();

s1x = new ArrayList<Integer>();
s1h = new ArrayList<Integer>();
s2x = new ArrayList<Integer>();
s2h = new ArrayList<Integer>();
sx = new ArrayList<Integer>();
sh = new ArrayList<Integer>();

nc = s1c.size() - 1;
mc = s2c.size() - 1;

i1 = 0;
i2 = 0;

while (i1 <= nc){
s1x.add(new Integer(s1c.get(i1).getCambio()));
s1h.add(new Integer(s1c.get(i1).getAltura()));
i1 = i1 + 1;
}

while (i2 <= nc){
//s2h[0] = s2.get(0).getAltura();
i2 = i2 + 1;
}

ic = 0;
jc = 0;
k = 0;

while ((ic <= nc) || (jc <= mc)) {

x = Math.min(s1x.get(ic), s2x.get(jc));

if ((s1x.get(ic)) <= (s2x.get(jc))) {
maximo = Math.max(s1h.get(ic), s2h.get(jc - 1));
ic = ic + 1;
}
else
if ((s1x.get(ic)) > (s2x.get(jc))) {
maximo = Math.max(s1h.get(ic - 1), s2h.get(jc));
jc = jc + 1;
}
else {
maximo = Math.max(s1h.get(ic), s2h.get(jc));
ic = ic + 1;
jc = jc + 1;
}

sx.add(k, new Integer(x));
sh.add(k, new Integer(maximo));
k = k + 1;
}
v = 0; z = 0;
while ((v != sx.size()) || (z != sh.size())){
sc.add(new TipoSkyline(sx.get(v),sh.get(z)));
v = v + 1;
z = z +1;
}
return sc;
}
}