Results 1 to 10 of 10
  1. #1
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default Problem in Program

    HELLO,

    i HAVE AN ASSIGHNMENT THAT HAS ME PUZZLED > I CAN GET TOTALS ON INVENTORY ITEMS SEPERATLY , BUT CANT GET GRAND TOTAL I AM HONEST WITH MY TEACHEER MRS. FERIBEE AT AXIA AND SHE TOLD ME I COULD LEARN A GREAT DEAL FROM FORUMS SO HERE I AM. THIS WAS SUPPOSED TO BE DONE IN ARRAYS BUT i HAD TWO MANY ERRORs SO i WILL USE THIS ONE. How do I get total inventory. I have another programI done in arrays I am trying to finish.


    public class Inventory{

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    class Product {

    private int itemNumber;
    private String name;
    private int unitsInStock;
    private double unitPrice;

    public Product(int itemNumber, String name, int unitsInStock,
    double unitPrice) {
    this.itemNumber = itemNumber;
    this.name = name;
    this.unitsInStock = unitsInStock;
    this.unitPrice = unitPrice;
    }

    public double getValueOfProduct() {
    return unitsInStock * unitPrice;
    }


    public String toString() {
    String itemStr = "Item: " + String.format("%-3s | ", itemNumber);
    String titleStr = "Name: " + String.format("%-10s | ", name);
    String unitsStr = "Units: " + String.format("%4d | ", unitsInStock);
    String costStr = "Unit: " + String.format("$ %6.2f | ", unitPrice);
    String valueStr = "Value: "
    + String.format("$ %8.2f", getValueOfProduct());

    return itemStr + titleStr + unitsStr + costStr + valueStr;
    }

    }

    {

    {

    Product one = new Product(1, "Polaris90", 2, 1000.00);
    Product two = new Product(2, "Polaris125", 3, 1250.50);
    Product three = new Product(3, "POLARIS250", 1, 2999.00);
    Product four = new Product(4, "YAMAHA90", 2, 1199.99);
    Product five = new Product(5, "Yamaha110", 5, 1299.00);
    Product six = new Product(6, "Suzuki50", 7, 812.50);



    System.out.println(one);
    System.out.println(two);
    System.out.println(three);
    System.out.println(four);
    System.out.println(five);
    System.out.println(six);


    }

    }
    }

    }
    THIS IS MY PRINT OUT BUT NEED TOTAL
    Item: 1 | Name: Polaris90 | Units: 2 | Unit: $ 1000.00 | Value: $ 2000.00
    Item: 2 | Name: Polaris125 | Units: 3 | Unit: $ 1250.50 | Value: $ 3751.50
    Item: 3 | Name: POLARIS250 | Units: 1 | Unit: $ 2999.00 | Value: $ 2999.00
    Item: 4 | Name: YAMAHA90 | Units: 2 | Unit: $ 1199.99 | Value: $ 2399.98
    Item: 5 | Name: Yamaha110 | Units: 5 | Unit: $ 1299.00 | Value: $ 6495.00
    Item: 6 | Name: Suzuki50 | Units: 7 | Unit: $ 812.50 | Value: $ 5687.50

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    Just use an array by putting each value into the array. and later summing everything up.

    array of size 6.
    int sum=0;
    Put the value of each item in the array.
    then
    for(i=0;i<5;i++)
    {sum+= array[i];}
    return sum;

  3. #3
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Sorry, I don't help yelling people. Besides, you should use code tags. :)
    I die a little on the inside...
    Every time I get shot.

  4. #4
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default Invetory total

    I am not going to have time to do an array so how would I get total with code used

  5. #5
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default

    Sorry ,
    I am having alot of trouble

  6. #6
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Java Code:
    System.out.println(one.getValueOfProduct() + two.getValueOfProduct()
         + three.getValueOfProduct() + four.getValueOfProduct() + five.getValueOfProduct()
         + six.getValueOfProduct());

  7. #7
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Smile Total inventory

    Hello,

    Thank you for your time and even though i didn't use tags . I will try to do better in the future. I will try tyhis and get back.:)

  8. #8
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Alright cool. lemme know if it works

  9. #9
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Talking Total Inventory

    Hello,

    Works Great!

    Thanks

  10. #10
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Can you mark this thread as SOLVED?

    To do so, do the following:
    1. Find "Post Reply" button on the top of this thread.
    2. Look exactly right of it until you see "Thread Tools." (between LinkBack and Thread Tools)
    3. Click on "Thread Tools" and on the drop down menu, click on "Mark as solved."

Similar Threads

  1. Problem with the below program
    By srikanthnambu in forum Java 2D
    Replies: 1
    Last Post: 05-20-2009, 05:43 PM
  2. Gui program problem..
    By mingming2009 in forum Advanced Java
    Replies: 7
    Last Post: 04-03-2009, 05:15 AM
  3. Program problem
    By arindamchkrbrty in forum New To Java
    Replies: 8
    Last Post: 03-10-2009, 04:58 AM
  4. program problem
    By amith in forum AWT / Swing
    Replies: 12
    Last Post: 05-16-2008, 08:07 PM
  5. Problem with my program HelloWorld
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 05:32 PM

Posting Permissions

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