-
Notifications
You must be signed in to change notification settings - Fork 0
/
KhachHang.java
172 lines (163 loc) · 4.13 KB
/
KhachHang.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
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
package fastfoodanddrinkstore;
import java.util.*;
import java.io.*;
public class KhachHang{
Scanner in = new Scanner(System.in);
private String maKh;
private String tenKh;
private String hoKh;
private boolean gioiTinh;
private String diaChi;
private String soDt;
/*==========CONSTRUCTOR==========*/
public KhachHang() {}
public KhachHang(String maKh, String tenKh, String hoKh, boolean gioiTinh, String diaChi, String soDt) {
this.maKh = maKh;
this.tenKh = tenKh;
this.hoKh = hoKh;
this.gioiTinh = gioiTinh;
this.diaChi = diaChi;
this.soDt = soDt;
}
public KhachHang(KhachHang kh) {
maKh = kh.maKh;
tenKh = kh.tenKh;
hoKh = kh.hoKh;
gioiTinh = kh.gioiTinh;
diaChi = kh.diaChi;
soDt = kh.soDt;
}
/*==========GETTER & SETTER==========*/
public String getMaKh() {
return maKh;
}
public void setMaKh(String maKh) {
this.maKh = maKh;
}
public String getTenKh() {
return tenKh;
}
public void setTenKh(String tenKh) {
this.tenKh = tenKh;
}
public String getHoKh() {
return hoKh;
}
public void setHoKh(String hoKh) {
this.hoKh = hoKh;
}
public boolean isGioiTinh() {
return gioiTinh;
}
public void setGioiTinh(boolean gioiTinh) {
this.gioiTinh = gioiTinh;
}
public String getDiaChi() {
return diaChi;
}
public void setDiaChi(String diaChi) {
this.diaChi = diaChi;
}
public String getSoDt() {
return soDt;
}
public void setSoDt(String soDt) {
this.soDt = soDt;
}
/*=========INPUT & OUTPUT==========*/
public void nhap()
{
RemoveRedundantSpace rp = new RemoveRedundantSpace();
//Enter maKh
while(true) {
System.out.print("Nhap vao ma khach hang (5 so): ");
maKh = in.nextLine();
if(maKh.length() == 5) {
break;
}
}
//Enter hoKh
while(true) {
System.out.print("Nhap vao ho va chu lot cua khach hang: ");
hoKh = in.nextLine();
if(hoKh.equals(" ") == false && hoKh.equals("") == false && hoKh.equals(null) == false) {
break;
}
}
hoKh = rp.removeSpace(hoKh); //remove all redundant space from user input
//Enter tenKh
while(true) {
System.out.print("Nhap vao ten cua khach hang: ");
tenKh = in.nextLine();
if(tenKh.equals(" ") == false && tenKh.equals("") == false && tenKh.equals(null) == false) {
break;
}
}
tenKh = rp.removeSpace(tenKh); //remove all redundant space from user input
//Enter gender
String genderText;
while(true) {
System.out.print("Nhap vao gioi tinh cua khach hang (nam hoac nu): ");
genderText = in.nextLine();
if(genderText.equals("nam") == true || genderText.equals("nu") == true) {
break;
}
}
if(genderText.equals("nam") == true) {
gioiTinh = true;
}else {
gioiTinh = false;
}
//Enter phone number
System.out.print("Nhap vao so dien thoai cua khach hang: ");
soDt = in.nextLine();
//Enter address
while(true) {
System.out.print("Nhap vao dia chi cua khach hang: ");
diaChi = in.nextLine();
if(diaChi.equals(" ") == false && diaChi.equals("") == false && diaChi.equals(null) == false) {
break;
}
}
}
public void xuat()
{
//handle name output
String hoTen = hoKh + " " + tenKh;
hoTen = hoTen.toUpperCase();
int nameLength = hoTen.length();
for(int i = 0; i < 28-nameLength; i++) {
hoTen += " ";
}
//handle gender output
String genderText;
if(gioiTinh == true) {
genderText = "nam";
}else {
genderText = "nu ";
}
//Handle address
int addressLength = diaChi.length();
String diaChiTam = diaChi;
for(int i = 0; i < 90 - addressLength; i++) {
diaChiTam += " ";
}
//output row
System.out.print(maKh + " | " + hoTen + " | " + genderText + " | " + diaChiTam + " | " + soDt + " | ");
}
/*==========WRITE FILE==========*/
public void ghiFile(String fileName)throws IOException {
DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName, Boolean.TRUE));
try {
out.writeUTF(maKh);
out.writeUTF(tenKh);
out.writeUTF(hoKh);
out.writeBoolean(gioiTinh);
out.writeUTF(diaChi);
out.writeUTF(soDt);
}catch(IOException e) {}
finally {
out.close();
}
}
}