SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.io.*; | |
| 2 | import java.util.*; | |
| 3 | ||
| 4 | ||
| 5 | public class LetturaconTokenizer_BOZZA_ADATTAMENTO {
| |
| 6 | ||
| 7 | static String Luogo_Partenza; | |
| 8 | static String Luogo_Destinazione; | |
| 9 | static String Orario; | |
| 10 | ||
| 11 | ||
| 12 | public static void main (String[] args) {
| |
| 13 | try {
| |
| 14 | - | FileReader f = null; |
| 14 | + | |
| 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //Creazione Buffer per la lettura tramite ReadLine() | |
| 16 | - | f=new FileReader("prova.txt");
|
| 16 | + | FileReader f = null; |
| 17 | f=new FileReader("prova.txt");
| |
| 18 | - | BufferedReader b; |
| 18 | + | BufferedReader b; |
| 19 | - | b = new BufferedReader(f); |
| 19 | + | b = new BufferedReader(f); |
| 20 | int n = 0; | |
| 21 | - | int n=0; |
| 21 | + | int a = 0; |
| 22 | - | while (n==0) |
| 22 | + | |
| 23 | - | {
|
| 23 | + | while (n==0){
|
| 24 | - | System.out.println("Inserisci il Luogo da dove vuoi partire ");
|
| 24 | + | |
| 25 | - | System.out.println("1. Domodossola");
|
| 25 | + | System.out.println("Inserisci il Luogo da dove vuoi partire ");
|
| 26 | - | System.out.println("2. Novara");
|
| 26 | + | System.out.println("1. Domodossola");
|
| 27 | - | System.out.println("3. Verbania - Pallanz / Gravellona Toce");
|
| 27 | + | System.out.println("2. Novara");
|
| 28 | - | Luogo_Partenza=br.readLine(); //Assumo il valore con l'oggetto br (linea 21) e utilizzo il metodo readLine() |
| 28 | + | System.out.println("3. Verbania - Pallanz / Gravellona Toce");
|
| 29 | - | switch(Luogo_Partenza) {
|
| 29 | + | Luogo_Partenza=br.readLine(); //Assumo il valore con l'oggetto br (linea 21) e utilizzo il metodo readLine() |
| 30 | switch(Luogo_Partenza) {
| |
| 31 | - | |
| 31 | + | case "1": |
| 32 | - | case "1": |
| 32 | + | System.out.println("Inserisci Destinazione:");
|
| 33 | - | System.out.println("Inserisci Destinazione:");
|
| 33 | + | System.out.println("1. Novara");
|
| 34 | - | System.out.println("1. Novara");
|
| 34 | + | System.out.println("2. Verbania - Pallanz / Gravellona Toce");
|
| 35 | - | System.out.println("2. Verbania - Pallanz / Gravellona Toce");
|
| 35 | + | Luogo_Destinazione=br.readLine(); |
| 36 | - | Luogo_Destinazione=br.readLine(); |
| 36 | + | n++; |
| 37 | - | n++; |
| 37 | + | break; //si ferma qui |
| 38 | - | break; //si ferma qui |
| 38 | + | |
| 39 | case "2": | |
| 40 | - | case "2": |
| 40 | + | System.out.println("Inserisci Destinazione:");
|
| 41 | - | System.out.println("Inserisci Destinazione:");
|
| 41 | + | System.out.println("1. Domodossola");
|
| 42 | - | System.out.println("1. Domodossola");
|
| 42 | + | System.out.println("2. Verbania - Pallanz / Gravellona Toce");
|
| 43 | - | System.out.println("2. Verbania - Pallanz / Gravellona Toce");
|
| 43 | + | Luogo_Destinazione=br.readLine(); |
| 44 | - | Luogo_Destinazione=br.readLine(); |
| 44 | + | n++; |
| 45 | - | n++; |
| 45 | + | break; //si ferma qui |
| 46 | - | break; //si ferma qui |
| 46 | + | |
| 47 | case "3": | |
| 48 | - | case "3": |
| 48 | + | System.out.println("Inserisci Destinazione:");
|
| 49 | - | System.out.println("Inserisci Destinazione:");
|
| 49 | + | System.out.println("1. Domodossola");
|
| 50 | - | System.out.println("1. Domodossola");
|
| 50 | + | System.out.println("2. Novara");
|
| 51 | - | System.out.println("2. Novara");
|
| 51 | + | Luogo_Destinazione=br.readLine(); |
| 52 | - | Luogo_Destinazione=br.readLine(); |
| 52 | + | n++; |
| 53 | - | n++; |
| 53 | + | break; |
| 54 | - | break; |
| 54 | + | |
| 55 | default: | |
| 56 | - | default: |
| 56 | + | System.out.println("ERRORE: INSERISCI UN VALORE");
|
| 57 | - | System.out.println("ERRORE: INSERISCI UN VALORE");
|
| 57 | + | |
| 58 | } | |
| 59 | - | } |
| 59 | + | |
| 60 | ||
| 61 | - | } |
| 61 | + | while(a<=0){
|
| 62 | ||
| 63 | - | String lettura; |
| 63 | + | int Ora; |
| 64 | String ora; | |
| 65 | - | while ((lettura = b.readLine()) != null) |
| 65 | + | String minuti; |
| 66 | - | {
|
| 66 | + | int Minuti; |
| 67 | do{
| |
| 68 | ||
| 69 | - | while (st.hasMoreTokens()) |
| 69 | + | System.out.println("Inserisci un orario da cui vuoi partire[ORA]");
|
| 70 | - | {
|
| 70 | + | ora=br.readLine(); |
| 71 | Ora = Integer.parseInt(ora); | |
| 72 | - | String A = st.nextElement().toString(); |
| 72 | + | |
| 73 | - | String B = st.nextElement().toString(); |
| 73 | + | if (Ora>24){
|
| 74 | - | String C = st.nextElement().toString(); |
| 74 | + | |
| 75 | - | String D = st.nextElement().toString(); |
| 75 | + | System.out.println("Inserisci un valore corretto [da 00 a 24pm]");
|
| 76 | } | |
| 77 | - | boolean DomodossolaA = A.equalsIgnoreCase("Domodossola");
|
| 77 | + | }while (Ora>24); |
| 78 | - | boolean DomodossolaB = B.equalsIgnoreCase("Domodossola");
|
| 78 | + | |
| 79 | - | boolean VerbaniaA = A.equalsIgnoreCase("Verbania");
|
| 79 | + | do |
| 80 | - | boolean VerbaniaB = B.equalsIgnoreCase("Verbania");
|
| 80 | + | {
|
| 81 | - | boolean NovaraA = A.equalsIgnoreCase("Novara");
|
| 81 | + | System.out.println("Inserisci un orario da cui vuoi partire[MINUTO]");
|
| 82 | - | boolean NovaraB = B.equalsIgnoreCase("Novara");
|
| 82 | + | minuti=br.readLine(); |
| 83 | - | System.out.println(A+B+C+D); |
| 83 | + | Minuti = Integer.parseInt(minuti); |
| 84 | if (Minuti>60) | |
| 85 | {
| |
| 86 | - | if ((Luogo_Partenza=="1") && (Luogo_Destinazione=="1") && (DomodossolaA==true) && (NovaraB==true)) |
| 86 | + | System.out.println("Inserisci un valore corretto [da 00 a 60]");
|
| 87 | - | {
|
| 87 | + | } |
| 88 | ||
| 89 | }while (Minuti>60); | |
| 90 | ||
| 91 | - | } |
| 91 | + | System.out.println("L'orario inserito è "+Ora+":"+Minuti);
|
| 92 | - | else if (((Luogo_Partenza=="1") && (Luogo_Destinazione=="2") && DomodossolaA==true) && (VerbaniaB==true)) |
| 92 | + | a++; |
| 93 | - | {
|
| 93 | + | } //Fine While (a<=0) |
| 94 | ||
| 95 | - | } |
| 95 | + | |
| 96 | - | else if ((Luogo_Partenza=="2") && (Luogo_Destinazione=="1") && (NovaraA==true) && (DomodossolaB==true)) |
| 96 | + | |
| 97 | - | {
|
| 97 | + | String lettura; |
| 98 | ||
| 99 | - | } |
| 99 | + | while ((lettura = b.readLine()) != null){
|
| 100 | - | else if ((Luogo_Partenza=="2") && (Luogo_Destinazione=="2") && (NovaraA==true) && (VerbaniaB==true)) |
| 100 | + | |
| 101 | - | {
|
| 101 | + | |
| 102 | ||
| 103 | - | } |
| 103 | + | while (st.hasMoreTokens()){
|
| 104 | - | else if ((Luogo_Partenza=="3") && (Luogo_Destinazione=="1") && (VerbaniaA==true) && (DomodossolaB==true)) |
| 104 | + | |
| 105 | - | {
|
| 105 | + | String A = st.nextElement().toString(); |
| 106 | String B = st.nextElement().toString(); | |
| 107 | - | } |
| 107 | + | String C = st.nextElement().toString(); |
| 108 | - | else if ((Luogo_Partenza=="3") && (Luogo_Destinazione=="2") && (VerbaniaA==true) && (NovaraB==true)) |
| 108 | + | String D = st.nextElement().toString(); |
| 109 | - | {
|
| 109 | + | |
| 110 | boolean DomodossolaA = A.equalsIgnoreCase("Domodossola");
| |
| 111 | - | } |
| 111 | + | boolean DomodossolaB = B.equalsIgnoreCase("Domodossola");
|
| 112 | - | else |
| 112 | + | boolean VerbaniaA = A.equalsIgnoreCase("Verbania");
|
| 113 | - | {System.out.println("MALE");
|
| 113 | + | boolean VerbaniaB = B.equalsIgnoreCase("Verbania");
|
| 114 | - | } |
| 114 | + | boolean NovaraA = A.equalsIgnoreCase("Novara");
|
| 115 | - | } |
| 115 | + | boolean NovaraB = B.equalsIgnoreCase("Novara");
|
| 116 | ||
| 117 | ||
| 118 | //System.out.println(Luogo_Partenza+Luogo_Destinazione+DomodossolaA+NovaraB); | |
| 119 | ||
| 120 | ||
| 121 | - | } catch(Exception e) { //???
|
| 121 | + | if ((Luogo_Partenza=="1") && (Luogo_Destinazione=="1") && (DomodossolaA==true) && (NovaraB==true)){
|
| 122 | ||
| 123 | System.out.println(A+" "+B+" "+C+" "+D); | |
| 124 | } | |
| 125 | ||
| 126 | else if ((Luogo_Partenza=="1") && (Luogo_Destinazione=="2") && (DomodossolaA==true) && (VerbaniaB==true)){
| |
| 127 | ||
| 128 | System.out.println(A+B+C+D); | |
| 129 | } | |
| 130 | else if ((Luogo_Partenza=="2") && (Luogo_Destinazione=="1") && (NovaraA==true) && (DomodossolaB==true)){
| |
| 131 | ||
| 132 | System.out.println(A+B+C+D); | |
| 133 | } | |
| 134 | else if ((Luogo_Partenza=="2") && (Luogo_Destinazione=="2") && (NovaraA==true) && (VerbaniaB==true)){
| |
| 135 | ||
| 136 | System.out.println(A+B+C+D); | |
| 137 | } | |
| 138 | else if ((Luogo_Partenza=="3") && (Luogo_Destinazione=="1") && (VerbaniaA==true) && (DomodossolaB==true)){
| |
| 139 | ||
| 140 | System.out.println(A+B+C+D); | |
| 141 | } | |
| 142 | else if ((Luogo_Partenza=="3") && (Luogo_Destinazione=="2") && (VerbaniaA==true) && (NovaraB==true)){
| |
| 143 | ||
| 144 | System.out.println(A+B+C+D); | |
| 145 | } | |
| 146 | } | |
| 147 | } | |
| 148 | ||
| 149 | ||
| 150 | b.close(); | |
| 151 | } | |
| 152 | } catch(Exception e) { //???
| |
| 153 | e.printStackTrace(); //??? | |
| 154 | } | |
| 155 | } | |
| 156 | } |