-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentTest.java
More file actions
67 lines (66 loc) · 1.43 KB
/
StudentTest.java
File metadata and controls
67 lines (66 loc) · 1.43 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
//Answer to 1A
class Student
{
private String name;
private String major;
private double gpa;
public Student()
{
this.name = "";
this.major = "";
this.gpa = 0.0;
}
public Student(String name, String major)
{
this.name = name;
this.major = major;
}
public Student(String name, String major, double gpa)
{
this.name = name;
this.major = major;
this.gpa = gpa;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getMajor()
{
return major;
}
public void setMajor(String major)
{
this.major = major;
}
public double getGpa()
{
return gpa;
}
public void setGpa(double gpa)
{
this.gpa = gpa;
}
public String toString()
{
return "The name is " + name + ", the major is " + major + ", and the GPA is " + gpa;
}
}
//Answer for 1B driver class
class StudentTest
{
public static void main(String[] args)
{
Student firstStudent = new Student("John", "CS", 3.5);
Student secondStudent = new Student();
secondStudent.setName("Mary Ann");
secondStudent.setMajor("CE");
secondStudent.setGpa(3.3);
System.out.println(firstStudent.toString());
System.out.println(secondStudent.toString());
}
}