我如何将用户输入项目(名称、成本、优先级)中的 3 个项目放入一个对象项中,并将该对象项放入一组其他对象中?
public class Main {
public static void main(String[] args) {
//here are my variables.
//I'm pretty sure a few of these should be defined
// in their own item class.
int i=0;
String name1;
int priority1;
double cost1;
//String[] shoppingList = new String[7];
String[] item = new String[7];
// I am able to grab input from the user for all 3 elements of
// an item object (name, cost, priority)
// I am missing how to save these 3 elements into an item object
// and create an array for each item object
for (i=0; i<item.length;i++) {
//I want to capture name, priority, and cost of each item
// and add each item as an in
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter item name " + i);
String name = keyboard.next();
Scanner keyboard2 = new Scanner(System.in);
System.out.println("Enter the price of item " + i);
double cost = keyboard2.nextDouble();
Scanner keyboard3 = new Scanner(System.in);
System.out.println("Enter Priority Number " + i);
int priority = keyboard3.nextInt();