Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need help with my code .... PLEASE HELP!!!!

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with my code .... PLEASE HELP!!!!

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package wheeliesvehicalrentalspackage;

    import java.sql.*;
    import java.util.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JOptionPane;

    /**
    *
    * @author Felisha
    */
    public class WVRSApplication {

    private Staff currentStaff;
    private ArrayList<Customer> customerList;
    private ArrayList<Vehicle> vehicleList;

    //No args constructor
    public WVRSApplication(){}

    //Full Constructor
    public WVRSApplication(Staff s)
    {
    this.currentStaff = s;

    //Gte instance of staffDAO
    StaffDAO sdao = new StaffDAO();
    Logger logger = Logger.getLogger("wheeliesvehicalrentalspackage.WV RSApplication");

    //Load customer list from database
    try{
    //Load customer list from database
    this.customerList = sdao.getAllCustomersFromDatabase();

    //Load vehicle list from database
    this.vehicleList = sdao.getAllVehiclesFromDatabase();
    }
    catch(SQLException sqle)
    {
    logger.log(Level.SEVERE,String.format("SQL Exception while loading lists: %s", sqle.getMessage()));
    }
    catch(Exception e)
    {
    logger.log(Level.SEVERE,String.format("Exception while loading lists: %s", e.getMessage()));
    }

    }


    //Method to be called when adding a customer to the database
    //DO NOT MODIFY OR REMOVE
    private void addCustomerToDatabase(Customer c)
    {
    ClerkDAO cdao = new ClerkDAO();
    Logger logger = Logger.getLogger("wheeliesvehicalrentalspackage.WV RSApplication");
    try{
    StaffDAO sdao = new StaffDAO();
    cdao.addCustomerToDatabase(c);
    this.customerList = sdao.getAllCustomersFromDatabase();
    }
    catch(SQLException sqle)
    {
    logger.log(Level.SEVERE,String.format("SQL Exception while adding customer to database %s", sqle.getMessage()));
    }
    catch(Exception e)
    {
    logger.log(Level.SEVERE,String.format("Exception while adding customer to database %s", e.getMessage()));
    }
    }

    //Method to be called when adding a vehicle to the database
    //DO NOT MODIFY OR REMOVE
    private void addVehicleToDatabase(Vehicle v)
    {
    ManagerDAO mdao = new ManagerDAO();
    Logger logger = Logger.getLogger("wheeliesvehicalrentalspackage.WV RSApplication");
    try{
    mdao.addVehicleToDatabase(v);
    }
    catch(SQLException sqle)
    {
    logger.log(Level.SEVERE,String.format("SQL Exception while adding vehicle to database: %s", sqle.getMessage()));
    }
    catch(Exception e)
    {
    logger.log(Level.SEVERE,String.format("Exception while adding vehicle to database: %s", e.getMessage()));
    }
    }

    //Method to be called when updating a customer in the database
    //DO NOT MODIFY OR REMOVE
    private void updateCustomerInDatabase(Customer c)
    {
    ClerkDAO cdao = new ClerkDAO();
    Logger logger = Logger.getLogger("wheeliesvehicalrentalspackage.WV RSApplication");
    try{
    cdao.updateCustomerDetails(c);
    }

    catch(SQLException sqle)
    {
    logger.log(Level.SEVERE,String.format("SQL Exception while updating customer: %s", sqle.getMessage()));
    }
    catch(Exception e)
    {
    logger.log(Level.SEVERE,String.format("Exception while updating customer: %s", e.getMessage()));
    }
    }

    //Method to be called when adding a vehicle in the database
    //DO NOT MODIFY OR REMOVE
    private void updateVehicleInDatabase(Vehicle v)
    {
    ManagerDAO mdao = new ManagerDAO();
    Logger logger = Logger.getLogger("wheeliesvehicalrentalspackage.WV RSApplication");
    try{
    mdao.updateVehicleDetails(v);
    }
    catch(SQLException sqle)
    {
    logger.log(Level.SEVERE,String.format("SQL Exception while updating vehicle: %s", sqle.getMessage()));
    }
    catch(Exception e)
    {
    logger.log(Level.SEVERE,String.format("Exception while updating vehicle: %s", e.getMessage()));
    }
    }

    //Method that handles the adding of a customer
    //Note that this method must be written by the student
    public void addCustomer(String firstName, String lastName, String address, String dateOfBirth, String phone, String email)
    {
    //Perform Validation
    int errorVal = 0;
    String errorMessage = "";
    if(firstName.equals("") || firstName == null)
    {
    errorVal = errorVal+1;
    errorMessage+="You must enter the customer's first name \n";
    }
    if(lastName.equals("") || lastName == null)
    {
    errorVal = errorVal+1;
    errorMessage+="You must enter the customer's last name \n";
    }
    if(address.equals("") || address == null)
    {
    errorVal = errorVal+1;
    errorMessage+="You must enter the customer's address \n";
    }
    try{
    if(dateOfBirth.trim().equals("") || dateOfBirth.trim() == null)
    {
    throw new EmptyDateException("You must enter the customer's date of birth \n");
    //errorMessage+="You must enter the customer's date of birth \n";
    //errorVal = errorVal+1;
    }
    else
    {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    java.sql.Date sqlCustDOB = new java.sql.Date(formatter.parse(dateOfBirth).getTime ());
    if(!sqlCustDOB.toString().equals(dateOfBirth))
    {
    //errorMessage+="You must enter the customer's date of birth in the format yyyy-MM-dd \n";
    //errorVal = errorVal+1;
    throw new InvalidDateException("You must enter a Valid date in the format yyyy-MM-dd \n");
    }
    }

    if(errorVal !=0)
    {
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    else if(errorVal ==0)
    {

    //Convert dob to java.sql.Date
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    java.sql.Date customerDOB = new java.sql.Date(formatter.parse(dateOfBirth).getTime ());

    //Create customer object
    Customer c = new Customer(firstName, lastName, address, dateOfBirth, phone, email);

    //Add customer object to list
    customerList.add(c);

    //Pass the customer object to store in the database
    addCustomerToDatabase(c);

    //Show user confirmation message of adding customer successfully
    JOptionPane.showMessageDialog(null,"Customer has been registered successfully!");
    }

    }
    catch(EmptyDateException ide)
    {
    errorMessage+=ide.getMessage();
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    catch(InvalidDateException ide)
    {
    errorMessage+=ide.getMessage();
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    catch(IllegalArgumentException iae)
    {
    errorMessage+="You must enter the customer's date of birth in the format yyyy-MM-dd \n";
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    catch(java.text.ParseException pe)
    {
    errorMessage+="You must enter the customer's date of birth in the format yyyy-MM-dd \n";
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    }



    //Method that handles the viewing of a customer
    //Note that this method must be written by the student
    public Customer viewCustomer(int custID)
    {
    //Create empty Customer object
    Customer foundCustomer = new Customer();

    //Loop through list and look for customer matching id passed
    boolean found = false;
    for(int x=0; x<customerList.size(); x++)
    {
    Customer c = customerList.get(x);
    int customerID = c.getCustomerID();
    //Check to see if the two ids match
    if(custID == customerID)
    {
    foundCustomer = c;
    found = true;
    }
    }

    if(found == false)
    {
    JOptionPane.showMessageDialog(null,"No Customer Found!");
    }

    return foundCustomer;
    }




    //Method that handles the editing of a customer
    //Note that this method must be written by the student
    public void editCustomer(int custID, String firstName, String lastName, String address, String dateOfBirth, String phone, String email)
    {
    //Perform validation
    int errorVal = 0;
    String errorMessage = "";
    if(firstName.equals("") || firstName == null)
    {
    errorVal = errorVal+1;
    errorMessage+="You must enter the customer's first name \n";
    }
    if(lastName.equals("") || lastName == null)
    {
    errorVal = errorVal+1;
    errorMessage+="You must enter the customer's last name \n";
    }
    if(address.equals("") || address == null)
    {
    errorVal = errorVal+1;
    errorMessage+="You must enter the customer's address \n";
    }
    try{
    if(dateOfBirth.trim().equals("") || dateOfBirth.trim() == null)
    {
    //errorMessage+="You must enter the customer's date of birth \n";
    //errorVal = errorVal+1;
    throw new EmptyDateException("You must enter the customer's date of birth \n");
    }
    else
    {
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
    java.sql.Date sqlCustDOB = new java.sql.Date(formatter.parse(dateOfBirth).getTime ());
    if(!sqlCustDOB.toString().equals(dateOfBirth))
    {
    //errorMessage+="You must enter the customer's date of birth in the format yyyy-MM-dd \n";
    //errorVal = errorVal+1;
    throw new InvalidDateException("You must enter a Valid date in the format yyyy-MM-dd \n");
    }
    }

    if(errorVal !=0)
    {
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    else if(errorVal ==0)
    {
    //Convert dob to java.sql.Date
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
    java.sql.Date customerDOB = new java.sql.Date(formatter.parse(dateOfBirth).getTime ());

    //Loop through ArrayList to find the Customer object being edited
    for(int x=0; x<customerList.size(); x++)
    {
    Customer c = customerList.get(x);
    int customerID = c.getCustomerID();
    //Check to see if the two ids match
    if(custID == customerID)
    {
    //Edit customer fields of the oject in the ArrayList
    customerList.get(x).setFirstName(firstName);
    customerList.get(x).setLastName(lastName);
    customerList.get(x).setAddress(address);
    customerList.get(x).setDateOfBirth(customerDOB);
    }

    //Extract the edited customer object from the ArrayList
    Customer editedCustomer = customerList.get(x);

    //Pass customer object to update in the database
    updateCustomerDetails(editedCustomer);
    }

    //Show user confirmation message of adding customer successfully
    JOptionPane.showMessageDialog(null,"Customer has been updated successfully!");
    }

    }
    catch(EmptyDateException ide)
    {
    errorMessage+=ide.getMessage();
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    catch(InvalidDateException ide)
    {
    errorMessage+=ide.getMessage();
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    catch(IllegalArgumentException iae)
    {
    errorMessage+="You must enter the customer's date of birth in the format yyyy-MM-dd \n";
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    catch(java.text.ParseException pe)
    {
    errorMessage+="You must enter the customer's date of birth in the format yyyy-MM-dd \n";
    JOptionPane.showMessageDialog(null,errorMessage);
    }
    catch(Exception e)
    {
    System.out.println(e);
    }




    //Method that handles the adding of a vehicle
    //Note that this method must be coded by the student
    public void addVehicle(String regNo, String rentalPrice, String colour, String mpg, String transmission, String dateObtained, String avail, String model)
    {

    }


    //Method that handles the viewing of a vehicle
    //Note that this method must be written by the student
    public Vehicle viewVehicle(String regNo)
    {

    }


    //Method that handles the editing of a vehicle
    //Note that this method must be code by the student
    public void editVehicle(String regNo, String rentalPrice, String colour, String mpg, String transmission, String dateObtained, String avail, String model)
    {

    }

    private void updateCustomerDetails(Customer editedCustomer) {
    throw new UnsupportedOperationException("Not yet implemented");
    }


    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Need help with my code .... PLEASE HELP!!!!

    "Need help with my code", does not tell me much about what is wrong or what is not working the way you expected it to. What is your question or problem? Post the error message if you have one.
    Also please use [code=java] before your code and [/code] after your code.

Similar Threads

  1. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 03:13 PM
  2. code to refresh and check the code of a webpage..
    By vaggelis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2012, 07:43 AM
  3. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  4. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  5. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 30th, 2011, 12:03 AM