-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathresidence.java
More file actions
114 lines (105 loc) · 3.21 KB
/
residence.java
File metadata and controls
114 lines (105 loc) · 3.21 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
import java.util.Scanner;
public class residence {
String resi_name;
String block;
int flat_no;
int due_amount;
String mobile;
public static void menu(){
System.out.println("Options Menu");
System.out.println("---------------");
System.out.println("1. Know the due amount");
System.out.println("2. Pay the maintenance");
System.out.println("3. Add new resident details");
System.out.println("4. Delete the existing residence");
System.out.println("0 to exit");
System.out.println("----------------------");
}
public void get()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter residence name : ");
resi_name = sc.nextLine();
System.out.println("Enter block : ");
block = sc.nextLine();
System.out.println("Enter flat number : ");
flat_no = sc.nextInt();
System.out.println("Enter due amount : ");
due_amount = sc.nextInt();
System.out.println("Enter mobile number : ");
mobile = sc.next();
}
public void print()
{
System.out.println("Residence name : " + resi_name);
System.out.println("Block : " + block);
System.out.println("Flat Number : " + flat_no);
System.out.println("Due amount : " + due_amount);
}
public void pay()
{
Scanner sc= new Scanner(System.in);
if (due_amount == 0)
{
System.out.println("The due amount is paid");
}
else if (due_amount > 0)
{
int amt;
System.out.println("Enter amount : ");
amt = sc.nextInt();
due_amount -= amt;
if (due_amount == 0)
{
System.out.println("The due amount is paid");
}
if (due_amount < 0)
{
System.out.println("Your due is paid , the extra amount is " + -(due_amount));
}
}
}
public static void main(String args[])
{
int flag = 400;
Scanner sc = new Scanner(System.in);
residence cus[] = new residence[30];
System.out.println("Enter number of residents :");
int N = sc.nextInt();
for (int i = 0; i < N; i++) {
cus[i] = new residence();
System.out.println("Enter details \n --------------\n");
cus[i].get();
}
menu();
while (flag != 0)
{
int res,b;
System.out.println("Enter Option : ");
flag = sc.nextInt();
if (flag == 0){
break;
}
System.out.println("Enter flat number : ");
b = sc.nextInt();
if (flag == 1){
for (int i = 0 ; i < N ; i++)
{
if (cus[i].flat_no == b)
{
cus[i].print();
}
}
}
if (flag == 2){
for (int i = 0 ; i < N ; i++)
{
if (cus[i].flat_no == b)
{
cus[i].pay();
}
}
}
}
}
}