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.

Page 2 of 2 FirstFirst 12
Results 26 to 40 of 40

Thread: help with this code please!!!

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,005
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: help with this code please!!!

    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.

  2. #27
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    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

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,005
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: help with this code please!!!

    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.

  4. #29
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    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

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,005
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: help with this code please!!!

    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.

  6. #31
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    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...

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,005
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: help with this code please!!!

    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.

  8. #33
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    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..

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,005
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: help with this code please!!!

    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.

  10. #35
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    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

  11. #36
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    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
            }
    }

  12. #37
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    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);
    	}
    }>

  13. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,005
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: help with this code please!!!

    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.

  14. #39
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    Quote Originally Posted by Norm View Post
    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.
    yes everything just throw me off right now ...
    I have been working since early morning today but cant still get it to work with THOSE CLASSES

  15. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,005
    Thanks
    52
    Thanked 2,276 Times in 2,247 Posts

    Default Re: help with this code please!!!

    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.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 4
    Last Post: January 24th, 2013, 10:20 AM
  2. Replies: 7
    Last Post: January 24th, 2013, 09:41 AM
  3. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 03:38 PM
  4. Replies: 5
    Last Post: November 14th, 2012, 09:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM

Tags for this Thread