forked from Gomavijayan/Java_Accenture_LearningModules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollege Fee – Abstract Class.java
More file actions
200 lines (187 loc) · 4.8 KB
/
College Fee – Abstract Class.java
File metadata and controls
200 lines (187 loc) · 4.8 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
public class DayScholar extends Student{
private int busNumber;
private float distance;
public DayScholar(int studentId, String studentName, String department,
String gender, String category, double collegeFee, int busNumber, float distance){
super(studentId,studentName,department,gender,category,collegeFee);
this.busNumber=busNumber;
this.distance=distance;
}
public int getBusNumber(){
return busNumber;
}
public void setBusNumber(int busNumber){
this.busNumber=busNumber;
}
public float getDistance(){
return distance;
}
public void setDistance(float distance){
this.distance=distance;
}
public double calculateTotalFee() {
int busFee=0;
if(distance>30 && distance <=40){
busFee=28000;
}
else if (distance>20 && distance<=30){
busFee=20000;
}
else if(distance >10 && distance <= 20){
busFee=12000;
}
else{
busFee=6000;
}
return (collegeFee+busFee);
}
}
//===============================================//
public abstract class Student {
protected int studentId;
protected String studentName;
protected String department;
protected String gender;
protected String category;
protected double collegeFee;
public Student(int studentId, String studentName, String department, String
gender, String category, double collegeFee){
this.studentId=studentId;
this.studentName=studentName;
this.department=department;
this.gender=gender;
this.category=category;
this.collegeFee=collegeFee;
}
public int getStudentId(){
return studentId;
}
public void setStudentId(int studentId){
this.studentId=studentId;
}
public String getStudentName(){
return studentName;
}
public void setStudentName(String studentName){
this.studentName=studentName;
}
public String getDepartment(){
return department;
}
public void setDepartment(String department){
this.department=department;
}
public String getGender(){
return gender;
}
public void setGender(String gender){
this.gender=gender;
}
public String getCategory(){
return category;
}
public void setCategory(String category){
this.category=category;
}
public double getCollegeFee(){
return collegeFee;
}
public abstract double calculateTotalFee();
}
//===========================================//
import java.util.Scanner;
public class UserInterface {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Student Id");
int studentId= Integer.parseInt(sc.nextLine());
System.out.println("Enter Student name");
String name=sc.nextLine();
System.out.println("Enter Department name");
String deptName=sc.nextLine();
System.out.println("Enter gender");
String gender=sc.nextLine();
System.out.println("Enter category");
String category=sc.nextLine();
System.out.println("Enter College fee");
double collegeFee=Double.parseDouble(sc.nextLine());
if(category.equals("DayScholar")){
System.out.println("Enter Bus number");
int busNumber=Integer.parseInt(sc.nextLine());
System.out.println("Enter the distance");
int distance=Integer.parseInt(sc.nextLine());
DayScholar dayScholar=new DayScholar(studentId, name, deptName, gender,
category, collegeFee, busNumber, distance);
System.out.println("Total College fee is
"+dayScholar.calculateTotalFee());
}
else{
System.out.println("Enter the room number");
int roomNumber=Integer.parseInt(sc.nextLine());
System.out.println("Enter the Block name");
char blockName=sc.nextLine().charAt(0);
System.out.println("Enter the room type");
String roomType=sc.nextLine();
Hosteller hosteller=new
Hosteller(studentId,name,deptName,gender,category,collegeFee,roomNumber,blockName,r
oomType);
System.out.println("Total College fee is
"+hosteller.calculateTotalFee());
}
}
}
//======================================//
public class Hosteller extends Student{
private int roomNumber;
private char blockName;
private String roomType;
public Hosteller(int studenId,String studentName, String department, String
gender, String category, double collegeFee, int roomNumber, char blockName, String
roomType){
super(studenId,studentName,department,gender,category,collegeFee);
this.roomNumber=roomNumber;
this.blockName=blockName;
this.roomType=roomType;
}
public int getRoomNumber(){
return roomNumber;
}
public void setRoomNumber(int roomNumber){
this.roomNumber=roomNumber;
}
public char getBlockName(){
return blockName;
}
public void setBlockName(char blockName){
this.blockName=blockName;
}
public String getRoomType(){
return roomType;
}
public void setRoomType(String roomType){
this.roomType=roomType;
}
public double calculateTotalFee(){
int roomFee=0;
int hostelFee=0;
if(blockName=='A'){
hostelFee=60000;
if(roomType.equals("AC")){
roomFee=8000;
}
}
else if (blockName=='B'){
hostelFee=50000;
if(roomType.equals("AC")){
roomFee=5000;
}
}
else if (blockName=='C'){
hostelFee=40000;
if(roomType.equals("AC")){
roomFee=2500;
}
}
return collegeFee+hostelFee+roomFee;
}
}