Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 9th, 2013, 11:20 AM
XxdarkstarxX XxdarkstarxX is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 XxdarkstarxX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 9 sec
Reputation 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?

Reply With Quote
  #2  
Old February 9th, 2013, 01:09 PM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,825 bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 8 h 46 m 17 sec
Reputation Power: 1248
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
Note that you can't place a method directly inside another method.

Reply With Quote
  #3  
Old February 9th, 2013, 01:24 PM
XxdarkstarxX XxdarkstarxX is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 XxdarkstarxX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 9 sec
Reputation Power: 0
Quote:
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
		
	}
}

Reply With Quote
  #4  
Old February 9th, 2013, 01:50 PM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,825 bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level)bullet User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 8 h 46 m 17 sec
Reputation Power: 1248
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
It looks like your code is compiling and running. Is there a problem?

Reply With Quote
  #5  
Old February 9th, 2013, 05:08 PM
XxdarkstarxX XxdarkstarxX is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 3 XxdarkstarxX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 9 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
  #6  
Old February 10th, 2013, 05:50 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > ValidInput errors and return error.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap