I was asked for my AP Comp Sci online course to construct a program that would calculate fahrenheit to celsius and vice versa, the volume of a sphere given the radius, and the hypotenuse of a right triangle given the two other sides. I was given a program to work with to start but it was pretty much all of my programming. They just set up the comments and params and what-not. So I got the error message <identifier> expected over my first System.out.println("..."); line, which meant the console was not identified or imported, but it is clearly identified below. If anyone can help me out with this it'd be appreciated. I'll move onto my next program in the mean time.

public class MathFun
{
  /**
   *  Default Constructor for the MathFun object.
   *  Does nothing
   */
  public MathFun ( ) { }
  
  /**
   *  Converts a fahrenheit temperature value to celsius
   *
   * @param  fahrenheit  temperature in degrees fahrenheit
   * @return             temperature in degrees celsius
   */

  ConsoleIO console = new ConsoleIO();  
  
  double f, fToC;
  System.out.println("Input temperature in ºF ---> ");
  f = console.readDouble();
  fToC = (5 / 9)(f - 32);
  System.out.println("That is " + Format.right(fToC, 8, 2) + "ºC");
  
  /**
   *  Converts a celsius temperature value to fahrenheit
   *
   * @param  celsius  temperature in degrees celsius
   * @return          temperature in degrees fahrenheit
   */
  
  double c, cToF
  System.out.print("Input temperature in ºC ---> ");
  c = console.readDouble();
  cToF = (9 / 5)(c) + 32;
  System.out.println("That is " + Format.right(cToF, 8, 2) + "ºF");

  /**
   *  Calculates the volume of a sphere
   *
   * @param  r  radius of the sphere
   * @return    volume of the sphere
   */

  double r, V, pi
  System.out.print("Input radius of a sphere ---> ");
  r = console.readDouble();
  pi = 3.141592654;
  V = (4 / 3)(pi)(r) ^ 3;
  System.out.print("That gives the sphere a volume of " + Format.right(V, 8, 2);

  /**
   *  Calculates the hypotenuese of a right triangle
   *
   * @param  sideA  length of one side of the right-angle triangle
   * @param  sideB  length of one side of the right-angle triangle
   * @return        length of the hypotenues
   */

  double sideA, sideB, hypsqr, hyp;
  System.out.println("Input side A of your right triangle ---> ");
  sideA = console.readDouble();
  System.out.println("Now input side B ---> ");
  sideB = console.readDouble();
  hypsqr = ((sideA) ^ 2) + ((sideB) ^ 2);
  hyp = ((hypsqr) ^ (1/2));
  System.out.println("Those creat a hypotenuse of " + Format.right(hyp, 8, 2);

  /**
   *  The main program for the MathFun class. Gathers input,
   *  calculates the requested values and formats the output.
   *
   * @param  args  The command line arguments (not used)
   */
  public static void main(String[] args)
  {
    MathFun calc = new MathFun();

  }
}

Thank again,
-IMtheBESTatJAVA

You need to put commands such as this in methods: System.out.println("Input temperature in ºF ---> "); Also in java if you want the power of a number use: Math.pow(double a, double b)

Does the way I used with the ^'s still work? Also, what do you mean by putting certain code in methods?

Does the way I used with the ^'s still work? Also, what do you mean by putting certain code in methods?

the code you wrote above will automatically give errors
you end your constructor, but you do not start another method or constructor.

you can indeed declare variables in a class without having them in methods, but you can't use them, nor can you make actions like System.out.println(...);

you need to put every part of your code (except maybe declarations of class variables) into methods

I already asked what he meant by methods I've never used Java before but I took a VB class last year. Please explain what code I need to move if you can it'd be greatly appreciated.

#
ConsoleIO console = new ConsoleIO();

double f, fToC;
System.out.println("Input temperature in ºF ---> ");
f = console.readDouble();
fToC = (5 / 9)(f - 32);
System.out.println("That is " + Format.right(fToC, 8, 2) + "ºC");

/**
  * Converts a celsius temperature value to fahrenheit
  *
  * @param celsius temperature in degrees celsius
  * @return temperature in degrees fahrenheit
  */

double c, cToF
System.out.print("Input temperature in ºC ---> ");
c = console.readDouble();
cToF = (9 / 5)(c) + 32;
System.out.println("That is " + Format.right(cToF, 8, 2) + "ºF");

/**
  * Calculates the volume of a sphere
  *
  * @param r radius of the sphere
  * @return volume of the sphere
  */

double r, V, pi
System.out.print("Input radius of a sphere ---> ");
r = console.readDouble();
pi = 3.141592654;
V = (4 / 3)(pi)(r) ^ 3;
System.out.print("That gives the sphere a volume of " + Format.right(V, 8, 2);

/**
  * Calculates the hypotenuese of a right triangle
  *
  * @param sideA length of one side of the right-angle triangle
  * @param sideB length of one side of the right-angle triangle
  * @return length of the hypotenues
  */

double sideA, sideB, hypsqr, hyp;
System.out.println("Input side A of your right triangle ---> ");
sideA = console.readDouble();
System.out.println("Now input side B ---> ");
sideB = console.readDouble();
hypsqr = ((sideA) ^ 2) + ((sideB) ^ 2);
hyp = ((hypsqr) ^ (1/2));
System.out.println("Those creat a hypotenuse of " + Format.right(hyp, 8, 2);

put this part in a method, and call that method from your main method

How would I identify a method? I tried putting it in a public static void main(String[] args) but now theres a line of code (fToC = (5 / 9)(f - 32);) that keeps displaying the error message of ';' needed no matter what I do.

do not put methods in methods

public Class Test{

public static void main(String args[]){
  Test test = new Test();
   String printTest = test.returnPrintString();
   returnsNothing(printTest);
}

public vioid returnsNothing(String printMe){
  System.out.println(printMe);
}

public String returnPrintString(){
  return "printMePrettyPlease";
}

}

Okay I have that down now I just don't understand the ';' needed error on a line of code that has one. I'll try using the power code to try and fix this before coming back for help, but so far so good.

Yeah I used proper coding for my powers and square roots, yet when I compile it still returns an error message saying i need a ; after fToC = (5 / 9)(f - 32);.

Yeah I used proper coding for my powers and square roots, yet when I compile it still returns an error message saying i need a ; after fToC = (5 / 9)(f - 32);.

try

fToC = (5 / 9)*(f - 32);

Yeah I used proper coding for my powers and square roots, yet when I compile it still returns an error message saying i need a ; after fToC = (5 / 9)(f - 32);.

fToC = (5.0 / 9.0)*(f - 32)

Thanks a lot I finally came back around to this program and got it to work. Rep power for you and thread solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.