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 3 of 3 FirstFirst 123
Results 51 to 59 of 59

Thread: Need some minor help.

  1. #51
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Need some minor help.

    You could do the computations after getting the input
    and validating it.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #52
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    import java.util.*;
    public class InputValidation {
    	public static void main(String[] args) {
    		Scanner inputScanner = new Scanner(System.in);
    		do {
    			System.out.println("Enter a Fahrenheit temperature (integer): ");	
    			try {
    				value = inputScanner.nextInt();
    				if (value<0 || value>212) {
    					System.out.println("The entered value is out of range [0-212]");
    				}
    			}
    			catch (Exception e) {
    				System.out.println("This entered value is invalid.");
    				inputScanner.next();
    			}
    		} while (value<0 || value>212);
     
     
    	}
    	public static int value=-1, fTemp, fDist, pWeight;//Declare variables
    	public static double cTemp, mDist, kWeight, K, I,S, CS = (5.0 / 9), ME = 0.3048, KL = 0.4536;//Declare constants and doubles
     
    	public static double fahrenheitToCelsiusToKelvin(double fahrenheit) {
    		return cTemp = fTemp * CS;}
    	{	
    		System.out.println(fTemp  + " fahrenheit " + cTemp + " celsius "  + K + " Kelvin ");
    	}
     
     
     
     
     
     
    }

    Do I do something like this or how would I put it after validating the fahrenheit temp along with the 2 other conversions i need done?

    Is it possible for me to put all three conversions after the loop?

  3. #53
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Need some minor help.

    Do I do something like this or how would I put it after
    Make the list of steps for the program in pseudo code before coding the program.
    When you have the list of steps, then write the code.
    Don't write code before you have gotten the steps figured out.

     return cTemp = fTemp * CS;}      //<<<<< NOTE HIDDEN }
    That is a very POOR coding technique. Don't hide }s at the end of statements.
    }s should be on a line by themselves
    If you don't understand my answer, don't ignore it, ask a question.

  4. #54
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    import java.util.*;
     
    public class InputValidation {
    	public static void main(String[] args) {
    		int value=-1, fTemp, fDist, pWeight;//Declare variables
    		double cTemp, mDist, kWeight, K, I,S; //Declare variables
    		final double CS = (5.0 / 9), ME = 0.3048, KL = 0.4536;//Declare constants
     
    		Scanner inputScanner = new Scanner(System.in);
    		do	{
    			System.out.println("Enter a Fahrenheit temperature (integer): ");
     
    			try {
    				value = inputScanner.nextInt();
    				if (value<0 || value>212) {
    					System.out.println("The entered value is out of range [0-212]");
    				}
    			}
    			catch (Exception e) {
    				System.out.println("This entered value is invalid.");
    				inputScanner.next();
    			}
    		} 	while (value<0 || value>212); 
     
     
    	}
     
     
    }

    This is what I would like to stick with, could you give me a hint other then pseudo code as to where to enter my computations and display report so they work? Or with this loop am i way off track?

  5. #55
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Need some minor help.

    where to enter my computations and display report
    From post#19:
    Here is some pseudo code:
    get input from user
    validate input
    use input in computations <<<<<<<<<< NOTE this comes after validate input
    print out results <<<<<<<<< NOTE this comes after doing computations
    If you don't understand my answer, don't ignore it, ask a question.

  6. #56
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    I understand that..I meant does it go before the } while, or would it go after the } while. I appreciate your help greatly I just am stupid at this as it is so new to me.

  7. #57
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Need some minor help.

    The while loop is for the validate step. The computation step follows the validation step.

    If the computation step requires a loop, it would be a new loop, not part of the validation loop.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #58
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    Ok so i guess what your saying is in order to put this;
    //Perform Conversions
    cTemp = fTemp * CS;
    mDist = fDist * ME;
    kWeight = pWeight * KL;
    K = (fTemp + 459.67) * 5/9;
    I = fDist * 12;
    S = pWeight * 0.0714285714;

    //Display Report
    System.out.println(fTemp + " fahrenheit " + cTemp + " celsius " + K + " Kelvin ");
    System.out.println(fDist + " feet " + mDist + " meters " + I + " Inches ");
    System.out.println(pWeight + " pounds " + kWeight + " kilograms " + S + "Stones ");

    AFTER my loop/validation, I would need to create another loop to execute the above? Which im guessing would mean from another class or could I just make two loops on this page?

  9. #59
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Need some minor help.

    need to create another loop
    I don't see what you need a loop for.

    I'm done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Java vending machine, minor thing.
    By Aprok in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 5th, 2011, 02:35 PM
  2. my code displaying some minor wrong o/p ....plz suggest me an answer !
    By naved in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2011, 11:59 AM
  3. [SOLVED] Please help with this... I think I have a minor coding error
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 12th, 2011, 08:02 AM