#Main.java:2: error: class DrivingCosts is public, should be declared in a file named DrivingCosts.ja

28 messages · Page 1 of 1 (latest)

split heath
#

Can't find anyway to fixt this despite me making a package in regards to it.

wicked fernBOT
#

This post has been reserved for your question.

Hey @split heath! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

split heath
#
public class DrivingCosts {
   public static double drivingCost(double drivenMiles, double milesPerGallon, double dollarsPerGallon) {
   double totalCost = (drivenMiles / milesPerGallon) * dollarsPerGallon;
   return totalCost;
}

public static void main(String[] args) { 
   Scanner scnr = new Scanner(System.in);
      double milesPerGallon;
      double dollarsPerGallon;
      
      milesPerGallon = scnr.nextDouble();
      dollarsPerGallon = scnr.nextDouble();

      System.out.printf("%.2f", drivingCost(milesPerGallon, dollarsPerGallon, 10));

   System.out.printf(" %.2f", drivingCost(milesPerGallon, dollarsPerGallon, 50));

    System.out.printf(" %.2f\n", drivingCost(milesPerGallon, dollarsPerGallon, 400));
            

      scnr.close();
}
}
#

Error I'm met with is error: class DrivingCosts is public, should be declared in a file named DrivingCosts.java

split heath
#

If someone has a quick fix let me know.

oak palm
#

Are you running your code from an IDE ?

split heath
#

Code was written in an IDE.

short kayak
#

exactly as the error says

#

it should be in a file named DrivingCosts.java

#

not Main.java

split heath
#

I'm just having a hard time seeing where I put it in main.java.

#

Plus this is in Zybooks is where I'm placing this.

short kayak
short kayak
#

you should be able to though

split heath
#

No I mean.

#

Zybooks has no files.

#

Wait...

#

Okay it gave me an output but it's not the output I wanted.

#

I got it now.

short kayak
split heath
#

I got 4/10 but it's all good.

short kayak
#

you need a file for most things

split heath
#

Yeah I realized.

#

Zybooks has a premade file.