ShoppingCartPrinter.java:29: ошибка: достигнут конец файла при анализе
}
^
1 ошибка
Я просмотрел свой код и не вижу, где я пропустил фигурные скобки.
Вот подробности лабораторной работы.
Создайте программу, используя классы, которые выполняют следующие действия в Разработчик zyLabs ниже. В ходе этой лабораторной работы вы будете работать с двумя разными файлами классов. Чтобы переключить файлы, найдите место, где написано «Текущий файл» в верхней части окна разработчика. Щелкните имя текущего файла, затем выберите нужный файл.
(1) Создайте два файла для отправки:
ItemToPurchase.java — определение класса
ShoppingCartPrinter.java — содержит метод main()
Создайте класс ItemToPurchase со следующими спецификациями:
Частные поля
- String itemName — инициализируется в конструкторе по умолчанию значением «none»
- int itemPrice — инициализируется в конструкторе по умолчанию значением 0
- int itemQuantity — инициализируется в конструкторе по умолчанию значением 0
Открытые методы-члены (мутаторы и методы доступа)
- setName() и getName() (2 баллов)
- setPrice() и getPrice() (2 балла)
- setQuantity() и getQuantity() (2 балла)
Пример:
Товар 1
Введите название товара: Шоколадные чипсы
Введите цену товара: 3
Введите количество товара: 1
Товар 2
Введите название товара: Бутилированная вода
Введите цену товара: 1
Введите количество товара: 10
(3) Сложите затраты двух товаров и выведите общую стоимость. (2 балла)
Пример:
ОБЩАЯ СТОИМОСТЬ
Шоколадные чипсы 1 @ 3 $ = 3 $
Вода в бутылках 10 @ 1 $ = 10 $
Итого: 13 $
Вот мой код:
ShoppingCartPrinter
import java.until.Scanner;
public class ShoppingCartPrinter{
//main method
public static void main(String[] args){
//create object of scanner
Scanner scnr = new Scanner(System.in);
//variable declaration
int i = 0;
String productName;
int productPrice = 0;
int productQuantity = 0;
int cartTotal = 0;
ItemToPurchase item1 = new ItemToPurchase();
ItemToPurchase item2 = new ItemToPurchase();
//get item 1 details
System.out.println("Item 1");
System.out.println("Enter the item name: ");
productName = scnr.nextLine();
item1.setName(productName);
System.out.println("Enter the item price: ");
productPrice = scnr.nextInt();
item1.setPrice(productPrice);
scnr.nextLine();
System.out.println("Enter the item quantity: ");
productQuantity = scnr.nextInt();
item1.setQuantity(productQuantity);
scnr.nextLine();
scnr.nextLine();
System.out.println("");
//get item 2 details
System.out.println("Item 2");
System.out.println("Enter the item name: ");
productName = scnr.nextLine();
item2.setName(productName);
System.out.println("Enter the item price: ");
productPrice = scnr.nextInt();
item2.setPrice(productPrice);
scnr.nextLine();
System.out.println("Enter the item quantity: ");
productQuantity = scnr.nextInt();
item2.setQuantity(productQuantity);
scnr.nextLine();
System.out.println("");
//add cost of item 1 and 2 and print total
cartTotal = (item1.getQuantity() * item1.getPrice()) + (item2.getQuantity() * item2.getPrice());
System.out.println("TOTAL COST");
//cart total is item 1 price * quantity + item 2 price * quantity
//item 1 info
int item1Total = item1.getPrice() * item1.getQuantity();
System.out.println(item1.getName() + " " + item1.getQuantity() + " @ $" + item1.getPrice() + " = $" + item1Total);
//item 2 info
int item2Total = item2.getPrice() * item2.getQuantity();
System.out.println(item2.getName() + " " + item2.getQuantity() + " @ $" + item2.getPrice() + " = $" + item2Total);
//output total
System.out.println("");
System.out.print("Total: $" + cartTotal);
}
}
Предметы для покупки
public class ItemToPurchase {
//Private fields - itemName, itemPrice, and itemQuanity
private String itemName;
private int itemPrice;
private int itemQuantity;
//Default Constructor
public ItemToPurchase(){
itemName = "none";
itemPrice = 0;
itemQuantity = 0;
}
//public member methods
public void setName(String itemName){
this.itemName = itemName;
}
public String getName(){
return itemName;
}
public void setPrice(int itemPrice){
this.itemPrice = itemPrice;
}
public int getPrice(){
return itemPrice;
}
public void setQuantity(int itemQuantity){
this.itemQuantity = itemQuantity;
}
public int getQuantity(){
return itemQuantity;
}
public void printItemPurchase() {
System.out.println(itemQuantity + " " + itemName + " $" + itemPrice +
" = $" + (itemPrice * itemQuantity));
}
}
Подробнее здесь: https://stackoverflow.com/questions/771 ... or-in-java
Мобильная версия