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");
}
}
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.