Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameterized Constructor Problem

Status
Not open for further replies.

WantABeeProgrammer

Programmer
Mar 17, 2004
2
US
I'm taking a java course and am have a problem with the parameterized constructor. I've copied and pasted my drive and PD. When, I try and create a new instance of the parameterized constructor I keep getting a compiler error (cannot find symbol) and it's pointing to

Order c = new Order( ect......);

If anyone can help me figure this out and maybe explain why I get this error it would extremely help. :)

Driver:
public class OrderDriver
{
public static void main( String args[] )
{
Order c2 = new Order( "PERIC", "Pericles Comidas", "Calle Dr. Jorge Cash 321",
"Mexico", "D.F.", 05033, "Mexico", 11073, "Andrew Fuller", "04-Jun-96", "02-Jul-96",
"", "United Package", 11, "Queso Cabrales", 10, 0.0 , 21.00 );
c2.displayResults();
} // end of main()
}// end of class OrderDriver()
PD:
public class Order
{
//Customer information
private String customerId;
private String name;
private String address;
private String city;
private String state;
private int zip;
private String country;

//Order information
private int orderId;
private String salesperson;
private String orderDate;
private String requiredDate;
private String shippingDate;
private String shippingVia;

//Product information
private int productId;
private String productName;
private int quantity;
private double discount;
private double unitPrice;

// Default constructor
public void order()
{
//Customer information
setCustomerId( "" );
setName( "" );
setAddress( "" );
setCity( "" );
setState( "" );
setZip( 0 );
setCountry( "" );

//Order information
setOrderId( 0 );
setSalesperson( "" );
setOrderDate( "" );
setRequiredDate( "" );
setShippingDate( "" );
setShippingVia( "" );

//Product information
setProductId( 0 );
setProductName( "" );
setQuantity( 0 );
setDiscount( 0.0 );
setUnitPrice( 0.0 );
}


//Parameterized constructor
public void Order(String customerId, String name, String address, String city, String state, int zip, String country,
int orderId, String salesperson, String orderDate, String requiredDate, String shippingDate,
String shippingVia, int productId, String productName, int quantity, double discount, double unitPrice)
{
//Customer information
setCustomerId( customerId );
setName( name );
setAddress( address );
setCity( city );
setState( state );
setZip( zip );
setCountry( country );

//Order information
setOrderId( orderId );
setSalesperson( salesperson );
setOrderDate( orderDate );
setRequiredDate( requiredDate );
setShippingDate( shippingDate );
setShippingVia( shippingVia );

//Product information
setProductId( productId );
setProductName( productName );
setQuantity( quantity );
setDiscount( discount );
setUnitPrice( unitPrice );
}

///////////////////////////////
// Set Methods to all variables
///////////////////////////////
//Customer information
public void setCustomerId( String set )
{ customerId = set; }
public void setName( String set )
{ name = set; }
public void setAddress( String set )
{ address = set; }
public void setCity( String set )
{ city = set; }
public void setState( String set )
{ state = set; }
public void setZip( int set )
{ zip = set; }
public void setCountry( String set )
{ country = set; }

//Order information
public void setOrderId( int set )
{ orderId = set; }
public void setSalesperson( String set )
{ salesperson = set; }
public void setOrderDate( String set )
{ orderDate = set; }
public void setRequiredDate( String set )
{ requiredDate = set; }
public void setShippingDate( String set )
{ shippingDate = set; }
public void setShippingVia( String set )
{ shippingVia = set; }

//Product information
public void setProductId( int set )
{ productId = set; }
public void setProductName( String set )
{ productName = set; }
public void setQuantity( int set )
{ quantity = set; }
public void setDiscount( double set )
{ discount = set; }
public void setUnitPrice( double set )
{ unitPrice = set; }

///////////////////////////////
// Get Methods to all variables
///////////////////////////////
//Customer information
public String getCustomerId()
{ return customerId; }
public String getName()
{ return name; }
public String getAddress()
{ return address; }
public String getCity()
{ return city; }
public String getState()
{ return state; }
public int getZip()
{ return zip; }
public String getCountry()
{ return country; }

//Order information
public int getOrderId()
{ return orderId; }
public String getSalesperson()
{ return salesperson; }
public String getOrderDate()
{ return orderDate; }
public String getRequiredDate()
{ return requiredDate; }
public String getShippingDate()
{ return shippingDate; }
public String getShippingVia()
{ return shippingVia; }

//Product information
public int getProductId()
{ return productId; }
public String getProductName()
{ return productName; }
public int getQuantity()
{ return quantity; }
public double getDiscount()
{ return discount; }
public double getUnitPrice()
{ return unitPrice; }

///////////////////////////////
// Methods or Functions
///////////////////////////////

public double lineItemTotal()
{ return (unitPrice*quantity) - (discount * (unitPrice*quantity)); }

public void displayResults() {
System.out.println("..::Customer information::..\r");
System.out.println("Customer Id:\t\t" + getCustomerId() + "\r");
System.out.println("Customer Name:\t\t" + getName() + "\r");
System.out.println("Customer Address:\t" + getAddress() + "\r");
System.out.println("Customer City:\t\t" + getCity() + "\r");
System.out.println("Customer State:\t\t" + getState() + "\r");
System.out.println("Customer Zip:\t\t" + getZip() + "\r");
System.out.println("Customer Country:\t" + getCountry() + "\r\n");
System.out.println("..::Order information::..\r");
System.out.println("Order Id:\t\t" + getOrderId() + "\r");
System.out.println("Order Salesperson:\t" + getSalesperson() + "\r");
System.out.println("Order OrderDate:\t" + getOrderDate() + "\r");
System.out.println("Order RequiredDate:\t" + getRequiredDate() + "\r");
System.out.println("Order ShippingDate:\t" + getShippingDate() + "\r");
System.out.println("Order ShippingVia:\t" + getShippingVia() + "\r\n");
System.out.println("..::product information::..\r");
System.out.println("Product Id:\t\t" + getProductId() + "\r");
System.out.println("Product ProductName:\t" + getProductName() + "\r");
System.out.println("Product Quantity:\t" + getQuantity() + "\r");
System.out.println("Product Discount:\t" + getDiscount() + "\r");
System.out.println("Product UnitPrice:\t" + getUnitPrice() + "\r\n");
System.out.println("Line item Total:\t" + lineItemTotal() + "\r");
}
}
 
Try removing the "void" thingie from the constructor declaration.


public class A {

public A() {whatever;}
}

Cheers.

Dian
 
On a constructor you do should not specify a return type

So instead of
Code:
    public [b]void[/b] Order(String customerId, String name, String address, ...
use
Code:
    public Order(String customerId, String name, String address, ...
 
... and if your classname is 'Order' (how it should be) your constructor needs to be 'Order' too, not 'order'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top