Я создал это приложение-калькулятор, чтобы оно могло рассчитать либо количество краски на стене, либо толщину бетонной плиты для моего класса APCSA. Однако, когда я попытался запустить его, я получаю это сообщение об ошибке.
ошибка: имена классов «MaterialsCalculatorApp.Java» принимаются только в том случае, если явно запрошена обработка аннотаций.
Может ли кто-нибудь понять, как это исправить?
Вот коды для справки (мы не изучали Javac в моем классе пока).
MaterialsCalculatorApp.Java
import java.util.Scanner;
public class MaterialsCalculatorApp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("===== Materials Calculator =====");
System.out.println("1. Paint Wall");
System.out.println("2. Concrete Slab");
System.out.print("Choose project type (1 or 2): ");
int choice = sc.nextInt();
MaterialProject project = null;
if (choice == 1) {
project = new PaintWallProject();
} else if (choice == 2) {
project = new ConcreteSlabProject();
} else {
System.out.println("Invalid choice.");
sc.close();
return;
}
project.collectInput(sc);
double materialNeeded = project.calculateMaterialNeeded();
System.out.println("\n----- RESULTS -----");
System.out.println("Project Type: " + project.getName());
System.out.printf("Material Needed: %.2f %s\n",
materialNeeded,
project.getUnit());
double cost = project.calculateEstimatedCost(materialNeeded);
System.out.printf("Estimated Cost: $%.2f\n", cost);
sc.close();
}
}
MaterialProject.java
import java.util.Scanner;
public abstract class MaterialProject {
private String name;
private String unitLabel;
private double costPerUnit;
public MaterialProject(String name, String unitLabel, double costPerUnit) {
this.name = name;
this.unitLabel = unitLabel;
this.costPerUnit = costPerUnit;
}
public String getName() {
return name;
}
public String getUnitLabel() {
return unitLabel;
}
public double getCostPerUnit() {
return costPerUnit;
}
public abstract void collectInput(Scanner sc);
public abstract double calculateMaterialNeeded();
public double calculateEstimatedCost(double amountNeeded) {
return amountNeeded * costPerUnit;
}
}
PaintWallProject.java
import java.util.Scanner;
public class PaintWallProject extends MaterialProject {
private double width;
private double height;
private int coats;
private static final double COVERAGE = 350.0; // sq ft per gallon
public PaintWallProject() {
super("Paint Wall", "gallons", 34.99);
}
@Override
public void collectInput(Scanner sc) {
System.out.print("Enter wall width (feet): ");
width = sc.nextDouble();
System.out.print("Enter wall height (feet): ");
height = sc.nextDouble();
System.out.print("Enter number of coats: ");
coats = sc.nextInt();
}
@Override
public double calculateMaterialNeeded() {
double area = width * height;
double totalArea = area * coats;
return totalArea / COVERAGE;
}
}
ConcreteSlabProject.java
import java.util.Scanner;
public class ConcreteSlabProject extends MaterialProject {
private double length;
private double width;
private double thicknessInches;
public ConcreteSlabProject() {
super("Concrete Slab", "cubic yards", 150.0);
}
@Override
public void collectInput(Scanner sc) {
System.out.print("Enter slab length (feet): ");
length = sc.nextDouble();
System.out.print("Enter slab width (feet): ");
width = sc.nextDouble();
System.out.print("Enter slab thickness (inches): ");
thicknessInches = sc.nextDouble();
}
@Override
public double calculateMaterialNeeded() {
double thicknessFeet = thicknessInches / 12.0;
double cubicFeet = length * width * thicknessFeet;
return cubicFeet / 27.0; // convert to cubic yards
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... citly-requ