Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Similar assignment to last one

1 answer below »
Similar assignment to last one
Answered Same Day Sep 25, 2021

Solution

Sayed Shad Ahmad answered on Oct 11 2021
153 Votes
Address_18344019.java
Address_18344019.java
*
 * Student ID: 18344019
 * Name: Adam Doan
 * Campus: Pa
amatta
 * Tutor Name: Paul Davies
 * Class Day: Thursday
 * Class Time: 09:00 am
 *
Class Address
public class Address 
{
    
Instance variables
    private String street;
    private String subu
;
    private String state;
    private int postCode;
    
    
Constructo
    public Address(String street, String subu
, String state, int postCode)
    {
        this.street = street;
        this.subu
 = subu
;
        this.state = state;
        this.postCode = postCode;
    }
    
    /*
     * Accessors
     *
    public String getStreet() {
        return street;
    }
    
    public String getSubu
() {
        return subu
;
    }
    
    public String getState() {
        return state;
    }
    
    public int getPostCode() {
        return postCode;
    }
    
Method to get String representation of Address
    @Ove
ide
    public String toString() {
        return street + " " + subu
 + " " + state + " " + postCode;
    }
}
Student ID: 18344019
Client_18344019.java
Client_18344019.java
*
 * Student ID: 18344019
 * Name: Adam Doan
 * Campus: Pa
amatta
 * 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 Constructo
    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: Pa
amatta
 * Tutor Name: Paul Davies
 * Class Day: Thursday
 * Class Time: 09:00 am
 *
Importing Scanner class for user input
import java.util.Scanner;
Importing A
ayList class for using A
ayList
import java.util.A
ayList;
*
 * 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 Drive
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 
;
        
        
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 A
ayList of respective class objects
         *
        A
ayList c = new A
ayList();
        A
ayList p = new A
ayList();
        A
ayList e = new A
ayList();
        A
ayList r = new A
ayList();
        
        /*
         * 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 cu
ent date
        String cu
ent_date;
        
        
Repeating until file is found
        do
        {
            try
            {
                
Reading file
                
 = new BufferedReader(new FileReader(clients_filename));
                
eak;
            }
            catch(FileNotFoundException ex)
            {
                /*
                 * Displaying file not found message and
                 * requesting new file name from use
                 *
                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 A
ayList of object
         *
        while((line = 
.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
        
.close();
        
        
Repeating until file is found
        do
        {
            try
            {
                
Reading file
                
 = new BufferedReader(new FileReader(properties_filename));
                
eak;
            }
            catch(FileNotFoundException ex)
            {
                /*
                 * Displaying file not found message and
                 * requesting new file name from use
                 *
                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 A
ayList of object
         *
        while((line = 
.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
        
.close();
        
Repeating until file is found
        do
        {
            try
            {
                
Reading file
                
 = new BufferedReader(new FileReader(expenses_filename));
                
eak;
            }
            catch(FileNotFoundException ex)
            {
                /*
                 * Displaying file not found message and
                 * requesting new file name from use
                 *
                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 A
ayList of object
         *
        while((line = 
.readLine()) != null)
        {
            data = line.split(",");
            
            e.add(new Expense(Integer.parseInt(data[0]), data[1], Double.parseDouble(data[2]), data[3]));
        }
    
        
Closing the file
        
.close();
        
Repeating until file is found
        do
        {
            try
            {
                
Reading file
                
 = new BufferedReader(new FileReader(rents_filename));
                
eak;
            }
            catch(FileNotFoundException ex)
            {
                /*
                 * Displaying file not found message and
                 * requesting new file name from use
                 *
                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 A
ayList of object
         *
        while((line = 
.readLine()) != null)
        {
            data = line.split(",");
            
            r.add(new Rent(Integer.parseInt(data[0]), Double.parseDouble(data[1]), data[2]));
        }
        
        
Closing the file
        
.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 use
                    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.");
                        
eak;
                    }
                    
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;
                                    
eak;
                                }
                            }
                            
                            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()));
                 ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here