I built this calculator app so that it can calculate either the amount of paint to wall or the amount of thickness on a concrete slab for my APCSA class. when i tried to run it, however, I get this error message:" error: Class names, 'MaterialsCalculatorApp.Java', are only accepted if annotation processing is explicitly requested." Can anyone figure out how to fix this? Here are the codes for reference. (And no. we did not learn Javac in my class yet)
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
}
}