||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ID: 441929 • Letter: #
Question
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Tester that needs to be changed
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public class InventoryTracker {
public static void main(String[] args) {
//create 7 new books/games
InventoryItem[] inventory = new InventoryItem[7];
inventory[0] = new ComicBook(2, 100., "Superman", 2);
inventory[1] = new BoardGame(3, 39.95, "AwfulGreenThings from Outer Space");
inventory[2] = new BoardGame(10, 29.95, "Monopoly");
inventory[3] = new ComicBook(10, 9.95, "Buffy the Vampire Slayer", 12);
inventory[4] = new ComicBook(12, 8.95, "X-men", 119);
inventory[5] = new BoardGame(9, 59.99, "Scrabble");
inventory[6] = new ComicBook(8, 21.98, "The Amazing Spiderman: Original Series,", 20);
for(int i = 0; i<inventory.length; i++) {
System.out.println(inventory[i]);
}
//calculations
InventoryItem maxvalue = inventory[0];
InventoryItem minvalue = inventory[0];
int inventoryQty = 0;
double inventoryValue = 0;
for(int i=0; i<inventory.length; i++)
{
inventoryQty += inventory[i].getQuantity();
double currentValue = inventory[i].getQuantity() * inventory[i].getRetailPrice();
if(currentValue < minvalue.getQuantity() * minvalue.getRetailPrice())
minvalue = inventory[i];
if(currentValue > maxvalue.getQuantity() * maxvalue.getRetailPrice())
maxvalue = inventory[i];
inventoryValue += currentValue;
}
//print results
System.out.println(" Total Inventory Quantity (num items):" + inventoryQty);
System.out.println("Total Inventory Value:" + inventoryValue);
System.out.println("Inventory Item with Max Value of " + (maxvalue.getQuantity() *maxvalue.getRetailPrice()) + " is: " + maxvalue);
System.out.println("Inventory Item with Min Value of " + (minvalue.getQuantity() *minvalue.getRetailPrice()) + " is: " + minvalue);
}
}
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Explanation / Answer
import java.util.Scanner; public class InventoryTracker { public static void main(String[] args) { // prompting user for array size Scanner keyboard = new Scanner(System.in); System.out.print( "How large do you want the array? " ); int[] inventory = new int[keyboard.nextInt()]; //prompting user for input for( int i=0 ; i maxvalue.getQuantity() * maxvalue.getRetailPrice()) maxvalue = inventory[i]; inventoryValue += currentValue; } //print results System.out.println(" Total Inventory Quantity (num items):" + inventoryQty); System.out.println("Total Inventory Value:" + inventoryValue); System.out.println("Inventory Item with Max Value of " + (maxvalue.getQuantity() *maxvalue.getRetailPrice()) + " is: " + maxvalue); System.out.println("Inventory Item with Min Value of " + (minvalue.getQuantity() *minvalue.getRetailPrice()) + " is: " + minvalue); } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.