Results 1 to 10 of 10
Thread: Problem in Program
- 01-08-2010, 12:08 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
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
- 01-08-2010, 12:35 AM #2
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
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;
- 01-08-2010, 01:42 AM #3
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
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.
- 01-08-2010, 02:36 AM #4
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
Invetory total
I am not going to have time to do an array so how would I get total with code used
- 01-08-2010, 02:38 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
Sorry ,
I am having alot of trouble
- 01-08-2010, 02:53 AM #6
Java Code:System.out.println(one.getValueOfProduct() + two.getValueOfProduct() + three.getValueOfProduct() + four.getValueOfProduct() + five.getValueOfProduct() + six.getValueOfProduct());
- 01-08-2010, 03:04 AM #7
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
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.:)
- 01-08-2010, 03:06 AM #8
Alright cool. lemme know if it works
- 01-08-2010, 03:29 AM #9
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
Total Inventory
Hello,
Works Great!
Thanks
- 01-08-2010, 03:38 AM #10
Similar Threads
-
Problem with the below program
By srikanthnambu in forum Java 2DReplies: 1Last Post: 05-20-2009, 05:43 PM -
Gui program problem..
By mingming2009 in forum Advanced JavaReplies: 7Last Post: 04-03-2009, 05:15 AM -
Program problem
By arindamchkrbrty in forum New To JavaReplies: 8Last Post: 03-10-2009, 04:58 AM -
program problem
By amith in forum AWT / SwingReplies: 12Last Post: 05-16-2008, 08:07 PM -
Problem with my program HelloWorld
By trill in forum New To JavaReplies: 1Last Post: 08-05-2007, 05:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks