Results 1 to 4 of 4
- 04-15-2011, 03:02 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Code written but cannot get it to add the total inventory amount and needs sorted
Hi, I have written my code for my assignment and it compiles and runs, however, it doesn't display JUST the total of the inventory it displays all 5 totals again. I cannot figure out what I have done wrong, or could be I'm tired :eek:. Can someone please tell me what I am doing wrong? I also need to sort by product name but finally gave up on it and removed the code so I could at least get the total done.
public class Laptop { //class name and attributes
private String ItemNumber; //item # of product
private String ProductName; //product name
private double UnitsStock; //# of units in stock
private double UnitPrice; //Price per unit
private double InventoryValue; //The dollar value of the inventory in stock
private double CalculateInventory; //The total value of all of the inventory in stock
private double value;
//contructor
public Laptop(String item, String product, double units, double price) {
ItemNumber = item;
ProductName = product;
UnitsStock = units;
UnitPrice = price;
} //end constructor
//getter and setter methods for Laptop
public void setItemNumber (String item) { //setter for item number
this.ItemNumber = item;
} //end setter item number
public String getItemNumber() { //getter for item number
return ItemNumber;
} //end getter item number
public void setProductName (String product) { //setter for product name
this.ProductName = product;
} //end setter product name
public String getProductName() { //getter for product name
return ProductName;
} //end getter product name
public void setUnitsStock (double units) { //setter for units in stock
this.UnitsStock = units;
} //end setter units in stock
public double getUnitsStock() { //getter for units in stock
return UnitsStock;
} //end getter units in stock
public void setUnitPrice (double price) { //setter for unit price
this.UnitPrice = price;
} //end setter unit price
public double getUnitPrice() { //getter for unit price
return UnitPrice;
} //end getter for unit price
//calculate inventory value
public double getInventoryValue(){
return UnitsStock * UnitPrice;
}//end calculate inventory value
public void setCalculateInventory (double value){
this.CalculateInventory = value;
}
public double getCalculateInventory(){
double value = 0;
for(int i = 0; i < 5; i++){
value = getInventoryValue();
}
return value;
}
//end getter and setter methods for Laptop
} //end class Laptop
-----------
//begin main program
import java.util.*;
public class InventoryPart2 {
public static void main (String args []){
//instantiate Laptop array
Laptop myLaptops[] = new Laptop[5];
myLaptops[0] = new Laptop("0001", "Dell Inspiron 1545", 4, 549.99);
myLaptops[1] = new Laptop("0002", "IBM Thinkpad R400", 6, 580.00);
myLaptops[2] = new Laptop("0003", "HP Pavilion", 2, 679.99);
myLaptops[3] = new Laptop("0004", "Sony Vaio C Series", 8, 899.99);
myLaptops[4] = new Laptop("0005", "Apple MacBook Pro", 2, 1799.00);
//output
for (int i = 0; i < myLaptops.length; i++){
System.out.println("Product Number: \t\t" + myLaptops[i].getItemNumber());
System.out.println("Product Name: \t\t\t" + myLaptops[i].getProductName());
System.out.println("Number of Units in Stock: \t" + myLaptops[i].getUnitsStock());
System.out.printf("Price per Unit: \t\t$%.2f\n", + myLaptops[i].getUnitPrice());
System.out.printf("Value of Inventory: \t\t$%.2f\n", + myLaptops[i].getInventoryValue());
System.out.println();
} // end output
for (int i = 0; i < 5; i++){ //output total inventory value
System.out.printf("Total Value of Inventory is: \t$%.2f\n", + myLaptops[i].getCalculateInventory());
System.out.println();
}//end output total inventory value
} //end method main
} //end class InventoryPart1
- 04-15-2011, 03:07 AM #2
Please use code tags, indent, and delete your comments so we can easily read your code.
- 04-15-2011, 03:25 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Sorry about that
It was indented when I hit submit, oh well, I guess me posting is what it took for me to figure it out! I did it.
Thanks
- 04-15-2011, 04:50 AM #4
Yes indentation is deleted when you type plain words. If you use code tags like so: [ code ] code goes here [ /code ] (without the spaces between the brackets), all indentation will be restored.
Similar Threads
-
how do i read a clob data from a function written in oracle in java code
By renu in forum New To JavaReplies: 1Last Post: 03-29-2011, 08:59 AM -
Sharp decrease in program speed after adding small amount of code.
By Repsajo in forum New To JavaReplies: 0Last Post: 03-18-2011, 08:48 PM -
I need some java / html code written
By DeDanan in forum New To JavaReplies: 2Last Post: 03-01-2011, 09:36 AM -
i need help with my code.how can i eliminate duplicate number from my sorted list
By yinghang in forum New To JavaReplies: 6Last Post: 04-13-2009, 04:19 AM -
Help with Code! Display Array of Strings and Integers - Sorted
By luvjoynt in forum New To JavaReplies: 7Last Post: 04-28-2008, 04:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks