-
Notifications
You must be signed in to change notification settings - Fork 0
/
CitizenTest.java
54 lines (47 loc) · 1.33 KB
/
CitizenTest.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
class Citizen {
// Properties of the class...
private String name;
private int salary;
private int savings;
private int loan;
// Constructor of the class...
public Citizen(String aName, int aSalary, int aSavings, int aLoan) {
name = aName;
salary = aSalary;
savings = aSavings;
loan = aLoan;
}
public Citizen(String aName) {
name = aName;
salary = 0;
savings = 0;
loan = 0;
}
// Methods of the class...
public int getSalary() {
return salary;
}
public void setSalary(int aSalary) {
salary = aSalary;
}
public void salaryRise(int amount) {
salary = salary + amount;
}
public int netWorth() {
return savings - loan;
}
public String toString() {
return " Name: " + name + " Salary: " + salary + " Savings: " + savings + " Loan: " + loan;
}
}
class CitizenTest {
// The main method is the point of entry into the program...
public static void main(String[] args) {
Citizen e = new Citizen("Ernie", 50000, 2000, 0);
Citizen b = new Citizen("Bert", 100000,10000,5000);
Citizen f = new Citizen("Fred");
e.salaryRise(10000);
System.out.println("Ernie's salary is: " + e.getSalary());
System.out.println("Ernie's net worth is: " + e.netWorth());
}
}