Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

customer class n test class

 
Micheal Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the compiler is complaining about "Customer firstCustomer = new Customer();" its saying a ";" is expected. why is it saying this?


my customer class


/*
* Class.java
*
* 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)
{
name.equals(aName);
}
// sets customer address
public void setAddress(String anAddress)
{
address.equals(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

firstCustomer.setName("Joe");
firstCustomer.setDOB("4-07-85");
firstCustomer.setAddress("Berrylands");
firstCustomer.setTelephoneNumber("020-347");
firstCustomer.setVehicle("Ford");
firstCustomer.setAmount("50");
firstCustomer.setCharge("10");
firstCustomer.setDateOut("10-04-2005");
firstCustomer.setDateIn("10-05-2005");


// 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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not sure what u mean. please alloborate. cheers jody!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.
 
Micheal Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
^
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic