darkleo91
darkleo91

Reputation: 19

Java help Decimal format cannot be resolved to a type

I have spent a while trying to figure out why it won't use the decimal format in my java code. I have declared the decimal format with the other integers but is still coming up with errors. Here is my code:

public class Assign31
{
  public static void main(String [] args)
  {
    DecimalFormat speedPattern = new DecimalFormat( "00.00" );
    int gearRadius = 100;
    double pi = Math.PI;
    int cadence = 90;

     double gearspeed = gearRadius * pi;

     double speedmph = gearspeed % cadence;

     System.out.println("The speed of the cyclist on a bike with gear 100.0 and cadence 90 is " + 
speedmph + " mph.");
     System.out.println("The speed (rounded) of the cycleist on the bike with gear 100.0 and cadence 90 is " + 
speedPattern.format(speedmph));
  }
}

Upvotes: 1

Views: 29579

Answers (2)

Iswanto San
Iswanto San

Reputation: 18569

import java.text.DecimalFormat;

public class Assign31 {
    public static void main(String[] args) {

        // Problem 1

        // declare variables
        DecimalFormat speedPattern = new DecimalFormat("00.00");
        int gearRadius = 100;
        double pi = Math.PI;
        int cadence = 90;

        // initialze data for first scenario
        double gearspeed = gearRadius * pi;

        // calculate speed
        double speedmph = gearspeed % cadence;

        // display speed
        System.out
                .println("The speed of the cyclist on a bike with gear 100.0 and cadence 90 is "
                        + speedmph + " mph.");
        System.out
                .println("The speed (rounded) of the cycleist on the bike with gear 100.0 and cadence 90 is "
                        + speedPattern.format(speedmph));

        // end problem 1

    }
}

Upvotes: 1

Dave Newton
Dave Newton

Reputation: 160211

You need to import it:

import java.text.DecimalFormat;

public class Assign31 {
    public static void main(String [] args) {
        DecimalFormat speedPattern = new DecimalFormat( "00.00" );
        // etc.

Upvotes: 3

Related Questions