This repository was archived by the owner on Apr 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOldPhone.java
More file actions
124 lines (114 loc) · 2.48 KB
/
OldPhone.java
File metadata and controls
124 lines (114 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
// I have already discovered the issue I had with my program
public class OldPhone {
public static void main(String args[]) {
Scanner file = null;
try {
file = new Scanner(new FileInputStream("OldPhone.txt"));
} catch (FileNotFoundException ERROR) {
System.out.println("ERROR, file not found");
System.exit(0);
}
int loop = file.nextInt();
file.nextline(); // T remove whtespace
for (int i = 0; i < loop; i++) {
String toConvert = file.nextLine();
for (int j = 0; j < toConvert.length(); j++) {
char letter = toConvert.charAt(j);
switch (letter) {
case 'a':
System.out.print("2");
break;
case 'b':
System.out.print("22");
break;
case 'c':
System.out.print("222");
break;
case 'd':
System.out.print("3");
break;
case 'e':
System.out.print("33");
break;
case 'f':
System.out.print("333");
break;
case 'g':
System.out.print("4");
break;
case 'h':
System.out.print("44");
break;
case 'i':
System.out.print("444");
break;
case 'j':
System.out.print("5");
break;
case 'k':
System.out.print("55");
break;
case 'l':
System.out.print("555");
break;
case 'm':
System.out.print("6");
break;
case 'n':
System.out.print("66");
break;
case 'o':
System.out.print("666");
break;
case 'p':
System.out.print("7");
break;
case 'q':
System.out.print("77");
break;
case 'r':
System.out.print("777");
break;
case 's':
System.out.print("7777");
break;
case 't':
System.out.print("8");
break;
case 'u':
System.out.print("88");
break;
case 'v':
System.out.print("888");
break;
case 'w':
System.out.print("9");
break;
case 'x':
System.out.print("99");
break;
case 'y':
System.out.print("999");
break;
case 'z':
System.out.print("9999");
break;
default:
System.out.print("0");
break;
}
}
/*
String waste = null; // Weird behaviour?
if (file.hasNextLine()) {
waste = file.nextLine();
}
System.out.println(waste); // To check what is compiled
Didn't really need any of this
*/
}
}
}