Opzione 1 + menù migliorato
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
package rettangoli_quadrati;
|
package rettangoli_quadrati;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.InputMismatchException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -19,17 +20,17 @@ public class Rettangoli_Quadrati {
|
|||||||
static Scanner sc = new Scanner(System.in);
|
static Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int scelta;
|
Rettangolo forme[] = Init();
|
||||||
|
int scelta, nextPosizioneLibera = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
System.out.println("Scegliere un'opzione:");
|
System.out.println("Scegliere un'opzione:");
|
||||||
System.out.println("1. Ingresso auto");
|
System.out.println("1. Inserimento dimensioni");
|
||||||
System.out.println("2. Stampa posti occupati");
|
System.out.println("2. Confronta aree");
|
||||||
System.out.println("3. Stampa posti liberi");
|
|
||||||
System.out.println("4. Uscita auto");
|
|
||||||
System.out.println("0. Esci");
|
System.out.println("0. Esci");
|
||||||
System.out.print("Opzione: ");
|
System.out.print("Opzione: ");
|
||||||
|
|
||||||
|
try {
|
||||||
scelta = sc.nextInt();
|
scelta = sc.nextInt();
|
||||||
sc.nextLine();
|
sc.nextLine();
|
||||||
|
|
||||||
@@ -37,19 +38,21 @@ public class Rettangoli_Quadrati {
|
|||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
System.out.println(garage.IngressoAuto());
|
forme[nextPosizioneLibera] = CreaRettangolo(IngressoDati(1), IngressoDati(2));
|
||||||
|
forme[nextPosizioneLibera + 1] = CreaQuadrato(IngressoDati(3));
|
||||||
|
nextPosizioneLibera = +2;
|
||||||
|
System.out.println("Forme create con successo");
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
System.out.println(garage.GetPostiOccupati());
|
// System.out.println(garage.GetPostiOccupati());
|
||||||
Pausa();
|
//Debug: Controllo che funzioni tutto
|
||||||
break;
|
System.out.println(forme[0].dimensioneUno);
|
||||||
case 3:
|
System.out.println(forme[0].dimensioneDue);
|
||||||
System.out.println(garage.GetPostiLiberi());
|
System.out.println(forme[0].isQuadrato);
|
||||||
Pausa();
|
System.out.println(forme[1].dimensioneUno);
|
||||||
break;
|
System.out.println(forme[1].dimensioneDue);
|
||||||
case 4:
|
System.out.println(forme[1].isQuadrato);
|
||||||
System.out.println(garage.UscitaAuto());
|
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -58,6 +61,11 @@ public class Rettangoli_Quadrati {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} catch (InputMismatchException e) {
|
||||||
|
System.out.println("Opzione non valida.");
|
||||||
|
Pausa();
|
||||||
|
scelta = -1;
|
||||||
|
}
|
||||||
} while (scelta != 0);
|
} while (scelta != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,4 +73,73 @@ public class Rettangoli_Quadrati {
|
|||||||
System.out.println("Premere un tasto per continuare. . .");
|
System.out.println("Premere un tasto per continuare. . .");
|
||||||
sc.nextLine();
|
sc.nextLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Rettangolo[] Init() {
|
||||||
|
boolean error;
|
||||||
|
int dimensione = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = false;
|
||||||
|
try {
|
||||||
|
System.out.println("Quante coppie di forme gestire? ");
|
||||||
|
|
||||||
|
dimensione = sc.nextInt();
|
||||||
|
sc.nextLine();
|
||||||
|
|
||||||
|
if (dimensione <= 0) {
|
||||||
|
System.out.println("Errore: inserire una dimensione "
|
||||||
|
+ (dimensione == 0 ? "diversa da" : "maggiore di") + " 0.");
|
||||||
|
Pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} catch (InputMismatchException e) {
|
||||||
|
System.out.println("Errore: dimensione non valida.");
|
||||||
|
Pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} while (error);
|
||||||
|
|
||||||
|
return new Rettangolo[dimensione];
|
||||||
|
}
|
||||||
|
|
||||||
|
static double IngressoDati(int p_selettore) {
|
||||||
|
double ritorno = 0;
|
||||||
|
boolean error;
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = false;
|
||||||
|
try {
|
||||||
|
if (p_selettore == 1) {
|
||||||
|
System.out.println("Inserisci la prima dimensione del rettangolo: ");
|
||||||
|
} else if (p_selettore == 2) {
|
||||||
|
System.out.println("Inserisci la seconda dimensione del rettangolo: ");
|
||||||
|
} else if (p_selettore == 3) {
|
||||||
|
System.out.println("Inserisci dimensione del quadrato: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
ritorno = sc.nextDouble();
|
||||||
|
sc.nextLine();
|
||||||
|
|
||||||
|
if (ritorno <= 0) {
|
||||||
|
System.out.println("Errore: inserire una dimensione "
|
||||||
|
+ (ritorno == 0 ? "diversa da" : "maggiore di") + " 0.");
|
||||||
|
Pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} catch (InputMismatchException e) {
|
||||||
|
System.out.println("Errore: dimensione non valida.");
|
||||||
|
Pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} while (error);
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Rettangolo CreaRettangolo(double p_dimensioneUno, double p_dimensioneDue) {
|
||||||
|
return new Rettangolo(p_dimensioneUno, p_dimensioneDue, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Rettangolo CreaQuadrato( double p_dimensione) {
|
||||||
|
return new Rettangolo(p_dimensione, p_dimensione, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package rettangoli_quadrati;
|
package rettangoli_quadrati;
|
||||||
|
|
||||||
public class Rettangolo {
|
public class Rettangolo {
|
||||||
private boolean isQuadrato;
|
//Debug: public per testare che funzioni tutto
|
||||||
private double dimensioneUno, dimensioneDue;
|
public boolean isQuadrato;
|
||||||
|
public double dimensioneUno, dimensioneDue;
|
||||||
|
|
||||||
public Rettangolo(double p_dimensioneUno, double p_dimensioneDue, boolean p_isQuadrato) {
|
public Rettangolo(double p_dimensioneUno, double p_dimensioneDue, boolean p_isQuadrato) {
|
||||||
this.dimensioneUno = p_dimensioneUno;
|
this.dimensioneUno = p_dimensioneUno;
|
||||||
|
|||||||
Reference in New Issue
Block a user