-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMidterm.java
More file actions
75 lines (55 loc) · 1.49 KB
/
Midterm.java
File metadata and controls
75 lines (55 loc) · 1.49 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
/*
Abraham Estrada
*/
import java.util.Scanner;
public class Midterm {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
//user inputs their number
System.out.print("Enter a student id number: ");
String studId = s.nextLine();
// uses the index of the dashes and slash to get the numbers in between.
int dashOne= studId.indexOf("-");
int dashTwo= studId.lastIndexOf("-");
int slash = studId.indexOf("/");
//Order of how the numbers are pulled out of the big string,
String num1 = studId.substring(0,dashOne);
String num2= studId.substring(dashOne+1,dashTwo);
String num3 = studId.substring(dashTwo+1,slash );
String num4 = studId.substring(slash+1);
int first = Integer.parseInt(num1);
int second = Integer.parseInt(num2);
int third = Integer.parseInt(num3);
int fourth = Integer.parseInt(num4);
int addedNums = first+third;
int remainder = first / third;
// if(studId.contains("-")){
// if(studId.contains("-")){
// if(studId.contains("/")) {
//
// }
// }
// }
// else{
// System.out.print("The Id is not valid.");
// System.exit(0);
// }
//
if(second == addedNums){
System.out.print("The Id is Valid.");
System.exit(0);
}
else{
System.out.print("The Id is not valid.");
System.exit(0);
}
if (fourth == remainder){
System.out.print("The Id is Valid.");
System.exit(0);
}
else{
System.out.print("The Id is not valid.");
System.exit(0);
}
}
}