VegetaSSJ5
02-11-2004, 19:31
Salve a tutti, per esercitarmi in java sto cercando di fare un piccolo package di prova che contiene la classe lato e la classe forma. Ora non badate a quello che è scritto nel codice visto che non è quello ciò su cui mi sto concentrando ma è proprio la creazione del package. Ho creato due files che sono Lato.java (che si compila correttamente):package figure;
public class Lato {
private float lunghezza;
public Lato (float l) throws IllegalArgumentException {
if (l<=0) throw new IllegalArgumentException();
else this.lunghezza=l;
}
public void setL (float l) throws IllegalArgumentException {
if (l<=0) throw new IllegalArgumentException();
else this.lunghezza=l;
}
public float getL () {
return this.lunghezza;
}
}e Forma.java (mi dà errore dicendo "cannot resolve symbol getL()"):package figure;
import java.util.*;
public abstract class Forma {
LinkedList list= new LinkedList();
public Forma () {
}
public void addLato (float lunghezza) {
Lato l;
while (true) {
try{
l= new Lato(lunghezza);
break;
}
catch (IllegalArgumentException e) {
System.out.println("E' stato inserito un valore negativo o nullo per il lato");
System.out.println("Per favore inserire un valore positivo");
}
}
this.list.add(l);
}
public float Perimetro () {
int i;
float perimetro=0;
for (i=0; i<this.list.size(); i++) {
perimetro+=this.list.get(i).getL();
}
return perimetro;
}
public abstract float Area ();
}
public class Lato {
private float lunghezza;
public Lato (float l) throws IllegalArgumentException {
if (l<=0) throw new IllegalArgumentException();
else this.lunghezza=l;
}
public void setL (float l) throws IllegalArgumentException {
if (l<=0) throw new IllegalArgumentException();
else this.lunghezza=l;
}
public float getL () {
return this.lunghezza;
}
}e Forma.java (mi dà errore dicendo "cannot resolve symbol getL()"):package figure;
import java.util.*;
public abstract class Forma {
LinkedList list= new LinkedList();
public Forma () {
}
public void addLato (float lunghezza) {
Lato l;
while (true) {
try{
l= new Lato(lunghezza);
break;
}
catch (IllegalArgumentException e) {
System.out.println("E' stato inserito un valore negativo o nullo per il lato");
System.out.println("Per favore inserire un valore positivo");
}
}
this.list.add(l);
}
public float Perimetro () {
int i;
float perimetro=0;
for (i=0; i<this.list.size(); i++) {
perimetro+=this.list.get(i).getL();
}
return perimetro;
}
public abstract float Area ();
}