Link to home
Start Free TrialLog in
Avatar of gkilgore
gkilgore

asked on

Add calling method named Centrigrade to the program

Use the formula to convet fahrenheit to centrigrade.  Write a method named Centrigrade that accepts Fahrenheit temperature as a argument.  Method should return temperature converted to Centigrade.  Demonstrate the method by calling it in a loop that displays a table of Fahrenheit 0 through 20.  My program displays the requirements, however, after 20 iterations have been made the program starts over.  Also, Not sure where to add the calling method named centrigrade(); in my main program.
import java.util.Scanner; 
import javax.swing.JOptionPane;
import java.io.*;
 
 
public class CentrigradeToFahrenheitTest
{
	public static void main(String[] args)
	{
	 	int number = 1;
		int degree;
    	boolean done=false;
    	    	String type = null; 
					String input;
 
//Create a Scanner object for keyboard input.				
		DataInput keyboard = new DataInputStream(System.in);
 
//Select F to convert to C.		
		do
		
		{
    		System.out.println("Press F to convert F-C");
    		try
			{
    			type = keyboard.readLine();
    		}
				catch(Exception e)
				{
    				System.out.println(e);
    			}
    		if(type.equals("F") || type.equals("f"))
			{
			
//Enter temperature to be converted.			
    			System.out.println("Please input the temprature: ");
				
				System.out.println("Fahrenheit\t\tCentrigrade");
				System.out.println("============================");
			
		  		try
				{
					for (number = 1; number > 0 && number <= 20; number++)
				
	    				Centrigrade(Double.valueOf(keyboard.readLine()).doubleValue());
				}
					catch(Exception e)
					{
    					System.out.println(e);
    				}
				
    		}
			
		}	
			while(!done);
	}
 
	public static void Centrigrade(double temp)
	{
	 			System.out.print(temp);
				temp = (temp - 32) / 1.8;
				System.out.println("\t\t" + temp);
		}}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gkilgore
gkilgore

ASKER

Perfect.  Thank you very much!!!!!