-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMODEL.java
144 lines (136 loc) · 3.85 KB
/
MODEL.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
/*Define a class Person with the following members
Data Members
Name of the person, age of the person and gender of the person
Member functions
read() - to read values to the data members
disp() - To display values of the data members
One default constructor and one overloaded constructor for Person class
Define a class Worker which inherits from Person class with the following
specification
Data members of Worker class
No.of hours worked per day and wage per hour
Member functions of Worker class
read() - to read values to the data members
calcwg() - to calculate the wage of a worker and return the value
extraWage() - if the twage of the worker is less than Rs. 200, then an extra
amount of Rs. 150 will be paid to the worker. Otherwise Rs. 50
will be paid.
TotalWage() - To find the total wage of the worker.
One default constructor and one overloaded constructor for worker class.
Overloaded constructor has to pass parameters to the parent class constructor.
display() - to display the values of the data members and the total wage
as shown below.
Output format
Name of the worker :
Age of the worker
No. Of Hours worked :
Wage per Hour :
Wage of the worker :
Extra wage :
Total Wage*/
import java.io.*;
class PERSON
{
//Variabel Declaration
private String pName;
private short pAge;
private char pGender;
//Constuctors
PERSON()
{
pName = " ";
pAge = 0;
pGender = 'U';
}
PERSON(String name,short age,char gender)
{
pName =name;
pAge = age;
pGender = gender;
}
//Public Functions
public void read() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Worker's Name:\t");
pName = br.readLine();
System.out.print("Enter Worker's Age:\t");
pAge = Short.parseShort(br.readLine());
System.out.print("Enter Worker's Gender:\t");
pGender = (char)br.read();
}
public void disp()
{
System.out.println("Worker's Name:\t\t\t"+pName);
System.out.println("Worker's Age:\t\t\t"+pAge);
System.out.println("Worker's Gender:\t\t"+pGender);
}
}
class WORKER extends PERSON
{
//Variable Declaration
//Hours Worked Per Day
private byte wHWPD;
//Wage Per Hour
private int wWPH;
//Constructors
WORKER()
{
wHWPD = 0;
wWPH = 0;
}
WORKER(byte wHWPD,int wWPH,String pName,short pAge,char pGender)
{
super(pName,pAge,pGender);
this.wHWPD = wHWPD;
this.wWPH = wWPH;
}
//Funtions
public void read() throws IOException
{
super.read();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the No. of Hours worker worked:\t");
wHWPD = Byte.parseByte(br.readLine());
System.out.print("Enter Wage to be givem per Hour:\t");
wWPH = Integer.parseInt(br.readLine());
}
public int calWage()
{
return wHWPD*wWPH;
}
public int extraWage()
{
if(calWage()<200)
{
return 150;
}
else
{
return 50;
}
}
public int totalWage()
{
return calWage()+extraWage();
}
public void display()
{
disp();
System.out.println("No. of Hours Worked :\t\t"+wHWPD);
System.out.println("Wage per Hour :\t\t\t"+wWPH);
System.out.println("Wage of the worker :\t\t"+calWage());
System.out.println("Extra Wage :\t\t\t"+extraWage());
System.out.println("Total Wage :\t\t\t"+totalWage());
}
}
class MODEL
{
public static void main(String args[]) throws IOException
{
// WORKER obj = new WORKER();
WORKER obj1 = new WORKER((byte)8,50,"Akshat",(short)19,(char)'M');
// obj.read();
obj1.display();
}
}