-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment2.java
More file actions
80 lines (80 loc) · 1.49 KB
/
assignment2.java
File metadata and controls
80 lines (80 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
76
77
78
79
80
import java.util.*;
class Employee
{
String fname, lname;
long salary;
Employee()
{
fname = null;
lname = null;
salary = 0;
}
Employee(String fnm, String lnm, long rp)
{
this.fname = fnm;
this.lname = lnm;
this.salary = rp;
}
public void setDetails()
{
Scanner input = new Scanner(System.in);
System.out.printf("\nEnter first name: ");
fname = input.next();
System.out.printf("\nEter last name: ");
lname = input.next();
System.out.printf("\nEnter Salary: ");
salary = input.nextLong();
}
public void setFirstname(String nm)
{
this.fname = nm;
}
public void setLastname(String nm)
{
this.lname = nm;
}
public void setSalary(long sl)
{
this.salary = sl;
}
public String getFirstName()
{
return fname;
}
public String getLastName()
{
return lname;
}
public long getSalary()
{
return salary;
}
public void display()
{
System.out.println("\nName: "+fname + " " + lname);
System.out.println("Salary: "+ salary);
}
public void incr15per()
{
long l = this.salary;
double s = (double)l*0.15;
this.salary = l+ (long)s;
}
}
class EmployeeTest
{
public static void main(String a[])
{
System.out.println("\nUsing parameterized Constructor");
Employee e1 = new Employee("Aman","Gupta",40000);
e1.display();
System.out.println("\nUsing default constructor and
taking inputs");
Employee e2 = new Employee();
e2.setDetails();
e2.display();
System.out.println("\nIncreasing "+e2.getFirstName()+"'s salary by 15% ");
e2.incr15per();
e2.display();
}
}