Groceryshop, trying to make interactive... need help with porting

I’m new to java, I’m in AP CS right now and I’m just fiddling around and I’ve been using this code over the first 5 lessons so I could review on it, and I swapped it over to Java(Main) on codeHS, I have this one error and IDK how to fix… My code is below, please help.

MyProgram.java:3: error: ‘{’ expected
public class GroceryShop.java
^
1 error

import java.util.Scanner;

public class GroceryShop.java 
{
    public static void main(String[] args)  
    {
        Scanner input = new Scanner(System.in);
        //Edit numApples quantity to estimate the cost for number of bags.
       int numApples = 12;
       double taxValue = 1.06;
       double costApples = 2.34;
       System.out.println("How many bags do you have?");
       int numBags = input.nextInt();
       
       System.out.println("You have this many apples in a bag: " + numApples);
       System.out.print("The cost is " + costApples);
       System.out.println(" dollars for one bag.");
       
       numBags*=numApples/12;
              
       double totalCost=costApples*numBags*taxValue;
       System.out.println("Your total cost is: " + totalCost);
    }
}

It looks like
public class GroceryShop.java should be public class GroceryShop.

The biggest clue to this is where the compiler said your error occurred (line 3). Which means it’s very likely either in line 3 or in the code preceding it.

You can check out some basic samples of java programs here: Java Coding Samples
to give you a sense of the syntax and style.

2 Likes