• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decimal Format

 
Mindy Truitt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi -
After writing the code :
public class Mileage {
public static void main(String[] args) {
DecimalFormat twoDigitsPastPoint = new DecimalFormat("0.00");
double LengthOfTrip, CostOfGas, MilePerGallon, Total;


System.out.print("Enter length of trip: ");
LengthOfTrip = SavitchIn.readLineDouble();
System.out.print("Enter cost of gas: ");
CostOfGas = SavitchIn.readLineDouble();
System.out.print("Enter mile per gallon: ");
MilePerGallon = SavitchIn.readLineDouble();
Total = LengthOfTrip / MilePerGallon * CostOfGas;
System.out.println("The cost of your trip will be: $" + twoDigitsPastPoint.format(Total));
}
}
It won't run because of the error:
java.lang.Error: Unresolved compilation problems:
DecimalFormat cannot be resolved or is not a type
DecimalFormat cannot be resolved or is not a type
at Mileage.main(Mileage.java:17)
Exception in thread "main"
I think it has something to do with the 'DecimalFormat' because that is underlined in my program. Any help would be amazing!! Thanks ~ Mindy
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mindy,
Welcome to JavaRanch!
Strange error messages -- what Java compiler are you using?
Based on just the code you've shown us: including the line
import java.text.DecimalFormat;
at the beginning of the file should fix this problem.
 
Mindy Truitt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that and it got rid of the DecimalFormat error but now the word Format is underlined. I am using Eclipse as the Complier I think. Thanks ~Mindy
 
Mindy Truitt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I got it to work I just had to move the line up a bit.
Thanks, MINDY
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic