Address_18344019.java
Address_18344019.java
/*
* Student ID: 18344019
* Name: Adam Doan
* Campus: Parramatta
* Tutor Name: Paul Davies
* Class Day: Thursday
* Class Time: 09:00 am
*/
//Class Address
public class Address
{
//Instance variables
private String street;
private String suburb;
private String state;
private int postCode;
//Constructor
public Address(String street, String suburb, String state, int postCode)
{
this.street = street;
this.suburb = suburb;
this.state = state;
this.postCode = postCode;
}
/*
* Accessors
*/
public String getStreet() {
return street;
}
public String getSuburb() {
return suburb;
}
public String getState() {
return state;
}
public int getPostCode() {
return postCode;
}
//Method to get String representation of Address
@Override
public String toString() {
return street + " " + suburb + " " + state + " " + postCode;
}
}
//Student ID: 18344019
Client_18344019.java
Client_18344019.java
/*
* Student ID: 18344019
* Name: Adam Doan
* Campus: Parramatta
* Tutor Name: Paul Davies
* Class Day: Thursday
* Class Time: 09:00 am
*/
//Class Client
public class Client
{
//Instance variables
private int clientID;
private String firstName;
private String surName;
private Address address;
//Default Constructor
public Client()
{
this.clientID = 0;
this.firstName = "";
this.surName = "";
this.address = null;
}
//Parameterized Constructors
public Client(int clientID, String firstName, String surName, Address address)
{
this.clientID = clientID;
this.firstName = firstName;
this.surName = surName;
this.address = address;
}
/*
* Accessors
*/
public int getClientID() {
return clientID;
}
public String getFirstName() {
return firstName;
}
public String getSurName() {
return surName;
}
public Address getAddress() {
return address;
}
/*
* Mutators
*/
public void setClientID(int clientID) {
this.clientID = clientID;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setSurName(String surName) {
this.surName = surName;
}
public void setAddress(Address address) {
this.address = address;
}
//Method to get full name of client
public String getName() {
return this.firstName + " " + this.surName;
}
}
//Student ID: 18344019
Driver_18344019.java
Driver_18344019.java
/*
* Student ID: 18344019
* Name: Adam Doan
* Campus: Parramatta
* Tutor Name: Paul Davies
* Class Day: Thursday
* Class Time: 09:00 am
*/
//Importing Scanner class for user input
import java.util.Scanner;
//Importing ArrayList class for using ArrayList
import java.util.ArrayList;
/*
* Importing classes for File Reading & Writing
*/
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.FileWriter;
//Importing classes for handling exceptions
import java.io.IOException;
import java.io.FileNotFoundException;
//Importing Date class for handling date
import java.util.Date;
//Importing SimpleDateFormat class for setting Date format
import java.text.SimpleDateFormat;
//Class Driver
public class Driver
{
//main method
public static void main(String[] args) throws IOException
{
//Creating Scanner object for taking user input
Scanner sc = new Scanner(System.in);
/*
* Setting filenames in respective variables
*/
String clients_filename = "clients.txt";
String properties_filename = "properties.txt";
String expenses_filename = "expenses.txt";
String rents_filename = "rents.txt";
//Declaring object for reading file
BufferedReader br;
//Declaring object for writing file
PrintWriter pr;
//Declaring flag variables
boolean changes = false, records, xchg;
//Declaring variables to process data read from file
String line, data[], sub_data[];
//Declaring variables to store user choice
int menu_ch, ch, report_ch;
//Declaring iterator for loop
int i, j, k;
//Declaring variables to store count & index
int count, index;
/*
* Declaring ArrayList of respective class objects
*/
ArrayList
c = new ArrayList();
ArrayList p = new ArrayList();
ArrayList e = new ArrayList();
ArrayList r = new ArrayList();
/*
* Declaring temporary variables for data processing
*/
String address, name = "", description = "";
Address addr;
int id, weeks, postcode;
double rent, expense, fee_rate, fee, net;
double rent_total, expense_total, fee_total, net_total;
String temp_client[], temp_c;
int c_index[], temp_c_index;
//Creating a date format object
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//Declaring variable to store current date
String current_date;
//Repeating until file is found
do
{
try
{
//Reading file
br = new BufferedReader(new FileReader(clients_filename));
break;
}
catch(FileNotFoundException ex)
{
/*
* Displaying file not found message and
* requesting new file name from user
*/
System.out.println(clients_filename + " file does not exists");
System.out.print("Please enter new filename that contains clients data: ");
clients_filename = sc.nextLine();
}
}while(true);
/*
* Loading data from file to ArrayList of object
*/
while((line = br.readLine()) != null)
{
data = line.split(",");
sub_data = data[1].split(" ");
c.add(new Client(Integer.parseInt(data[0]), sub_data[0], sub_data[1],
new Address(data[2], data[3], data[4], Integer.parseInt(data[5]))));
}
//Closing the file
br.close();
//Repeating until file is found
do
{
try
{
//Reading file
br = new BufferedReader(new FileReader(properties_filename));
break;
}
catch(FileNotFoundException ex)
{
/*
* Displaying file not found message and
* requesting new file name from user
*/
System.out.println(properties_filename + " file does not exists");
System.out.print("Please enter new filename that contains properties data: ");
properties_filename = sc.nextLine();
}
}while(true);
/*
* Loading data from file to ArrayList of object
*/
while((line = br.readLine()) != null)
{
data = line.split(",");
p.add(new Property(Integer.parseInt(data[0]), new Address(data[1], data[2], data[3],
Integer.parseInt(data[4])), Double.parseDouble(data[5]),
Double.parseDouble(data[6]), Integer.parseInt(data[7])));
}
//Closing the file
br.close();
//Repeating until file is found
do
{
try
{
//Reading file
br = new BufferedReader(new FileReader(expenses_filename));
break;
}
catch(FileNotFoundException ex)
{
/*
* Displaying file not found message and
* requesting new file name from user
*/
System.out.println(expenses_filename + " file does not exists");
System.out.print("Please enter new filename that contains expenses data: ");
expenses_filename = sc.nextLine();
}
}while(true);
/*
* Loading data from file to ArrayList of object
*/
while((line = br.readLine()) != null)
{
data = line.split(",");
e.add(new Expense(Integer.parseInt(data[0]), data[1], Double.parseDouble(data[2]), data[3]));
}
//Closing the file
br.close();
//Repeating until file is found
do
{
try
{
//Reading file
br = new BufferedReader(new FileReader(rents_filename));
break;
}
catch(FileNotFoundException ex)
{
/*
* Displaying file not found message and
* requesting new file name from user
*/
System.out.println(rents_filename + " file does not exists");
System.out.print("Please enter new filename that contains rents data: ");
rents_filename = sc.nextLine();
}
}while(true);
/*
* Loading data from file to ArrayList of object
*/
while((line = br.readLine()) != null)
{
data = line.split(",");
r.add(new Rent(Integer.parseInt(data[0]), Double.parseDouble(data[1]), data[2]));
}
//Closing the file
br.close();
//Repeating until user chooses to exit program
do
{
//Displaying Main Menu
System.out.println("1. Record Rent Collection");
System.out.println("2. Record Expense");
System.out.println("3. Generate Portfolio Report");
System.out.println("4. Save");
System.out.println("5. Exit Program");
//Requesting user choice
System.out.print("Enter your choice: ");
menu_ch = sc.nextInt();
sc.nextLine();
//Comparing user choice with the available cases
switch(menu_ch)
{
case 1:
//Requesting property address from user
System.out.print("\nEnter address of property: ");
address = sc.nextLine();
//Initializing count & index variables
count = 0;
index = -1;
/*
* Fetching count of matching properties
*/
for(i=0; i {
addr = p.get(i).getAddress();
if(addr.toString().contains(address))
{
++count;
index = i;
}
}
//Checking whether record is not found
if(count == 0)
{
//Displaying not found message
System.out.println("Property not found.");
break;
}
//Checking whether only one record found
else if(count == 1)
{
/*
* Getting client name
*/
for(j=0; j {
if(c.get(j).getClientID() == p.get(index).getClientID())
name = c.get(j).getName();
}
/*
* Displaying property details
*/
System.out.print(p.get(index).getAddress().toString());
System.out.print("\t" + String.format("%.2f", p.get(index).getWeeklyRent()));
System.out.println("\t" + name);
}
else
{
/*
* Displaying all matching properties
*/
System.out.println();
for(i=0; i {
addr = p.get(i).getAddress();
if(addr.toString().contains(address))
System.out.println(p.get(i).getPropertyID() + ". " + p.get(i).getAddress().toString());
}
/*
* Repeating until user chooses a property ID
*/
do
{
System.out.print("\nChoose property ID: ");
id = sc.nextInt();
sc.nextLine();
index = -1;
for(i=0; i {
if(p.get(i).getPropertyID() == id)
{
index = i;
break;
}
}
if(index == -1)
System.out.println("Invalid property ID.\n");
}while(index == -1);
//Getting client name
for(j=0; j {
if(c.get(j).getClientID() == p.get(index).getClientID())
name = c.get(j).getName();
}
//Displaying property details
System.out.print("\n" + p.get(index).getAddress().toString());
System.out.print("\t" + String.format("%.2f", p.get(index).getWeeklyRent()));
...