aspose file tools*
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
Author

customer class n test class

Micheal Lee
Greenhorn

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


/*
* 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

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
Greenhorn

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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Micheal Lee
Greenhorn

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;
^
 
Consider Paul's rocket mass heater.
 
subject: customer class n test class