Did you test those methods as I suggested? Did they return the correct results?
Where should those methods go in the printf() statement in the code you posted in post#19?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Did you test those methods as I suggested? Did they return the correct results?
Where should those methods go in the printf() statement in the code you posted in post#19?
If you don't understand my answer, don't ignore it, ask a question.
sorry for getting back to you late my computer just froze for like 30 mins..
No anytime i try to use these methods i get erros cause without this methods my program runs really great now..
all thanks to you directions...
but we were asked to write class that contains those two methods in the program and that part i just can't figure it out
You need to test those methods so you know how to use them before trying to put them into the EX5_8 program.
If you don't understand my answer, don't ignore it, ask a question.
dont know if am doing thye right thing but i get errors
[java=code]
<import java.util.Scanner;
public class EX5_8{
public static void main(String args[]){
public static double celsiusToFahrenheit(double celsius){
return celsius=(5.0/9.0) * fahrenheit - 32+14.22;
}
public static double fahrenheitToCelsius(double fahrenheit){
return fahrenheit=(9.0/5.0) * fahrenheit + 32;
}
System.out.println("|Celsius |Fahrenheit||Celsius|Fahrenheit| \n");
double i=40;
double j=120;
do{
//System.out.printf(" %3.1f|%11.1f | %3.1f | %8.2f | \n",i,(i*(9.0/5)+32),j,(j*(5.0/9)-32+14.22));
System.out.printf(" %3.1f|%11.1f | %3.1f | %8.2f | \n",i,( fahrenheit),j,( celsius));
i-=1;
j-=10;
}while(i>=31 && j>=30);
}
}>
[/code]
--- Update ---
<import java.util.Scanner; public class EX5_8{ public static void main(String args[]){ public static double celsiusToFahrenheit(double celsius){ return celsius=(5.0/9.0) * fahrenheit - 32+14.22; } public static double fahrenheitToCelsius(double fahrenheit){ return fahrenheit=(9.0/5.0) * fahrenheit + 32; } System.out.println("|Celsius |Fahrenheit||Celsius|Fahrenheit| \n"); double i=40; double j=120; do{ //System.out.printf(" %3.1f|%11.1f | %3.1f | %8.2f | \n",i,(i*(9.0/5)+32),j,(j*(5.0/9)-32+14.22)); System.out.printf(" %3.1f|%11.1f | %3.1f | %8.2f | \n",i,( fahrenheit),j,( celsius)); i-=1; j-=10; }while(i>=31 && j>=30); } }>
--- Update ---
find above is the code with the various class methods
Test calling the two methods and nothing else. No loop and no printf.
Call each method with a known value that returns a known value: 212 and 100
to make sure the methods work correctly.
Why do all the statements start in the first column? What happened to the indentation like in post#19
If you don't understand my answer, don't ignore it, ask a question.
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:13: error: illegal start of expression
public static double celsiusToFahrenheit(double celsius){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:13: error: illegal start of expression
public static double celsiusToFahrenheit(double celsius){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:13: error: ';' expected
public static double celsiusToFahrenheit(double celsius){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:13: error: '.class' expected
public static double celsiusToFahrenheit(double celsius){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:13: error: ';' expected
public static double celsiusToFahrenheit(double celsius){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:16: error: illegal start of expression
public static double fahrenheitToCelsius(double fahrenheit){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:16: error: illegal start of expression
public static double fahrenheitToCelsius(double fahrenheit){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:16: error: ';' expected
public static double fahrenheitToCelsius(double fahrenheit){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:16: error: '.class' expected
public static double fahrenheitToCelsius(double fahrenheit){
^
C:\Documents and Settings\ajiekum2011\Desktop\ex5_8.java:16: error: ';' expected
public static double fahrenheitToCelsius(double fahrenheit){
^
10 errors
Tool completed with exit code 1
am getting the above errors, i have dis-functioned the loop and printf
now but i dont know where my errors are coming from now...
Methods can NOT be defined inside other methods. Make sure there are no methods inside of any other methods.
Each method as a { at the start and a } at the end. There should NOT be any method defined between the { and the }.
The poor formatting of the code in post #29 makes it hard to see where the methods are defined.
If you don't understand my answer, don't ignore it, ask a question.
Norm,I really appreciated the help all they way .
But, I am lost completely on how to
use and incorporate these methods into my program..
You need to study how to write methods and where to put them in the code. This is a very basic concept.
Do not define a method within the {}s that enclose another method's statements.
Start writing a new class and leave this one for now.
Define a main() method in the new class.
Add a call to the println() method to the main() method
Compile and execute that new code.
Copy and paste that new class here.
If you don't understand my answer, don't ignore it, ask a question.
Norm please please I cant get it right would just show me just this once please I have a similar program I have to use that same format, please am a beginner with java programming..
please help start me ,
I need just a start
I literally have been working on this since morning...pls
Your question is asking convert Celsius from 40 to 30 and Fahrenheit from 120 to 30, right???
You need to use a for loop for your answer, call the method, get result, add it to string for the display then decrement Celsius by 1 and Fahrenheit by 10,
after ending the loop display the output.
to use a method call it from the main, and put outside the main, like the following:
public class EX5_8{ public static void main(String args[]){ //statements }//end of main public static double mehtod(double a){ //statments } }
Thanks Bahoom, but what statements would I use for the main methods now please ?
find below is my code...
<public class EX5_8{ public static void main(String args[]){ } public static double celsiusToFahrenheit(double celsius){ get celsius=(5.0/9.0) * fahrenheit - 32+14.22; } public static double fahrenheitToCelsius(double fahrenheit){ get fahrenheit=(9.0/5.0) * fahrenheit + 32; } System.out.println("|Celsius |Fahrenheit||Celsius|Fahrenheit| \n"); double i=40; double j=120; do{ System.out.printf(" %3.1f|%11.1f | %3.1f | %8.2f | \n",i,(i*(9.0/5)+32),j,(j*(5.0/9)-32+14.22)); i-=1; j-=10; }while(i>=31 && j>=30); } }>
Have you tested either of the methods by calling them with a single value and printing out the value that is returned to check that the method works as desired?
Use a simple method that calls the method, no loop.
The statements in the code in post #37 needs to be formatted properly. The indentations are not right and that makes the code hard to read and understand.
If you don't understand my answer, don't ignore it, ask a question.
Do it one step at a time.
Create a class and add one main method. No other methods.
Add a call to the println method in the main() method that prints a simple message.
compile and execute that. Post the code for it here.
When that works, we'll move to the next step.
If you don't understand my answer, don't ignore it, ask a question.