-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMethod.java
165 lines (150 loc) · 4.28 KB
/
Method.java
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*import java.util.Scanner;
class Method{ //Important reminder: The functions can be placed at first or last. */
//FIRST
/*
static int inputNum(){
Scanner num=new Scanner(System.in);
return (num.nextInt());
}
static void printAsk(int num){
switch(num){
case 0:System.out.println("Input the first number: ");break;
case 1:System.out.println("Input the second number: ");break;
}
}
static int calculation(int a,int b){
return (a+b);
}
static void displaySum(int a,int b,int sum){
System.out.println("The sum of "+a+" and "+b+" is "+sum+".");
}
public static void main(String args[]){
int a,b,sum;
printAsk(0);
a=inputNum();
printAsk(1);
b=inputNum();
sum=calculation(a,b);
displaySum(a,b,sum);
}
} */
//LAST
/*
public static void main(String args[]){
int a,b,sum;
printAsk(0);
a=inputNum();
printAsk(1);
b=inputNum();
sum=calculation(a,b);
displaySum(a,b,sum);
}
static int inputNum(){
Scanner num=new Scanner(System.in);
return (num.nextInt());
}
static void printAsk(int num){
switch(num){
case 0:System.out.println("Input the first number: ");break;
case 1:System.out.println("Input the second number: ");break;
}
}
static int calculation(int a,int b){
return (a+b);
}
static void displaySum(int a,int b,int sum){
System.out.println("The sum of "+a+" and "+b+" is "+sum+".");
}
} */
import java.util.*;
public class Method{
private String studentName;
private long studentIDnumber;
private String schoolName;
Method(){
this.setSchoolName("University of Cebu");
}
Method(String schoolName){
this.setSchoolName(schoolName);
}
public String getSchoolName(){
return schoolName;
}
public void setSchoolName(String schoolName){
this.schoolName=schoolName;
}
public static void main(String args[]){
Method student1=new Method();
Method student2=new Method("University of San Carlos");
Method student3=new Method("University of San Jose Recoletos");
askstudentName(1);
student1.studentName=enterstudentName();
askstudentIDnumber(1);
student1.studentIDnumber=enterstudentIDnumber(1);
if(student1.studentIDnumber>999999){
while(student1.studentIDnumber>999999){
System.out.println("Error! Try Again!");
askstudentIDnumber(1);
student1.studentIDnumber=enterstudentIDnumber(1);
}
}
System.out.print("\n");
askstudentName(2);
student2.studentName=enterstudentName();
askstudentIDnumber(2);
student2.studentIDnumber=enterstudentIDnumber(2);
if(student2.studentIDnumber>999999){
while(student2.studentIDnumber>999999){
System.out.println("Error! Try Again!");
askstudentIDnumber(2);
student2.studentIDnumber=enterstudentIDnumber(2);
}
}
System.out.print("\n");
askstudentName(3);
student3.studentName=enterstudentName();
askstudentIDnumber(3);
student3.studentIDnumber=enterstudentIDnumber(3);
if(student3.studentIDnumber>999999){
while(student3.studentIDnumber>999999){
System.out.println("Error! Try Again!");
askstudentIDnumber(3);
student3.studentIDnumber=enterstudentIDnumber(3);
}
}
printstudentProfile(1,student1.studentName,student1.studentIDnumber,student1.getSchoolName());
printstudentProfile(2,student2.studentName,student2.studentIDnumber,student2.getSchoolName());
printstudentProfile(3,student3.studentName,student3.studentIDnumber,student3.getSchoolName());
}
static void askstudentName(int num){
switch(num){
case 1:System.out.println("Enter the Student 1 name: ");break;
case 2:System.out.println("Enter the Student 2 name: ");break;
case 3:System.out.println("Enter the Student 3 name: ");break;
}
}
static String enterstudentName(){
Scanner studentName=new Scanner(System.in);
return (studentName.nextLine());
}
static void askstudentIDnumber(int num){
switch(num){
case 1:System.out.println("Enter the Student 1 ID number (6-digit): ");break;
case 2:System.out.println("Enter the Student 2 ID number (6-digit): ");break;
case 3:System.out.println("Enter the Student 3 ID number (6-digit): ");break;
}
}
static long enterstudentIDnumber(int num){
Scanner studentIDnumber=new Scanner(System.in);
return (studentIDnumber.nextLong());
}
static void printstudentProfile(int num,String studentName,long studentIDnumber,String schoolName){
System.out.println("\n\tSTUDENT "+num+" PROFILE");
System.out.println("Student Name: "+studentName);
System.out.println("ID Number: "+studentIDnumber);
if(schoolName=="University of Cebu")
System.out.println("School Name: "+schoolName+" (our student)");
else
System.out.println("School Name: "+schoolName+" (not our student)");
}
}