File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes customer class n test class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "customer class n test class" Watch "customer class n test class" New topic

customer class n test class

Micheal Lee

Joined: Nov 13, 2005
Posts: 3
the compiler is complaining about "Customer firstCustomer = new Customer();" its saying a ";" is expected. why is it saying this?

my customer class

* Created on 08 November 2005, 16:08

* @author K0403889

// a class named customer
public class Customer{

/** declaring the variables */

private String name;
private String address;
private String vehicle;
private int DateOut;
private int DateIn;
private double amount;
private double charge;
private double TotalAmount;
private int CustomerCount;
private static final double BASE_CHARGE = 10;
private int DOB;
private int TelephoneNumber;

/** Creates a new instance of Class */
public Customer() {

/** Gets the current name of the customer
public String getName()
return name;
/** Gets the current address of the customer
public String getAddress()
return address;
/** Gets the current vehicle of the customer*/

public String getVehicle()
return vehicle;
/** Gets the current DateOut of the customer*/
public int getDateOut()
return DateOut;
/** Gets the current DateIn of the customer*/
public int getDateIn()
return DateIn;
/** Gets the current customer amount*/
public double getAmount()
return amount;
/** Gets the current customer charge*/
public double getCharge()
return charge;
/** gets the TotalAmount*/
public double getTotalAmount()
return TotalAmount;
/** gets the number of customers*/
public int getCustomerCount()
return CustomerCount;
/** gets the telephone number of the customer*/
public int getTelephoneNumber()
return TelephoneNumber;
/** get the DOB of the customer*/

public int DOB()
return DOB;

// adds a customer

public void addCustomer()

// subtracts a customer
public void delCustomer()

// sets a customer name
public void setName(String aName)
// sets customer address
public void setAddress(String anAddress)

// sets the vehicle to a customer

public void setVechile(String aVehicle)
vehicle = aVehicle;
// sets the amount
public void setAmount(double anAmount)
amount = anAmount;

// a setCharge for the customer

public void setCharge(int numberOfdaysOverdue)
charge = BASE_CHARGE + numberOfdaysOverdue;

//sets the date the vechile was issued to customer

public void setDateOut(int aDate)
DateOut = aDate;

// sets the date the vehicle was returned from customer
public void setDateIn(int aDate)
DateIn = aDate;


my test class for the customer

// tests the methods in the customer class
public class CustomerTest
public static void main(String[] args )
// create instance
Customer firstCustomer = new Customer();

// invoke set accesors to populate attributes


// define variables to contain attribute values retrieved
String customerName, String customerAddress, int customerTelephoneNumber, String customerVechicle, double customerAmount, double customerCharge, int customerDateOut, int customerDateIn, int customerDOB;

//invoke get accessors to retrive attribute values
customerName = firstCustomer.getName();
customerAddress = firstCustomer.getAddress();
customerTelephoneNumber = firstCustomer.getTelephoneNumber();
customerVechicle = firstCustomer.getVechicle();
customerAmount = firstCustomer.getAmount();
customerCharge = firstCustomer.getCharge();
customerDateOut = firstCustomer.getDateOut();
customerDateIn = firstCustomer.getDateIn();
customerDOB = firstCustomer.getDOB();

// display the retrived attribute values
System.out.println("The name is " + customerName);
System.out.println("The address is" + customerAddress);
System.out.println("The telephone number is" + customerTelephoneNumber);
System.out.println("The vechile is" + customerVechicle);
System.out.println("The amount is" + customerAmount);
System.out.println("The date out is" + customerDateOut);
System.out.println("The date in is" + customerDateIn);
System.out.println("The dob is" + customerDOB);
System.out.println("The charge is" + customerCharge);
}Customer firstCustomer = new Customer();
Jody Brown
Ranch Hand

Joined: Nov 09, 2005
Posts: 43
The line you have pointed to is outside of any method. The two curly brackets immediately before the line in question closes the main method and the class definition. The line is effectively orphaned.
Micheal Lee

Joined: Nov 13, 2005
Posts: 3
not sure what u mean. please alloborate. cheers jody!
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24166


Welcome to JavaRanch!

It is outside of any method, but what's more relevant here is that it's entirely outside the body of the class. This line would actually be OK inside the class, but outside any method; it would then be a m ember variable declaration.

But given that it's a copy of a line from main(), I think the one in main() is what you want; that one at the end is not only wrong but unnecessary.

[Jess in Action][AskingGoodQuestions]
Micheal Lee

Joined: Nov 13, 2005
Posts: 3
when i delete the brackets from the Customer firstCustomer = new Customer line 2 errors occur. one of the errors is that'(' or '[' expected in the Customer firstCustomer = new Customer line. the other error is that ";" is expected in the line below:

String customerName, String customerAddress, int customerTelephoneNumber, String customerVechicle, double customerAmount, double customerCharge, int customerDateOut, int customerDateIn, int customerDOB;
I agree. Here's the link:
subject: customer class n test class
Similar Threads
Mockup for SCJD
Help with servlets
problem in connecting floggy using j2me
Error - not a statement