Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Cape Peninsula University of Technology Department of Information Technology App

ID: 3747419 • Letter: C

Question

Cape Peninsula University of Technology

Department of Information Technology

Application Development Practice II                       October 2018

Final Project

You are asked to write an information management application for a small DVD rental store that is just starting up. The owners only have one copy of any particular Dvd.

Design a client/server system which maintains a database for the store.

The user requests database information and operations via the client application. The client app sends the database request to the server which executes the request and returns the results of the request back to the client.

Given:

The UMLs and Java source code for 3 classes, Dvd, Customer, and Rental.

Do not make any changes to the Dvd.java, Customer.java and Rental.java source code.

If you really have to make changes then you will have to re-create the ser files.

Dvd

-dvdNumber : int

-title : String

-category : String

-price : double

-newRelease : boolean

-availableForRent : boolean

<<constructor>>+Dvd( )

<<constructor>>+Dvd( dvdNumber : int, title : String , category : int, newRelease: boolean, avail : boolean )

+setdvdNumber(dvdNum : int) : void

+setTitle( aTitle : String ) : void

+setCategory( aCategory : int ) : void

+setRelease( rel : boolean ) : void

-setPrice( ) : void    (NOTE: this method is private as it is only referenced from this class itself)

+setAvailable( avail : boolean ) : void

+getDvdNumber( ) : int

+getTitle( ) : String

+getCategory( ) : String

+getPrice( ) : int

+isNewRelease( ) : boolean

+isAvailable( ) : boolean

+toString( ) : String

Do not make any changes to the Dvd.java, Customer.java and Rental.java source code.

If you really have to make changes then you will have to re-create the ser files.

Rental

-rentalNumber: int

-dateRented: String

-dateReturned: String

-customerNumber: int

-dvdNumber: int

-totalPenaltyCost : double

-TOTAL_PENALTY_COST_PER_DAY : final double

<<constructor>>+Rental( )

<<constructor>>+Rental(rentNumber: int, dateRented: String, custNumber: int, dvdNumber: int )

<<constructor>>+Rental(rentNumber: int, dateRented: String, dateReturned: String, custNumber: int, dvdNumber: int )

+get methods…..

+set methods…..

+setDateReturned(String dt) : void (this method sets the date and also calls the method to determine the total penalty cost)

+numberOfDaysOverdue( ) : int

-daysBetween( date1 Date, date2 : Date) : int

-dateDifference(String dateRented, String dateReturned) : int

-determineTotalPenaltyCost( ) : void (this method calculates total penalty cost based on the number of days between

                                                            the date rented and the date returned.)

-toString( ) : String

Customer

-custNumber : int

-firstName : String

-surname : String

-phoneNum : String

-credit : double

-canRent : boolean

<<constructor>>+Customer( )

<<constructor>>+ Customer (custNumber : int, fName : String , sName : String , phone : String, credAmt: double, can : boolean)

+setCustNumber (custNumber int) : void

+setName( fName : String ) : void

+setSurname( sName : String ) : void

+setPhoneNum( phone : String ) : void

+setCredit( credAmt : double ) : void

+setCanRent(can : double ) : void

+getCustNumber( ) : int

+getFirstName( ) : String

+getSurname( ) : String

+getPhoneNum( ) : String

+getCredit( ) : double

+canRent( ) : boolean

+toString( ) : String

A serialized file containing customer data, Customers.ser

A serialized file containing movie data, Movies.ser

A serialized file containing rental data, Rentals.ser

Additional info:

Dvd class

Possible categories are horror, sci-fi, drama, romance, comedy, action, cartoon.

The fee for a movie is R10, and new releases are R5 more.

Customer class

When a customer is added to the system he/she must pay R100 which is captured as credit.

The rental fee is deducted from the customer’s credit when renting a movie.

If a customer has insufficient credit the option to pay the movie fee for this transaction is shown. The customer can choose to pay the required fee, or load R100 credit, or neither and thereby cancel the transaction.

Database Tables:

Customer table

custNumber is a primary key

A customer can only rent one Dvd at a time. A customer can only rent if a previously rented dvd has been returned. The attribute canRent indicates whether a customer is allowed to rent a dvd: When a customer rents a dvd this attribute is set to FALSE. When a customer returns a dvd, this attribute is set to TRUE.

Dvd table

dvdNumber is a primary key.

The attribute availableForRent is set to FALSE when a dvd is rented to a customer. It is set back to TRUE when a dvd is returned.

Rental table

rentalNumber is a primary key.

Attributes custNumber and dvdNumber are foreign keys.

totalPenaltyCost is calculated as follows: Every dvd rented must be returned within 24 hrs. R5 penalty is charged for every day exceeding the first 24hrs between the date rented and the date returned.

REQUIRED

Write a standalone JAVA program to load the data to the database. The program must:

Create database tables, customer, dvd and rental.

Load data into the database tables from the serialized files.

Display the number of rows inserted for each table.

Write a client server application to manage the car rentals.

CLIENT REQUIREMENTS

Write a GUI application which presents the user with options to manipulate the database. The minimum functionality of the client are:

Add a new customer

Add a new dvd

Rent a dvd

Select an existing customer

Select a movie category .Select from list of available movies for category selected

Display appropriate message after the server has updated the database

Return a dvd

Select/enter the rental number

Display appropriate message after the server has updated the DB tables. Display penalty cost if necessary.

List all movies and details by category (sorted)

List all customers and details (sorted alphabetically)

Search: the user enters a letter and all movies that start with that letter are listed.

….all movie lists must show the movie title, category, whether new release or not, whether available or not.

Include the following reports:

Display all rentals, sorted by date.

Display outstanding rentals (movies that have not been returned yet).

Daily rentals for a particular date.

Reduce chances of typing errors by making intelligent use of GUI items that require simple mouse-clicking to make selections.

SERVER REQUIREMENTS

Receive requests from the client to do transactions on the database. Results of these database requests are sent back to the client.

Add a new customer: execute the SQL command(s)

Add a new dvd: execute the SQL command(s)

Rent a dvd

Execute SQL to select all customers and send details to client

Execute SQL to select all dvd’s for a specific category and send details to client.

Receive the customer and dvd selected from the client.

Update the database tables

Update the customer table

Update the dvd table

Insert a new row (record) into the rental table.

Send a message to client indicating new rental is completed

Return a dvd

Receive the rental number from the client.

Update the customer table

Update the dvd table

Determine if dvd is overdue. Update the rental table.

Send a message to the client.

List all movies and details by category (sorted): Execute SQL to select dvd data and send to client

List all customers and details (sorted): Execute SQL to select all customer data and send to client

Reports: Execute SQL to select appropriate data and send to client

Dvd

-dvdNumber : int

-title : String

-category : String

-price : double

-newRelease : boolean

-availableForRent : boolean

<<constructor>>+Dvd( )

<<constructor>>+Dvd( dvdNumber : int, title : String , category : int, newRelease: boolean, avail : boolean )

+setdvdNumber(dvdNum : int) : void

+setTitle( aTitle : String ) : void

+setCategory( aCategory : int ) : void

+setRelease( rel : boolean ) : void

-setPrice( ) : void    (NOTE: this method is private as it is only referenced from this class itself)

+setAvailable( avail : boolean ) : void

+getDvdNumber( ) : int

+getTitle( ) : String

+getCategory( ) : String

+getPrice( ) : int

+isNewRelease( ) : boolean

+isAvailable( ) : boolean

+toString( ) : String

Explanation / Answer

AddCustFrame.java


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class AddCustFrame extends javax.swing.JFrame {

    private DefaultTableModel model;

    public AddCustFrame() {
        initComponents();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        custName = new javax.swing.JTextField();
        custSurname = new javax.swing.JTextField();
        custPhone = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        ctable = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel2.setText("Name");

        jLabel3.setText("Surname");

        jLabel4.setText("Phone Number");

        jButton1.setText("Add");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        ctable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "CustNum", "CustomerName"
            }
        ));
        jScrollPane3.setViewportView(ctable);

        jButton2.setText("Delete");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(custSurname, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(102, 102, 102)
                                .addComponent(custName, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(59, 59, 59)
                                .addComponent(custPhone))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(95, 95, 95)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addGap(95, 95, 95))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(custName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(custSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(custPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        Client objClient = new Client();
    
        String cName = this.custName.getText();
        String cSurname = this.custSurname.getText();
        String cPhone = this.custPhone.getText();
    

        this.custName.setText("");
        this.custSurname.setText("");
        this.custPhone.setText("");
    
        objClient.addNewCustomer(cName, cSurname, cPhone);
        populateTable();
            }//GEN-LAST:event_jButton1ActionPerformed

    public void populateTable(){

       Client cView = new Client();
   
       ArrayList<Customer> list = new ArrayList<Customer>(cView.customerTable());
   
        model = (DefaultTableModel) ctable.getModel();
        model.setRowCount(0);
        for(int a = 0; a<list.size(); a++)
        {
        model.addRow(new Object[]{list.get(a).getCustNumber(), list.get(a).getName(),list.get(a).getSurname(),
        list.get(a).getPhoneNum(),list.get(a).getCredit(), list.get(a).canRent()});
        }


    }
    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AddCustFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AddCustFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AddCustFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AddCustFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddCustFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable ctable;
    private javax.swing.JTextField custName;
    private javax.swing.JTextField custPhone;
    private javax.swing.JTextField custSurname;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
}


Client.java

import java.awt.event.ActionEvent;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Client extends javax.swing.JFrame {

    private static Socket socket;
    private static ObjectOutputStream out;
    private static ObjectInputStream in;
    private ArrayList<Customer> customerList;
    public Client() {
        initComponents();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnAddCustomer = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnAddCustomer.setText("Add a new Customer");
        btnAddCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddCustomerActionPerformed(evt);
            }
        });

        jButton2.setText("jButton2");

        jButton3.setText("jButton3");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("jButton4");

        jButton5.setText("jButton5");

        jButton6.setText("jButton6");

        jButton7.setText("jButton7");

        jButton8.setText("jButton8");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2)
                    .addComponent(jButton7, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3)
                    .addComponent(jButton5))
                .addGap(70, 70, 70))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton8)
                .addGap(24, 24, 24))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(153, 153, 153)
                        .addComponent(jButton6))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(127, 127, 127)
                        .addComponent(btnAddCustomer)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(btnAddCustomer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton8))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton6)
                .addContainerGap(105, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    private void addCust()
   {
     AddCustFrame objAddCust = new AddCustFrame();

     objAddCust.show();
     this.dispose();
   }

    private void addDvd()
   {
     this.dispose();
   }

    private void rentDvd()
   {
     this.dispose();
   }

    private void returnDvd()
   {
     this.dispose();
   }

    private void listAllMovies()
   {
     this.dispose();
   }

    private void listAllCust()
   {
     this.dispose();
   }
    private void searchMovies()
   {
     this.dispose();
   }


    private void btnAddCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddCustomerActionPerformed

        addCust();
    }//GEN-LAST:event_btnAddCustomerActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    
        addDvd();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed

        rentDvd();
    
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    
        returnDvd();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
       listAllMovies();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        listAllCust();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        searchMovies();
    }//GEN-LAST:event_jButton6ActionPerformed
    public static void main(String args[]) {
      try
        {
            socket = new Socket("localhost", 30000);
            out = new ObjectOutputStream(socket.getOutputStream());
            out.flush();
            in = new ObjectInputStream(socket.getInputStream());
    
        }
      catch(IOException e)
        {
            e.printStackTrace();
        }

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Client().setVisible(true);
            }
        });
    }

    public ArrayList customerTable(){
    customerList = new ArrayList<Customer>();
     try
     {
        out.writeObject("tableC");
        out.flush();
        customerList = (ArrayList) in.readObject();
     }
     catch(IOException e)
     {
        e.printStackTrace();
     }
     catch(ClassNotFoundException e)
     {
        e.printStackTrace();
     }
   return customerList;
    }

    //sends request to server to add new customer
    public void addNewCustomer(String name, String surname, String phoneNumber){
    
        String message = name+"#"+surname+"#"+phoneNumber;
    
        String command = "addNew";
        try
        {
            out.writeObject(command+message);
            out.flush();
            String reply = (String)in.readObject();
            JOptionPane.showMessageDialog(null, reply);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        catch(ClassNotFoundException e)
        {
            e.printStackTrace();
        }
  
}
    //sends request to server to remove customer
    public void removeCustomer(int i){
        try
        {
            String number = Integer.toString(i);
            String command = "remove";
            out.writeObject(command+number);
            out.flush();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
public void closeStreams(){
try{
in.close();
out.close();
socket.close();
System.exit(0);
}catch(IOException e){
e.printStackTrace();
}
}
    public javax.swing.JButton btnAddCustomer;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    // End of variables declaration//GEN-END:variables
}


Customer.java

import java.io.*;

public class Customer implements Serializable
{
    private int custNumber;
    private String firstName;
    private String surname;
    private String phoneNum;
    private double credit;
    private boolean canRent;

    public Customer()
    {
    
    }

    public Customer(int custNumber, String fName, String lName, String phone, double credAmt, boolean can)
    {
        setCustNumber(custNumber);
        setName(fName);
        setSurname(lName);
        setPhoneNum(phone);
        setCredit(credAmt);
        setCanRent(can);
    }
    public void setCustNumber(int custNumber) {
       this.custNumber = custNumber;
    }

    public void setName(String sFName)
    {
        firstName = sFName;
    }
    public void setSurname(String sSName)
    {
        surname = sSName;
    }

    public void setPhoneNum(String sPhone)
    {
        phoneNum = sPhone;
    }

    public void setCredit(double sCredAmt)
    {
        credit = sCredAmt;
    }
    public void setCanRent(boolean can)
    {
        canRent = can;
    }

    public int getCustNumber() {
       return custNumber;
    }
    public boolean canRent() {
       return canRent;
    }

    public String getName()
    {
        return firstName;
    }

    public String getSurname()
    {
        return surname;
    }

    public String getPhoneNum()
    {
        return phoneNum;
    }

    public double getCredit()
    {
        return credit;
    }

    //this method can be edited to format strings differently
    @Override
    public String toString()
    {
        return String.format("%-8d%-10s%-10s%-10s     %.2f %-6b", getCustNumber(), getName(), getSurname(),
                getPhoneNum(), getCredit(), canRent);
    }  
}

DVD.java
import java.io.*;

public class DVD implements Serializable
{
    private int dvdNumber;
    private String title;
    private String category;
    private double price;
    private boolean newRelease;
    private boolean availableForRent;

    //empty constructor
    public DVD()
    {
    
    }

    //constructor that takes 4 arguments to initialize the instance variables
    public DVD(int dvdNumber, String title, int category, boolean newRelease, boolean avail)
    {
        setDvdNumber(dvdNumber);
        setTitle(title);
        setCategory(category);
        setRelease(newRelease);
        setAvailable(avail);
    }

    // set methods
    public void setDvdNumber(int dvdNumber)
    {
        this.dvdNumber = dvdNumber;
    }
    public void setTitle(String sTitle)
    {
        title = sTitle;
    }

    public void setCategory(int sCategory)
    {
        switch(sCategory)
        {
            case 1:
                category = "horror";
                break;
            case 2:
                category = "Sci-fi";
                break;
            case 3:
                category = "Drama";
                break;
            case 4:
                category = "Romance";
                break;
            case 5:
                category = "Comedy";
                break;
            case 6:
                category = "Action";
                break;
            case 7:
                category = "Cartoon";
                break;
        }
    }

    public void setRelease(boolean sRelease)
    {
        newRelease = sRelease;
        setPrice();//sets the price based on whether movie is new release or not
    }
    private void setPrice()
    {
        if(newRelease)
            price = 15;
        else
            price = 10;
    }

    public void setAvailable(boolean sAvailable)
    {
        availableForRent = sAvailable;
    }

    //get methods
    public int getDvdNumber()
    {
        return dvdNumber;
    }
    public String getTitle()
    {
        return title;
    }

    public String getCategory()
    {
        return category;
    }
    public double getPrice()
    {
        return price;
    }
    //checks if the movie is a new release
    public boolean isNewRelease()
    {
        return newRelease;
    }

    //checks if the movie is available
    public boolean isAvailable()
    {
        return availableForRent;
    }

    //overrides the object method
    @Override
    public String toString()
    {
        return String.format("Dvd number: %-8dTitle: %-30sCategory:%-12sPrice:R%.2f New Release:%b Available:%b ", dvdNumber, title,category,price,newRelease,availableForRent);
    }
}

Rental.java

import java.io.*;
import java.util.*;

public class Rental implements Serializable
{
    private int rentalNumber;
    private String dateRented;
    private String dateReturned;
    private int custNumber;
    private int dvdNumber;
    private double totalPenaltyCost;
    private static final double PENALTY_COST_PER_DAY = 5;

    public Rental() {
    }

    public Rental (int rentalNumber, String dateRented, int custNumber , int dvdNumber) {
        this.rentalNumber = rentalNumber;
        this.dateRented = dateRented;
        this.dateReturned = "NA";
//        this.pricePerDay = pricePerDay;
        this.custNumber = custNumber;
        this.dvdNumber = dvdNumber;
//        determineTotalPenaltyCost();
    }

     public Rental (int rentalNumber, String dateRented, String dateReturned,
                    int custNumber , int dvdNumber) {
        this.rentalNumber = rentalNumber;
        this.dateRented = dateRented;
//        this.pricePerDay = pricePerDay;
        setDateReturned(dateReturned);
        determineTotalPenaltyCost();
        this.custNumber = custNumber;
        this.dvdNumber = dvdNumber;
    
    }
    public int getRentalNumber()
    {
        return this.rentalNumber;    
    }
    public String getDateRented()
    {
        return this.dateRented;    
    }
    public String getDateReturned()
    {
        return this.dateReturned;    
    }
    public int getCusNumber()
    {
        return this.custNumber;
    }
    public int dvdNumber()
    {
        return this.dvdNumber;
    }
//    public double getPricePerDay()
//    {
//        return this.pricePerDay;    
//    }
    public void setRentalNumber(int rn)
    {
        this.rentalNumber = rn;    
    }
    public void setDateRented(String rentD)
    {
        this.dateRented = rentD;
    }
//    public void setPricePerDay(double pricePerDay)
//    {
//        this.pricePerDay = pricePerDay;
//    }
    public void setDateReturned(String ret)
    {
        this.dateReturned = ret;
        determineTotalPenaltyCost();
    }
    public void setCustNumber(int cn)
    {
        this.custNumber = cn;    
    }
    public void setdvdNumber(int mov)
    {
        this.dvdNumber = mov;    
    }
    public double getTotalPenaltyCost()
    {
        return totalPenaltyCost;
    }
    public void determineTotalPenaltyCost()
    {
        totalPenaltyCost = numberOfDaysOverdue() * PENALTY_COST_PER_DAY;
    
    }
    private int dateDifference(String dateRented, String dateReturned) {
        int yyyy, mm, dd;
        StringTokenizer token;
        Calendar cal1 = new GregorianCalendar();
        Calendar cal2 = new GregorianCalendar();
    
        token = new StringTokenizer(dateRented, "/");
        yyyy = Integer.parseInt(token.nextToken());
        mm = Integer.parseInt(token.nextToken());
        dd = Integer.parseInt(token.nextToken());
        cal1.set(yyyy, mm, dd);
        if (!dateReturned.equalsIgnoreCase("NA")){
            token = new StringTokenizer(dateReturned, "/");
            yyyy = Integer.parseInt(token.nextToken());
            mm = Integer.parseInt(token.nextToken());
            dd = Integer.parseInt(token.nextToken());
            cal2.set(yyyy, mm, dd);
            return (daysBetween(cal1.getTime(),cal2.getTime()));
        }
        else
            return (0);
    }
    private int daysBetween(Date d1, Date d2){
        return (int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24)+1);
}

    public int numberOfDaysOverdue()
    {    
        int days = dateDifference(dateRented, dateReturned)-2;
        if (days < 0)
            return 0;
        else
            return days;
    }

    public String toString() {
        return "Rental#:" + rentalNumber + " Date Rented:" + dateRented + "   Date Returned:" + dateReturned + " Penalty cost per day:R" + PENALTY_COST_PER_DAY + " Total Penalty Cost:R" +
            totalPenaltyCost + " Customer#:" + custNumber + " Movie#:" + dvdNumber +" No of Days overdue:" + numberOfDaysOverdue()+" ";
    }


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote