#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    ValidInput errors and return error.


    I am getting an error on the return isValid, and the validInput areas of my methods. how can i solve these problems? On the validInput error it says void is an invalid type for the variable, and the second validInput error says illegal modifier for parameters validInput only final is permitted. For the return isValid, it says void methods cannot have a return.

    Code:
     import java.util.Scanner;
        
        
        public class Project2 {
        
        	private static final Object False = null;
        	private static final int number = 0;
        	private static final int CS = 0;
        	private static final int fTemp = 0;
        	private static final int fDist = 0;
        	private static final int ME = 0;
        	private static final int pWeight = 0;
        	private static final int KL = 0;
        
        	/**
        	 * @param args
        	 * @return 
        	 */
        	public static void main(String[] args) {
        		// TODO Auto-generated method stub
        		validInput();
        	
        		
        				//Declare constants
        				final double CS = (5.0 / 9);
        				final double ME = 0.3048;
        				final double KL = 0.4536;
        				
        				//Declare variables
        				Scanner input = new Scanner(System.in);
        				String entry;
        				int fTemp, fDist, pWeight;
        				String Inputnumber = null;
        				double cTemp, mDist, kWeight, K, I, S;
        				
        				System.out.println(" A B ");
        				System.out.println(" Project Title "); 
        				
        				//Get Input
        				System.out.print("Enter a Fahrenheit temperature (integer): ");
        				fTemp = input.nextInt();
        				System.out.print("Enter a distance in feet (integer): ");
        				fDist = input.nextInt();
        				System.out.print("Enter a weight in pounds (integer): ");
        				pWeight = input.nextInt();							
        				
        				//Perform Conversions
        				cTemp = fTemp * CS;
        				mDist = fDist * ME;
        				kWeight = pWeight * KL;
        				K = (fTemp + 459.67) * 5/9;
        				I = fDist * 12;
        				S = pWeight * 0.0714285714;
        				
        				//Methods           (error here)		
        				private static void validInput(int i; int j; {
        					// TODO Auto-generated method stub
        					boolean withinRange = true;
        					
        					if (i < 0 || i > 212);
        					System.out.println("Out of range");
        					withinRange = false;
        							
        				}
        
                                                               (error here)      (error here on entry)
        				private static boolean validInput(String entry); { 
        				// TODO Auto-generated method stub
        					boolean isValid = false;
        							
        					try {
        						Integer.parseInt(entry);
        						
        						isValid = true;
        						
        					}
        					catch  (Exception ex) {
        					System.out.println("Entered value is invalid");
        					}
        					
        					
        					(error here)
        					return isValid;
        				
        				
        				//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 ");
        				
        				}
        	
        	
        			
        			
        				
        	
        	
        		
        		
        		
        		
        				
        
        	}
        
        	private static void validInput() {
        		// TODO Auto-generated method stub
        		
        	}
        }
    My project is suppose to look like this as the ending result:
    Name
    Project title

    Enter a Fahrenheit temperature (integer) [0-212]: 212
    Enter a distance in feet (integer) [0-100]: 100
    enter a weight in pounds (integer) [0-100]: 100

    212 Fahenheit is 100.0 Celsius and 373.150 Kelvin
    100 Feet is 30.480 Meters and 1200.00 Inches
    100 Pounds is 45.360 Kilograms and 7.143 Stones

    Please enter a fahrenheit temperature (integer) [0-212]: abc
    The entered temperature value is invalid.

    Please enter a fahrenheit temperature (integer) [0-212]: 213
    The entered value is out of range [0-212]

    My code currently looks like this;
    A B
    Project Title
    Enter a Fahrenheit temperature (integer): 212
    Enter a distance in feet (integer): 100
    Enter a weight in pounds (integer): 100
    212 fahrenheit 117.77777777777779 celsius 373.15000000000003 Kelvin
    100 feet 30.48 meters 1200.0 Inches
    100 pounds 45.36 kilograms 7.14285714Stones

    So I know I dont have everything coded right so can anyone help as to how to get the results im supposed to get?
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Note that you can't place a method directly inside another method.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by bullet
    Note that you can't place a method directly inside another method.
    Here is my updated code. How would I put both of these methods in there so they arent directly inside each other and that way both of them are executed?

    Code:
    import java.util.Scanner;
    
    public class Project2 {
    
    	
    	/**
    	 * @param args
    	 * @return 
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    	
    		
    				//Declare constants
    				final double CS = (5.0 / 9);
    				final double ME = 0.3048;
    				final double KL = 0.4536;
    				
    				//Declare variables
    				Scanner input = new Scanner(System.in);
    				String entry;
    				int fTemp = 0, fDist, pWeight;
    				String Inputnumber = null;
    				double cTemp, mDist, kWeight, K, I, S;
    				
    				System.out.println(" A B ");
    				System.out.println(" Project Title "); 
    				
    				//Get Input
    				System.out.print("Enter a Fahrenheit temperature (integer): ");
    				fTemp = input.nextInt();
    				System.out.print("Enter a distance in feet (integer): ");
    				fDist = input.nextInt();
    				System.out.print("Enter a weight in pounds (integer): ");
    				pWeight = input.nextInt();							
    				
    				//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 ");
    	}
    				//Methods		
    				private static void validInput(int a) {
    					// TODO Auto-generated method stub
    					boolean withinRange = true;
    					
    					if (a < 0 || a > 212);
    					System.out.println("Out of range");
    					withinRange = false;
    							
    				
    					validInput();
    				}
    				
    				private static boolean validInput(String entry) { 
    				// TODO Auto-generated method stub
    					int fTemp, fDist, pWeight;
    					boolean isValid = false;
    							
    					try {
    					fTemp = Integer.parseInt(entry);
    					fDist=Integer.parseInt(entry);
    					pWeight=Integer.parseInt(entry);
    						isValid = true;
    						
    					}
    					catch  (Exception ex) {
    					System.out.println("Entered value is invalid");
    					
    					validInput();
    					}
    					
    					
    					
    					return isValid;
    				
    				
    						
    				}
    	private static void validInput() {
    		// TODO Auto-generated method stub
    		
    	}
    }
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    It looks like your code is compiling and running. Is there a problem?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by bullet
    It looks like your code is compiling and running. Is there a problem?
    I need the two methods i have in there to work. For example a max value of 212 so if i do 213 it says that the value is out of range and also if i put abc for a temperature it says the value is invalid. but other then that it works.
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348

IMN logo majestic logo threadwatch logo seochat tools logo