Initial Commit
This commit is contained in:
73
build.xml
Normal file
73
build.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="VerificaNovembre_B_Bassanetti" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project VerificaNovembre_B_Bassanetti.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="VerificaNovembre_B_Bassanetti-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
||||
3
manifest.mf
Normal file
3
manifest.mf
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
1771
nbproject/build-impl.xml
Normal file
1771
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=b11b056a
|
||||
build.xml.script.CRC32=2f059602
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.116.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=b11b056a
|
||||
nbproject/build-impl.xml.script.CRC32=6c14a5ec
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.116.0.48
|
||||
1
nbproject/private/private.properties
Normal file
1
nbproject/private/private.properties
Normal file
@@ -0,0 +1 @@
|
||||
user.properties.file=/home/Verde/.netbeans/27/build.properties
|
||||
86
nbproject/project.properties
Normal file
86
nbproject/project.properties
Normal file
@@ -0,0 +1,86 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processor.options=
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.modulepath=\
|
||||
${run.modulepath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
debug.test.modulepath=\
|
||||
${run.test.modulepath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/VerificaNovembre_B_Bassanetti.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
excludes=
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.modulepath=
|
||||
javac.processormodulepath=
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.modulepath=\
|
||||
${javac.modulepath}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=b_bassanetti.B_Bassanetti
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.modulepath=\
|
||||
${javac.modulepath}
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
run.test.modulepath=\
|
||||
${javac.test.modulepath}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
||||
15
nbproject/project.xml
Normal file
15
nbproject/project.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>VerificaNovembre_B_Bassanetti</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
589
src/b_bassanetti/B_Bassanetti.java
Normal file
589
src/b_bassanetti/B_Bassanetti.java
Normal file
@@ -0,0 +1,589 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package b_bassanetti;
|
||||
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author alunno
|
||||
*/
|
||||
public class B_Bassanetti {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
static Scanner sc = new Scanner(System.in);
|
||||
|
||||
public static void main(String[] args) {
|
||||
int scelta = -1;
|
||||
String sceltaCancellazione;
|
||||
Trecce trecce[] = null;
|
||||
boolean isTrecceEmpty = true;
|
||||
boolean error;
|
||||
BoxTrecce box;
|
||||
boolean doesBoxTrecceExist = false;
|
||||
|
||||
do {
|
||||
System.out.println("Inserire un'opzione:");
|
||||
System.out.println("1. Inserire le trecce profumate");
|
||||
System.out.println("2. Stampare tutte le trecce di una forma");
|
||||
System.out.println("3. Modificare i costi dei Trecce di una forma di una %");
|
||||
System.out.println("4. Visualizzare quali Trecce utilizzano il colore viola");
|
||||
System.out.println("5. Creare un BoxTrecce");
|
||||
System.out.println("6. Mostra BoxTrecce");
|
||||
System.out.println("0. Esci");
|
||||
System.out.print("Scelta: ");
|
||||
|
||||
try {
|
||||
scelta = sc.nextInt();
|
||||
sc.nextLine();
|
||||
switch (scelta) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (isTrecceEmpty) {
|
||||
trecce = inserisciTrecce();
|
||||
System.out.println("Tutte le trecce sono state inserite con successo.");
|
||||
isTrecceEmpty = false;
|
||||
} else {
|
||||
do {
|
||||
error = false;
|
||||
System.out.println("Attenzione: procedendo si cancelleranno le precedenti trecce.");
|
||||
System.out.print("Si vuole proseguire [S/N]? ");
|
||||
sceltaCancellazione = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
switch (sceltaCancellazione) {
|
||||
case "s":
|
||||
trecce = inserisciTrecce();
|
||||
System.out.println("Tutte le trecce sono state inserite con successo.");
|
||||
case "n":
|
||||
break;
|
||||
default:
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
} while (error);
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 2:
|
||||
if (!isTrecceEmpty) {
|
||||
stampaTreccePerForma(trecce);
|
||||
} else {
|
||||
System.out.println("Errore: è necessario inserire le trecce prima di stamparle.");
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 3:
|
||||
if (!isTrecceEmpty) {
|
||||
modificaPrezzoPercentuale(trecce);
|
||||
System.out.println("Il prezzo è stato odificato correttamente.");
|
||||
} else {
|
||||
System.out.println("Errore: è necessario inserire le trecce prima di modificarne il prezzo.");
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 4:
|
||||
if (!isTrecceEmpty) {
|
||||
stampaTreccePerColore(trecce);
|
||||
} else {
|
||||
System.out.println("Errore: è necessario inserire le trecce prima di stamparle.");
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 5:
|
||||
if (!doesBoxTrecceExist) {
|
||||
if (doesBoxTrecceExist) {
|
||||
box = creaBoxTrecce(trecce);
|
||||
System.out.println("Il box è stato creato con successo.");
|
||||
doesBoxTrecceExist = false;
|
||||
} else {
|
||||
do {
|
||||
error = false;
|
||||
System.out.println("Attenzione: procedendo si cancellerà il box precedente.");
|
||||
System.out.print("Si vuole proseguire [S/N]? ");
|
||||
sceltaCancellazione = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
switch (sceltaCancellazione) {
|
||||
case "s":
|
||||
box = creaBoxTrecce(trecce);
|
||||
System.out.println("Il box è stato creato con successo.");
|
||||
case "n":
|
||||
break;
|
||||
default:
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
} while (error);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Errore: è necessario inserire le trecce prima di creare un box.");
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 6:
|
||||
|
||||
pausa();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
break;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
}
|
||||
} while (scelta != 0);
|
||||
}
|
||||
|
||||
static void pausa() {
|
||||
System.out.println("Prememe un tasto per continuare. . .");
|
||||
sc.nextLine();
|
||||
}
|
||||
|
||||
static Trecce[] inserisciTrecce() {
|
||||
boolean error;
|
||||
int numeroTrecce;
|
||||
int codice;
|
||||
String nome;
|
||||
String forma;
|
||||
String colore;
|
||||
double costo;
|
||||
int scelta = -1;
|
||||
|
||||
numeroTrecce = numeroTrecce();
|
||||
Trecce ritorno[] = new Trecce[numeroTrecce];
|
||||
|
||||
for (int i = 0; i < numeroTrecce; i++) {
|
||||
codice = codice();
|
||||
|
||||
System.out.print("Inserire il nome della treccia: ");
|
||||
nome = sc.nextLine().trim();
|
||||
|
||||
System.out.print("Inserire la forma della treccia: ");
|
||||
forma = sc.nextLine().trim();
|
||||
|
||||
System.out.print("Inserire il colore della treccia: ");
|
||||
colore = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
costo = costo();
|
||||
|
||||
do {
|
||||
error = false;
|
||||
|
||||
System.out.println("Di che tipologia è la treccia? ");
|
||||
System.out.println("1. Piccola");
|
||||
System.out.println("2. Media");
|
||||
System.out.println("3. Grande");
|
||||
System.out.print("Scelta: ");
|
||||
|
||||
try {
|
||||
scelta = sc.nextInt();
|
||||
sc.nextLine();
|
||||
switch (scelta) {
|
||||
case 1:
|
||||
ritorno[i] = piccola(codice, nome, forma, colore, costo);
|
||||
break;
|
||||
case 2:
|
||||
ritorno[i] = media(codice, nome, forma, colore, costo);
|
||||
break;
|
||||
case 3:
|
||||
ritorno[i] = grande(codice, nome, forma, colore, costo);
|
||||
break;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
System.out.println("Treccia inserita con successo.");
|
||||
pausa();
|
||||
}
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static int numeroTrecce() {
|
||||
boolean error;
|
||||
int ritorno = -1;
|
||||
do {
|
||||
try {
|
||||
error = false;
|
||||
System.out.print("Quante trecce inserire? ");
|
||||
ritorno = sc.nextInt();
|
||||
|
||||
if (ritorno <= 0) {
|
||||
System.out.println("Errore: il numero di trecce deve essere un numero maggiore di zero.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Numero non valido.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
|
||||
} while (error);
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static int codice() {
|
||||
boolean error;
|
||||
int ritorno = -1;
|
||||
do {
|
||||
try {
|
||||
error = false;
|
||||
System.out.print("Inserisci il codice: ");
|
||||
ritorno = sc.nextInt();
|
||||
sc.nextLine();
|
||||
|
||||
if (ritorno <= 0) {
|
||||
System.out.println("Errore: il codice deve essere un numero maggiore di zero.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Codice non valido.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
|
||||
} while (error);
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static double costo() {
|
||||
boolean error;
|
||||
double ritorno = -1;
|
||||
do {
|
||||
try {
|
||||
error = false;
|
||||
System.out.print("Inserisci il prezzo: ");
|
||||
ritorno = sc.nextDouble();
|
||||
sc.nextLine();
|
||||
|
||||
if (ritorno <= 0) {
|
||||
System.out.println("Errore: il prezzo deve essere un numero maggiore di zero.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Prezzo non valido.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
|
||||
} while (error);
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static Piccola piccola(int codice, String nome, String forma, String colore, double costo) {
|
||||
Piccola ritorno;
|
||||
String tipoCera;
|
||||
String tipoFiore;
|
||||
|
||||
System.out.print("Inserire il tipo di cera: ");
|
||||
tipoCera = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
System.out.print("Inserire il tipo di fiore: ");
|
||||
tipoFiore = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
ritorno = new Piccola(codice, nome, forma, colore, costo, tipoCera, tipoFiore);
|
||||
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static Media media(int codice, String nome, String forma, String colore, double costo) {
|
||||
Media ritorno;
|
||||
String tipoLegno;
|
||||
String tipoFiocco;
|
||||
|
||||
System.out.print("Inserire il tipo di legno: ");
|
||||
tipoLegno = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
System.out.print("Inserire il tipo di fiocco: ");
|
||||
tipoFiocco = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
ritorno = new Media(codice, nome, forma, colore, costo, tipoLegno, tipoFiocco);
|
||||
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static Grande grande(int codice, String nome, String forma, String colore, double costo) {
|
||||
Grande ritorno;
|
||||
String tipoPalline;
|
||||
String tipoNastro;
|
||||
|
||||
System.out.print("Inserire il tipo di palline: ");
|
||||
tipoPalline = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
System.out.print("Inserire il tipo di nastro: ");
|
||||
tipoNastro = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
ritorno = new Grande(codice, nome, forma, colore, costo, tipoPalline, tipoNastro);
|
||||
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static void stampaTreccePerForma(Trecce[] trecce) {
|
||||
int scelta = -1;
|
||||
boolean error;
|
||||
|
||||
do {
|
||||
error = false;
|
||||
System.out.println("Di che forma mostrare le trecce? ");
|
||||
System.out.println("1. Piccola");
|
||||
System.out.println("2. Media");
|
||||
System.out.println("3. Grande");
|
||||
System.out.print("Scelta: ");
|
||||
|
||||
try {
|
||||
scelta = sc.nextInt();
|
||||
sc.nextLine();
|
||||
|
||||
switch (scelta) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
for (Trecce treccia : trecce) {
|
||||
switch (scelta) {
|
||||
case 1:
|
||||
if (treccia instanceof Piccola) {
|
||||
System.out.println(treccia.toString());
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (treccia instanceof Media) {
|
||||
System.out.println(treccia.toString());
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (treccia instanceof Grande) {
|
||||
System.out.println(treccia.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void modificaPrezzoPercentuale(Trecce[] trecce) {
|
||||
boolean error;
|
||||
int scelta = -1;
|
||||
int tipoTreccia;
|
||||
boolean direzione = true;//true = aumenta
|
||||
//false = decrementa
|
||||
double percentuale;
|
||||
do {
|
||||
error = false;
|
||||
|
||||
System.out.println("Di che tipologia è la treccia? ");
|
||||
System.out.println("1. Piccola");
|
||||
System.out.println("2. Media");
|
||||
System.out.println("3. Grande");
|
||||
System.out.print("Scelta: ");
|
||||
|
||||
try {
|
||||
scelta = sc.nextInt();
|
||||
sc.nextLine();
|
||||
switch (scelta) {
|
||||
case 1:
|
||||
tipoTreccia = scelta;
|
||||
break;
|
||||
case 2:
|
||||
tipoTreccia = scelta;
|
||||
break;
|
||||
case 3:
|
||||
tipoTreccia = scelta;
|
||||
break;
|
||||
default:
|
||||
System.out.println("Scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
do {
|
||||
error = false;
|
||||
|
||||
System.out.println("Come modificare il prezzo? ");
|
||||
System.out.println("1. Aumento");
|
||||
System.out.println("2. Diminuzione");
|
||||
System.out.print("Scelta: ");
|
||||
|
||||
try {
|
||||
scelta = sc.nextInt();
|
||||
sc.nextLine();
|
||||
switch (scelta) {
|
||||
case 1:
|
||||
direzione = true;
|
||||
break;
|
||||
case 2:
|
||||
direzione = false;
|
||||
break;
|
||||
default:
|
||||
System.out.println("Scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
percentuale = percentuale();
|
||||
|
||||
for (Trecce treccia : trecce) {
|
||||
switch (scelta) {
|
||||
case 1:
|
||||
if (treccia instanceof Piccola) {
|
||||
treccia.aggiornaCosto(direzione, percentuale);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (treccia instanceof Media) {
|
||||
treccia.aggiornaCosto(direzione, percentuale);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (treccia instanceof Grande) {
|
||||
treccia.aggiornaCosto(direzione, percentuale);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static double percentuale() {
|
||||
boolean error;
|
||||
double ritorno = -1;
|
||||
do {
|
||||
try {
|
||||
error = false;
|
||||
System.out.print("Inserisci la percentuale: ");
|
||||
ritorno = sc.nextDouble();
|
||||
sc.nextLine();
|
||||
|
||||
if (ritorno <= 0) {
|
||||
System.out.println("Errore: la percentuale deve essere un numero maggiore di zero.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Percentuale non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
|
||||
} while (error);
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static void stampaTreccePerColore(Trecce[] trecce) {
|
||||
final String colore = "viola";
|
||||
|
||||
for (Trecce treccia : trecce) {
|
||||
if (treccia.getColore().equals(colore)) {
|
||||
System.out.println(treccia.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BoxTrecce creaBoxTrecce(Trecce[] trecce){
|
||||
int prima;
|
||||
int seconda;
|
||||
int terza;
|
||||
int quarta;
|
||||
String nome;
|
||||
BoxTrecce ritorno;
|
||||
Trecce trecceBox[] = new Trecce[4];
|
||||
|
||||
System.out.println("Inserire il nome del box: ");
|
||||
nome = sc.nextLine().trim();
|
||||
|
||||
System.out.println("Trecce disponibili: ");
|
||||
for (int i = 0; i < trecce.length; i++) {
|
||||
System.out.println("Treccia numero " + i + ":");
|
||||
System.out.println(trecce[i].toString());
|
||||
}
|
||||
|
||||
System.out.print("Scegliere la prima treccia: ");
|
||||
prima = numeroTreccia(trecce.length);
|
||||
|
||||
System.out.print("Scegliere la prima treccia: ");
|
||||
seconda = numeroTreccia(trecce.length);
|
||||
|
||||
System.out.print("Scegliere la prima treccia: ");
|
||||
terza = numeroTreccia(trecce.length);
|
||||
|
||||
System.out.print("Scegliere la prima treccia: ");
|
||||
quarta = numeroTreccia(trecce.length);
|
||||
|
||||
trecceBox[0] = trecce[prima];
|
||||
trecceBox[1] = trecce[seconda];
|
||||
trecceBox[2] = trecce[terza];
|
||||
trecceBox[3] = trecce[quarta];
|
||||
|
||||
ritorno = new BoxTrecce(nome, trecceBox);
|
||||
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static int numeroTreccia(int limite) {
|
||||
boolean error;
|
||||
int ritorno = -1;
|
||||
do {
|
||||
try {
|
||||
error = false;
|
||||
ritorno = sc.nextInt();
|
||||
sc.nextLine();
|
||||
|
||||
if (ritorno < 0 || ritorno >= limite) {
|
||||
System.out.println("Errore: la treccia deve essere compresa tra zero e " + limite + ".");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Scelta non valida.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
|
||||
} while (error);
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
// static void mostraBoxTrecce
|
||||
}
|
||||
39
src/b_bassanetti/BoxTrecce.java
Normal file
39
src/b_bassanetti/BoxTrecce.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package b_bassanetti;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author alunno
|
||||
*/
|
||||
public class BoxTrecce {
|
||||
String nomeBoxTrecce;
|
||||
Trecce proposta[] = new Trecce[4];
|
||||
|
||||
public BoxTrecce(String nomeBox, Trecce[] proposta){
|
||||
this.nomeBoxTrecce = nomeBox;
|
||||
this.proposta = proposta;
|
||||
}
|
||||
|
||||
public double CalcolaCosto(){
|
||||
double ritorno = 0;
|
||||
for(Trecce treccia: this.proposta){
|
||||
ritorno += treccia.getCosto();
|
||||
}
|
||||
|
||||
ritorno += (ritorno * 50) / 100;
|
||||
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
public String getNomeBoxTrecce() {
|
||||
return nomeBoxTrecce;
|
||||
}
|
||||
|
||||
public Trecce[] getProposta() {
|
||||
return proposta;
|
||||
}
|
||||
}
|
||||
28
src/b_bassanetti/Grande.java
Normal file
28
src/b_bassanetti/Grande.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package b_bassanetti;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author alunno
|
||||
*/
|
||||
public class Grande extends Trecce {
|
||||
String tipoPalline;
|
||||
String tipoNastro;
|
||||
|
||||
public Grande(int codice, String nome, String forma, String colore, double costo, String tipoPalline, String tipoNastro){
|
||||
super(codice, nome, forma, colore, costo);
|
||||
this.tipoPalline = tipoPalline;
|
||||
this.tipoNastro = tipoNastro;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return super.toString()
|
||||
+ "\nTipo palline: " + this.tipoPalline
|
||||
+ "\nTipo fiore: " + this.tipoNastro;
|
||||
}
|
||||
}
|
||||
28
src/b_bassanetti/Media.java
Normal file
28
src/b_bassanetti/Media.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package b_bassanetti;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author alunno
|
||||
*/
|
||||
public class Media extends Trecce {
|
||||
String tipoLegno;
|
||||
String tipoFiocco;
|
||||
|
||||
public Media(int codice, String nome, String forma, String colore, double costo, String tipoLegno, String tipoFiocco){
|
||||
super(codice, nome, forma, colore, costo);
|
||||
this.tipoLegno = tipoLegno;
|
||||
this.tipoFiocco = tipoFiocco;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return super.toString()
|
||||
+ "\nTipo legno: " + this.tipoLegno
|
||||
+ "\nTipo fiocco: " + this.tipoFiocco;
|
||||
}
|
||||
}
|
||||
28
src/b_bassanetti/Piccola.java
Normal file
28
src/b_bassanetti/Piccola.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package b_bassanetti;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author alunno
|
||||
*/
|
||||
public class Piccola extends Trecce {
|
||||
String tipoCera;
|
||||
String tipoFiore;
|
||||
|
||||
public Piccola(int codice, String nome, String forma, String colore, double costo, String tipoCera, String tipoFiore){
|
||||
super(codice, nome, forma, colore, costo);
|
||||
this.tipoCera = tipoCera;
|
||||
this.tipoFiore = tipoFiore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return super.toString()
|
||||
+ "\nTipo cera: " + this.tipoCera
|
||||
+ "\nTipo fiore: " + this.tipoFiore;
|
||||
}
|
||||
}
|
||||
52
src/b_bassanetti/Trecce.java
Normal file
52
src/b_bassanetti/Trecce.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package b_bassanetti;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author alunno
|
||||
*/
|
||||
public class Trecce {
|
||||
|
||||
int codice;
|
||||
String nome;
|
||||
String forma;
|
||||
String colore;
|
||||
double costo;
|
||||
|
||||
public Trecce(int codice, String nome, String forma, String colore, double costo) {
|
||||
this.codice = codice;
|
||||
this.nome = nome;
|
||||
this.forma = forma;
|
||||
this.colore = colore;
|
||||
this.costo = costo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "Codice: " + this.codice
|
||||
+ "\nNome: " + this.nome
|
||||
+ "\nForma: " + this.forma
|
||||
+ "\nColore: " + this.colore
|
||||
+ "\nCosto: " + this.costo ;
|
||||
}
|
||||
|
||||
public void aggiornaCosto(boolean direzione, double percentuale){ //true = aumenta
|
||||
//false = decrementa
|
||||
if(direzione){
|
||||
this.costo += (this.costo * percentuale) / 100;
|
||||
}else{
|
||||
this.costo -= (this.costo * percentuale) / 100;}
|
||||
}
|
||||
|
||||
public String getColore() {
|
||||
return colore;
|
||||
}
|
||||
|
||||
public double getCosto() {
|
||||
return costo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user