Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** JTUNE MAIN **/
- import MyTools.*;
- public class JTunes {
- public static void benvenuto(){
- MyTools.printerF("Benvenuto in JTunes. \nQuesto programma gestirà tutto il tuo archivio di CD.");
- }
- public static void main(String [] arg){
- benvenuto();
- Archivio archivio = new Archivio();
- String [] voci = {"1- Inserire nuovo CD", "2- Visualizza CD", "3- Eliminna CD", "4- Brano a Caso"};
- boolean bool = true;
- MyMenu menu = new MyMenu("Menu Principale", voci);
- int risp;
- while(bool){
- risp = menu.scegli();
- switch (risp){
- case 0:
- bool = false;
- break;
- case 1:
- archivio.inserisciNuovoCD();
- break;
- case 2:
- archivio.visualizza();
- break;
- case 3:
- archivio.rimuovi();
- break;
- }
- }
- }
- }
- /** MyMenu **/
- package MyTools;
- /*
- Questa classe rappresenta un menu testuale generico a piu' voci
- Si suppone che la voce per uscire sia sempre associata alla scelta 0
- e sia presentata in fondo al menu
- */
- public class MyMenu
- {
- final private static String CORNICE = "--------------------------------";
- final private static String VOCE_USCITA = "0\tEsci";
- final private static String RICHIESTA_INSERIMENTO = "Digita il numero dell'opzione desiderata > ";
- private String titolo;
- private String [] voci;
- public MyMenu (String titolo, String [] voci)
- {
- this.titolo = titolo;
- this.voci = voci;
- }
- public int scegli ()
- {
- stampaMenu();
- return MyTools.getIntegerMM(RICHIESTA_INSERIMENTO, 0, voci.length);
- }
- public void stampaMenu ()
- {
- System.out.println(CORNICE);
- System.out.println(titolo);
- System.out.println(CORNICE);
- for (int i=0; i<voci.length; i++)
- {
- System.out.println( (i+1) + "\t" + voci[i]);
- }
- System.out.println();
- System.out.println(VOCE_USCITA);
- System.out.println();
- }
- }
- /** MyTools **/
- package MyTools;
- import java.util.*;
- public class MyTools {
- public static void printerF(String msg){
- System.out.println(msg);
- }
- public static int getInteger(String msg){
- printerF(msg);
- Scanner reader = new Scanner(System.in);
- int result = reader.nextInt();
- return result;
- }
- public static double getDouble(String msg){
- printerF(msg);
- Scanner reader = new Scanner(System.in);
- double result = reader.nextDouble();
- return result;
- }
- public static String getString(String msg){
- printerF(msg);
- Scanner reader = new Scanner(System.in);
- String result = reader.nextLine();
- return result;
- }
- public static char getChar(String msg){
- printerF(msg);
- Scanner reader = new Scanner(System.in);
- char result = reader.nextLine().charAt(0);
- return result;
- }
- public static int getRandom(){
- Random rand = new Random();
- int num = rand.nextInt();
- return num;
- }
- public static int getRandom(int range){
- Random rand = new Random();
- int num = rand.nextInt(range) +1;
- return num;
- }
- public static boolean confirm(String msg){
- printerF(msg);
- Scanner reader = new Scanner(System.in);
- String answ = reader.nextLine().toUpperCase();
- return(answ.equalsIgnoreCase("SI") || answ.charAt(0) == 'S');
- }
- public static int readMinInteger(String messaggio, int minimo)
- {
- boolean finito = false;
- int valoreLetto = 0;
- do
- {
- valoreLetto = getInteger(messaggio);
- if (valoreLetto >= minimo)
- finito = true;
- else
- System.out.println("Il valore deve essere maggiore di " + minimo);
- } while (!finito);
- return valoreLetto;
- }
- public static int getIntegerMM(String msg, int min, int max){
- boolean done = false;
- int readValue = 0;
- do {
- readValue = getInteger(msg);
- if(readValue >= min && readValue <= max){
- done = true;
- } else if(readValue < min){
- printerF("Il valore è minore del minimo");
- } else {
- printerF("Il valore è maggiore del massimo");
- }
- } while(done);
- return readValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement