Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions SCF-RealEstateAgency/SCF-RealEstateAgency.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/bin" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file added SCF-RealEstateAgency/bin/app/AgencyApplication.class
Binary file not shown.
Binary file added SCF-RealEstateAgency/bin/app/Customer.class
Binary file not shown.
Binary file added SCF-RealEstateAgency/bin/app/Employee.class
Binary file not shown.
Binary file added SCF-RealEstateAgency/bin/app/PartTimeEmp.class
Binary file not shown.
Binary file added SCF-RealEstateAgency/bin/app/Property.class
Binary file not shown.
Binary file not shown.
Binary file added SCF-RealEstateAgency/bin/login/Database.class
Binary file not shown.
Binary file added SCF-RealEstateAgency/bin/login/Menu.class
Binary file not shown.
Binary file added SCF-RealEstateAgency/bin/login/User.class
Binary file not shown.
Binary file added SCF-RealEstateAgency/bin/main/Driver.class
Binary file not shown.
2 changes: 2 additions & 0 deletions SCF-RealEstateAgency/customer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JUNYU,LEE,adifis@121.com,vic,junyu11,junyu22,1568956252566,VENDOR
ASIDJF,ASDF,asidfj,aid,asd,adsf,1568956465180,VENDR
1 change: 1 addition & 0 deletions SCF-RealEstateAgency/fake-people-db.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
north,dec,sdsdwed@hotmail.com,vic,north123,pass123,NORDECSDS
2 changes: 2 additions & 0 deletions SCF-RealEstateAgency/property.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1568956287640,1568956252566,jiasdjfs,vic,1,3,4,unit
1568956564884,1568956465180,ijoi,vic,2,3,4,house
5 changes: 5 additions & 0 deletions SCF-RealEstateAgency/src/app/AgencyApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package app;

public class AgencyApplication {

}
17 changes: 17 additions & 0 deletions SCF-RealEstateAgency/src/app/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app;

import java.util.Scanner;

import login.Database;
import login.User;

public class Customer extends User {
private String type;

public Customer(String[] parts, String type) {
// TODO Auto-generated constructor stub
super(parts);
this.type = type;
}

}
42 changes: 42 additions & 0 deletions SCF-RealEstateAgency/src/app/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app;

import java.util.Scanner;

public class Employee {

private String empId;

Scanner scanner = new Scanner (System.in);

public int salary(int salary)
{
int salary1;
int hours;
//System.out.println("Please enter your base salary: ");
salary = scanner.nextInt();
System.out.println("Please enter the hours you have worked: ");
hours = scanner.nextInt();

salary1 = salary * hours;

return salary1;
}

public Employee (String empId)
{
this.empId = empId;
}

public void salesConsultant () {

}

public void propertyManagers ()
{

}
public void branchAdministrator()
{

}
}
33 changes: 33 additions & 0 deletions SCF-RealEstateAgency/src/app/PartTimeEmp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package app;


public class PartTimeEmp extends Employee {

private String empId;
private String name;


public PartTimeEmp (String empId) {
super(empId);
}

@Override
public int salary (int salary)
{
return 0;
}

@Override
public void salesConsultant()
{

}
@Override
public void propertyManagers() {

}
@Override
public void branchAdministrator() {

}
}
108 changes: 108 additions & 0 deletions SCF-RealEstateAgency/src/app/Property.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package app;

public class Property {
String propertyId;
String custId;
String address;
String suburb;
int bedrooms;
int bathrooms;
int car_spaces;
String type;
public String getPropertyId() {
return propertyId;
}
public void setPropertyId(String propertyId) {
this.propertyId = propertyId;
}

public String getCustId() {
return custId;
}
public void setCustId(String custId) {
this.custId = custId;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getSuburb() {
return suburb;
}
public void setSuburb(String suburb) {
this.suburb = suburb;
}
public int getBedrooms() {
return bedrooms;
}
public void setBedrooms(int bedrooms) {
this.bedrooms = bedrooms;
}
public int getBathrooms() {
return bathrooms;
}
public void setBathrooms(int bathrooms) {
this.bathrooms = bathrooms;
}
public int getCar_spaces() {
return car_spaces;
}
public void setCar_spaces(int car_spaces) {
this.car_spaces = car_spaces;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}

public Property(String propertyId, String custId, String address, String suburb, int bedrooms, int bathrooms,
int car_spaces, String type) {
super();
this.propertyId = propertyId;
this.custId = custId;
this.address = address;
this.suburb = suburb;
this.bedrooms = bedrooms;
this.bathrooms = bathrooms;
this.car_spaces = car_spaces;
this.type = type;
}
public Property() {
super();
// TODO Auto-generated constructor stub
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(propertyId)
.append(",")
.append(custId)
.append(",")
.append(address)
.append(",")
.append(suburb)
.append(",")
.append(bedrooms)
.append(",")
.append(bathrooms)
.append(",")
.append(car_spaces)
.append(",")
.append(type);
return sb.toString();
}

public String printInfo() {
return "this property address is "+address+", suburb is "+suburb
+", it has "+bedrooms+" bedroom/s, "
+bathrooms+ " bathroom/s, "
+car_spaces+" car space/s "
+"and property type is "+type;

}

}
12 changes: 12 additions & 0 deletions SCF-RealEstateAgency/src/exceptions/CorruptedFileException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package exceptions;

@SuppressWarnings("serial")
public class CorruptedFileException extends Exception {
public CorruptedFileException() {
super("File is corrupted");
}

public CorruptedFileException(String message) {
super(message);
}
}
150 changes: 150 additions & 0 deletions SCF-RealEstateAgency/src/login/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package login;

import app.Customer;
import app.Property;
import exceptions.CorruptedFileException;

import java.io.*;

import java.util.*;


public class Database {

public static Properties properties = new Properties();
// public static Map<String, User> load() {
// Map<String, User> user_map = new HashMap<String, User>();
// try {
// Scanner data_store = new Scanner(new File("fake-people-db.txt"));
//
// while (data_store.hasNextLine()) {
// String[] split_string = data_store.nextLine().split(",");
// User u = new User(split_string);
// user_map.put(u.username, u);
// }
//
// } catch (FileNotFoundException e) {
// System.out.println(e.getMessage());
// }
// return user_map;
// }
public void saveEmpUser(User user) throws IOException {
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("employee.txt")));

if (user != null) {
pw.println(user.toString());
}

pw.close();
}

public void saveCusUser(User user,String type) throws IOException {
FileWriter fileWriter =new FileWriter(new File("customer.txt"), true);
String info = user.toString() +","+type+System.getProperty("line.separator");
fileWriter.write(info);
fileWriter.flush();
fileWriter.close();
}

public void saveProperty(Property property) throws IOException {
FileWriter fileWriter =new FileWriter(new File("property.txt"), true);
String info = property.toString() +System.getProperty("line.separator");
fileWriter.write(info);
fileWriter.flush();
fileWriter.close();
}

public User loadUser(String userType, String username, String password) throws IOException {
String fileName;

if (userType.equals("customer")) {
fileName = "customer.txt";
} else {
fileName = "employee.txt";
}

// Create File Reading Objects
BufferedReader br = new BufferedReader(new FileReader(fileName));
String line;

User user = null;
while ((line = br.readLine()) != null) {
user = createUser(line, userType, username, password);
}

br.close();
return user;
}

public List<Property> loadProperty() throws IOException {
List<Property> list = new ArrayList<Property>();
String fileName = "property.txt";
// Create File Reading Objects
BufferedReader br = new BufferedReader(new FileReader(fileName));
String line;

Property property = null;
while ((line = br.readLine()) != null) {
property = createProperty(line);
if(property.getCustId().equals(properties.get("loginUserId"))) {
list.add(property);
}

}

br.close();
return list;
}

private User createUser(String line, String userType, String inputUsername, String inputPassword) {
StringTokenizer inReader = new StringTokenizer(line, ",");

String firstName = inReader.nextToken();
String lastName = inReader.nextToken();
String email = inReader.nextToken();
String suburb = inReader.nextToken();
String username = inReader.nextToken();
String password = inReader.nextToken();
String uniqueId = inReader.nextToken();
String type = null;
try {
type = inReader.nextToken();
} catch (Exception e) {
return null;
}

if (username.equals(inputUsername) && password.equals(inputPassword)) {
if (userType.equals("customer")) {
properties.put("loginUserId", uniqueId);
String[] parts = {firstName, lastName, email, suburb, username, password,uniqueId};
return new Customer(parts, type);
} else {
return null;
}
}
return null;
}
private Property createProperty(String line) {
StringTokenizer inReader = new StringTokenizer(line, ",");

String propertyId;
try {
propertyId = inReader.nextToken();

String custId = inReader.nextToken();
String address = inReader.nextToken();
String suburb = inReader.nextToken();
String bedrooms = inReader.nextToken();
String bathrooms = inReader.nextToken();
String car_spaces = inReader.nextToken();
String type = inReader.nextToken();
return new Property(propertyId, custId, address, suburb,
Integer.parseInt(bedrooms),
Integer.parseInt(bathrooms),
Integer.parseInt(car_spaces),
type);
} catch (Exception e) {
return null;
}
}
}
Loading