***\\\\I have been trying to run this but I think there is
something wrong with the variables not being saved properly. I
really appreciate some help.
***
class Main {
public static void main(String[] args) {
final int NUM_ITEMS = 2;
ItemToPurchase[] itemList = new ItemToPurchase[NUM_ITEMS];
clearScreen();
promptItem(itemList);
total(itemList);
}
public static void promptItem(ItemToPurchase[] itemList)
{
Scanner scnr = new Scanner(System.in);
String tempItem;
int tempPrice;
int tempQuantity;
int count;
//-----Print prompts by number of items------//
for(count = 0; count < itemList.length; ++count)
{
System.out.println("Item " + (count + 1));
System.out.println("What is the item called?");
tempItem = scnr.next();
itemList[count].setName(tempItem);
System.out.println("How much does the item cost?\n$");
tempPrice = scnr.nextInt();
itemList[count].setPrice(tempPrice);
System.out.println("How many are you buying?");
tempQuantity = scnr.nextInt();
itemList[count].setQuantity(tempQuantity);
System.out.println("\n");
scnr.close();
}
}
ItemToPurchase.java
class ItemToPurchase {
private String tempItem;
private int tempPrice;
private int tempQuantity;
public ItemToPurchase() {
this.tempItem = " ";
this.tempPrice = 0;
this.tempQuantity=0;
}
public void setName(String tempItem) { this.tempItem = tempItem; }
public void setPrice(int tempPrice) { this.tempPrice = tempPrice; }
public void setQuantity(int tempQuantity) { this.tempQuantity = tempQuantity; }
}
Main.java
import java.util.*;
class Main {
public static void main(String[] args) {
final int NUM_ITEMS = 2;
ItemToPurchase[] itemList = new ItemToPurchase[NUM_ITEMS];
itemList[0]=new ItemToPurchase();
itemList[1]=new ItemToPurchase();
promptItem(itemList);
}
public static void promptItem(ItemToPurchase[] itemList)
{
Scanner scnr = new Scanner(System.in);
String tempItem;
int tempPrice;
int tempQuantity;
int count;
//-----Print prompts by number of items------//
for(count = 0; count < itemList.length; ++count)
{
System.out.println("Item " + (count + 1));
System.out.println("What is the item called?");
tempItem = scnr.next();
itemList[count].setName(tempItem);
System.out.println("How much does the item cost?\n$");
tempPrice = scnr.nextInt();
itemList[count].setPrice(tempPrice);
System.out.println("How many are you buying?");
tempQuantity = scnr.nextInt();
itemList[count].setQuantity(tempQuantity);
System.out.println("\n");
}
scnr.close();
}
}

if you like the answer please provide a thumbs up.
***\\\\I have been trying to run this but I think there is something wrong with the...
I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public class ItemToPurchase { // instance variables private String itemName; private String itemDescription; private int itemPrice; private int itemQuantity; // default constructor public ItemToPurchase() { this.itemName = "none"; this.itemDescription = "none"; this.itemPrice = 0; this.itemQuantity = 0; } public ItemToPurchase(String itemName, int itemPrice, int itemQuantity,String itemDescription) { ...
CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign is Teenager with false. 1 import java.util.Scanner; 3 public class TeenagerDetector 1 public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; D}]oll kidage = scnr.nextInt(); /* Your solution goes here */ Go USB if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 20 Run Feedback? CHALLENGE ACTIVITY 3.11.2: Boolean in branching statements. Write...
import java.util.Scanner;public class Inventory { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); InventoryNode headNode; InventoryNode currNode; InventoryNode lastNode; String item; int numberOfItems; int i; // Front of nodes list ...
Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method getInput , which asks the user how many words there are, stores them in an array, and returns this array. printBackwards then takes this array of words, and prints it in reverse. Code Example: import java.util.Scanner; public class L17Num1{ public static void main(String[] args) { String[] sArray=getInput(); printBackwards(sArray); } public static String[] getInput() { System.out.println("How many...
Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for sample program: 3.5 import java.util.Scanner; public class HourToMinConv { public static void outputMinutesAsHours(double origMinutes) { /* Your solution goes here */ } public static void main (String [] args) { Scanner scnr = new Scanner(System.in); double minutes; minutes = scnr.nextDouble(); outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0. System.out.println(""); } } 2....
import java.util.Scanner;public class ShoppingList { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); ItemNode headNode; // Create intNode objects ItemNode currNode; ItemNode lastNode; String item; int i; // Front of nodes list ...
CHALLENGE ACTIVITY 3.5.1: Detect specific values. Write an expression that prints "Special number if specialNum is-99, 0, or 44. 1 import java.util.Scanner; 3 public class Find SpecialValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int specialNum; specialNum - scnr.nextInt(); POSLOVOU if (/* Your solution goes here */) { System.out.println("Special number"); else { System.out.println("Not special number"); Run View your last submission
1. Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8. What i am given: import java.util.Scanner; public class SumOfExcess { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int NUM_VALS =...
*This needs comments for each line of code. Thanks in advance!* import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int numCount = scnr.nextInt(); int[] Array = new int[numCount]; for(int i = 0; i < numCount; ++i) { Array[i] = scnr.nextInt(); } int jasc = Array[0], gws = Array[1], numbers, tempo; if (jasc > gws) { tempo = jasc; jasc...
Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }