Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com temperature conversion

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 01-17-2011, 01:51 AM PM User | #1 worldtraveller Regular Coder   Join Date: Nov 2010 Location: canada Posts: 131 Thanks: 51 Thanked 0 Times in 0 Posts temperature conversion Exercise 3 Write an application that takes as input a temperature in Celsius and calculates both the approximated Fahrenheit equivalent and the actual Fahrenheit equivalent. Write out all three values. If the approximation and the actual value are within two degrees, write out “close enough” if they are not within two degrees, write out “ will not do” Hints Remember the Math.abs() method will return the absolute (unsigned) value of its argument. Refer to 'Numeric Methods' in Section 4.5 of the Main Text. this is what i am working from Code: ```public class Converter { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter temp: "); int temp = sc.nextInt(); System.out.println(convertToC(temp)); } public static int convertToC(int temp) { return ((temp - 32 ) * 5/9); } }``` but i am on wrong track how should i start this properly?
 01-17-2011, 03:19 AM PM User | #2 ShaneC Codeasaurus Rex   Join Date: Jun 2008 Location: Redmond, WA Posts: 659 Thanks: 31 Thanked 100 Times in 94 Posts Well first, I'm not really sure what you mean when you say the "approximated Fahrenheit equivalent" so I can't really help you on that part. This seems to be a fairly straight forward Introductory Java assignment. I don't want to do the assignment for you, for reasons posted in all sorts of stickies (among them: http://www.codingforums.com/showthread.php?t=53446), but you need to do a few things: 1) Read in the Celsius value from the user. You're already doing this right, except you shouldn't read it in as an Integer in the event they say 37.2 degrees. For this, try nextFloat and assign it to a Float data type. Also, you're going to need to enclose this in a try{}catch to catch the InputMismatchException Code: ```try { Scanner input = new Scanner( System.in ); float celsiusValue = input.nextFloat(); }catch( Exception e ){ System.out.println( "You must enter a floating point number!" ); System.exit( 1 ); }``` 2) Next, according to your assignment, output this. This is very straight forward and you've already got it for the most part: `System.out.println( "Specified Celsius Value: " + celsiusValue );` 3) Now, for clarity sake, create a method for two things: A) Calculating the approximate Fahrenheit value (again, not sure what this means) and B) Calculating the finite Fahrenheit value The function prototypes will look something like this: `public static float calcApproximateFahrenheit( float celsiusValue );` `public static float calcExactFahrenheit( float celsiusValue );` 4) Print both values 5) Take the result of those methods, compare them: Code: ```if( Math.abs( ( exactAmount - approxAmount ) ) <= 2 ) System.out.println( "Close enough" ); else System.out.println( "Will not do" );``` The method `Math.abs()` allows us to see both in the positive and negative direction at the same time. Let's say exactAmount - approxAmount = -2. The absolute value will turn -2 into 2, which we can then evaluate. Now, try to create a program to accomplish this one step at a time. As you encounter problems feel free to post them and I'll be more than happy to help you solve them. __________________ Unless otherwise stated, any code posted is most likely untested and may contain syntax errors. My posts, comments, code, and suggestions reflect only my personal views. Web Portfolio and Code Snippets: http://shanechism.com Last edited by ShaneC; 01-17-2011 at 06:30 AM.. Reason: Added try{}catch{} remark
 Users who have thanked ShaneC for this post: worldtraveller (01-17-2011)

 Bookmarks

 Tags java, temperature

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 10:26 AM.