#Main.java:2: error: class DrivingCosts is public, should be declared in a file named DrivingCosts.ja
28 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @split heath! Please use
/closeor theClose Postbutton 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.
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
If someone has a quick fix let me know.
Are you running your code from an IDE ?
I'm not running it from Eclipse I'm doing it from Zybooks.
Code was written in an IDE.
exactly as the error says
it should be in a file named DrivingCosts.java
not Main.java
In the public static void?
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.
no, your filename
if you can't change the filename you might have to rename your class to Main
you should be able to though
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.
it does
I got 4/10 but it's all good.
you need a file for most things