snowowls
05-05-2007, 07:37 PM
We have to create a Product class and then create and Inventory Test 1 to test the product class.
I am showing no errors in Product class or Inventory Test. When I put in "java InventoryTest1"; it shows name=null; number =0.0, etc.etc.
What I need to know is what I have done or need to change so that name doesn't say null , or is it supposed to?
Here is what I have:
/* File :Inventory1.java
Assignment:Inventory Program Part 1
Name : Doris Chase
Date : 05/04/07
*/
import java.util.Scanner; //required for keyboard input
public class Inventory1
{
public static void main (String args [] )
{
Scanner input = new Scanner (System.in );
Product p = new Product ( );
System.out.printf (p.toString () );
and Product class
/* File : Product.java
Assignment: Inventory Program Part 1
Name : Doris Chase
Date : 05/04/07
*/
public class Product
{
private String name; //the product name.
private double number; //the item number
private double units; //number of available units.
private double price; //the price of each unit.
private double value; //the value of total units
public Product ( ) //Default constructor
{
} //End default constructor.
public Product ( String nameIn, double numberIn, double unitsIn, double priceIn, double valueIn ) //Initialization constructor
{
setName (nameIn);
setNumber (numberIn);
setUnits (unitsIn);
setPrice (priceIn);
setValue (valueIn);
}
public void setName (String nameInput)
{
name = nameInput;
}
public void setNumber (double numberInput)
{
number = numberInput;
}
public void setUnits (double unitsInput)
{
units = unitsInput;
}
public void setPrice (double priceInput)
{
price = priceInput;
}
public void setValue (double valueInput)
{
value = valueInput;
}
public String getName ( )
{
return (name);
} //End method getName
public double getNumber ( )
{
return (numbe)r;
} //End method getNumber
public double getUnits ( )
{
return (units) ; //End method getUnits
}
public double getPrice ( )
{
return (price);
} //End method getPrice
public double getstockValue ( )
{
return (units * price);
} //End method stockValue
public String toString ( ) //Returns a formatted String for output purposes //toString () Method
{
String formatString = "itemName : %s\n";
formatString += "itemNumber : %d\n";
formatString += "totalUnits : %d\n";
formatString += "unitPrice : $%.2f\n";
formatString += "stockValue : $%.2f\n/n";
return String.format ( name(),number(), units(),price(),value() );
} //End toString()
} //End Product
Thanks for any advice.
I am showing no errors in Product class or Inventory Test. When I put in "java InventoryTest1"; it shows name=null; number =0.0, etc.etc.
What I need to know is what I have done or need to change so that name doesn't say null , or is it supposed to?
Here is what I have:
/* File :Inventory1.java
Assignment:Inventory Program Part 1
Name : Doris Chase
Date : 05/04/07
*/
import java.util.Scanner; //required for keyboard input
public class Inventory1
{
public static void main (String args [] )
{
Scanner input = new Scanner (System.in );
Product p = new Product ( );
System.out.printf (p.toString () );
and Product class
/* File : Product.java
Assignment: Inventory Program Part 1
Name : Doris Chase
Date : 05/04/07
*/
public class Product
{
private String name; //the product name.
private double number; //the item number
private double units; //number of available units.
private double price; //the price of each unit.
private double value; //the value of total units
public Product ( ) //Default constructor
{
} //End default constructor.
public Product ( String nameIn, double numberIn, double unitsIn, double priceIn, double valueIn ) //Initialization constructor
{
setName (nameIn);
setNumber (numberIn);
setUnits (unitsIn);
setPrice (priceIn);
setValue (valueIn);
}
public void setName (String nameInput)
{
name = nameInput;
}
public void setNumber (double numberInput)
{
number = numberInput;
}
public void setUnits (double unitsInput)
{
units = unitsInput;
}
public void setPrice (double priceInput)
{
price = priceInput;
}
public void setValue (double valueInput)
{
value = valueInput;
}
public String getName ( )
{
return (name);
} //End method getName
public double getNumber ( )
{
return (numbe)r;
} //End method getNumber
public double getUnits ( )
{
return (units) ; //End method getUnits
}
public double getPrice ( )
{
return (price);
} //End method getPrice
public double getstockValue ( )
{
return (units * price);
} //End method stockValue
public String toString ( ) //Returns a formatted String for output purposes //toString () Method
{
String formatString = "itemName : %s\n";
formatString += "itemNumber : %d\n";
formatString += "totalUnits : %d\n";
formatString += "unitPrice : $%.2f\n";
formatString += "stockValue : $%.2f\n/n";
return String.format ( name(),number(), units(),price(),value() );
} //End toString()
} //End Product
Thanks for any advice.