-
Notifications
You must be signed in to change notification settings - Fork 0
/
Personal.java
80 lines (77 loc) · 2.34 KB
/
Personal.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
import java.io.*;
class Personal extends DbObject
{
protected final int nameLen = 50;
protected final int cityLen = 20;
protected int SSN;
protected String name;
protected String city;
protected short yearOfBirth;
protected double salary;
Personal()
{
//no-arg constructor, as intended
}
Personal(int SSN, String name, String city, short yearOfBirth, double salary)
{
this.SSN = SSN;
this.name = name;
this.city = city;
this.yearOfBirth = yearOfBirth;
this.salary = salary;
}
public void readFromConsole() throws IOException
{
System.out.println("Fetching information from console...");
System.out.print("Enter the ID: ");
this.SSN = sc.nextInt();
System.out.print("Enter the name: ");
this.name = sc.next();
sc.nextLine();
for(int i = this.name.length(); i < nameLen; i++)
{
this.name += " ";
}
this.name = this.name.substring(0,nameLen);
System.out.print("Enter the city: ");
this.city = sc.next();
sc.nextLine();
for(int i = this.city.length(); i < cityLen; i++)
{
this.city += " ";
}
this.city = this.city.substring(0, cityLen);
System.out.print("Enter the year of birth: ");
this.yearOfBirth = sc.nextShort();
System.out.println("Enter the salary: ");
this.salary = sc.nextDouble();
}
public void readFromFile(RandomAccessFile in) throws IOException
{
this.SSN = in.readInt();
this.name = readString(nameLen, in);
this.city = readString(cityLen, in);
this.yearOfBirth = in.readShort();
this.salary = in.readDouble();
}
public void writeToFile(RandomAccessFile out) throws IOException
{
out.writeInt(this.SSN);
writeString(this.name, out);
writeString(this.city, out);
out.writeShort(this.yearOfBirth);
out.writeDouble(this.salary);
}
public int getUID()
{
return SSN;
}
public void display()
{
System.out.print("SSN: " + SSN + ", Name: " + name.trim() + ", City: " + city.trim() + ", Year of Birth: " + yearOfBirth + ", Salary: " + salary);
}
public long size()
{
return 14 + 2 * nameLen + 2 * cityLen;
}
}