Results 1 to 4 of 4

Thread: Help with java programming problem

  1. #1
    Join Date
    May 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with java programming problem

    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.

  2. #2
    Join Date
    May 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks

    I figured it out. Guess I just needed a break away from it to find the problem.

  3. #3
    Join Date
    Dec 2007
    Location
    Laguna, CA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    How did you fix this? I think I'm in the same class and having pretty much the same problems....

  4. #4
    Join Date
    Dec 2007
    Location
    Laguna, CA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well never mind. I just sucked it up and bought the solution at http://www.studentoffortune.com/ques...Program-Part-2 cuz I couldn't wait any longer

    Man I hate this class. I just dont get java at all haha

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •