Question

Download the attached .java file. Run it, become familiar with its processes. Your task is to...

Download the attached .java file. Run it, become familiar with its processes. Your task is to turn TemperatureConversion into GUI based program. it should, at the least, perform similar functions as their text output versions. The key factor to remember is that the workings should remain the same (some tweaks may be necessary) between text and GUI programs, while the means pf visual presentation and user interaction changes. You must properly document, comment, indent, space, and structure both programs. import java.util.*;

Please add comments to code

public class TemperatureConversionSelection {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        
        double  degrees, // user input
                convertedDegrees; // calculated output
        char    units;   // user input: 'F' or 'f' for Fahrenheit
        // or 'C' or 'c' for Celsius
        
        System.out.println();//Blank lines for readability
        System.out.println();
        System.out.println
                ("Enter a temperature in degress (for example 29.6): ");
        degrees = keyboard.nextDouble();
        
        System.out.println();
        System.out.println
                ("Enter 'F' (or 'f') for Fahrenheit or "
                + "'C' (or 'c') for Celsius: ");
        
        units = keyboard.next().charAt(0);
        System.out.println();
        
        switch(units) {
            case 'F':
            case 'f':
                convertedDegrees = 5 * (degrees -32)/9;
                System.out.println(degrees + " degrees F = "
                        + convertedDegrees + " degrees Celsius.");
                break;
                
            case 'C':
            case 'c':
                convertedDegrees = degrees * 9/5 + 32;
                System.out.println(degrees + " degrees C = "
                        + convertedDegrees
                        + " degrees Fahrenheit.");
                break;
            default:
                System.out.println("Unknown units -");
                System.out.println("  cannot do calculation -");
                System.out.println("  next time enter either "
                        + "'F' for Fahrenheit or 'C' for Celsius.");
        } //end switch
        
        
    }
}

Homework Answers

Answer #1

import java.util.Scanner;

public class TemperatureConversionSelection {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
  
double degrees; // user input values
double convertedDegrees; // calculated output valus
char units; // user input: 'F' or 'f' for Fahrenheit,// or 'C' or 'c' for Celsius
  
  
System.out.println();//Blank lines for readability
System.out.println();
System.out.println("Enter a temperature in degress (for example 29.6): ");
degrees = keyboard.nextDouble();
System.out.println();
System.out.println("Enter 'F' (or 'f') for Fahrenheit or "+ "'C' (or 'c') for Celsius: ");
units = keyboard.next().charAt(0);
System.out.println();
  
switch(units) {
case 'F':
case 'f':convertedDegrees = 5 * (degrees -32)/9;
System.out.println(degrees + " degrees F = " + convertedDegrees + " degrees Celsius.");
break;
case 'C':
case 'c': convertedDegrees = degrees * 9/5 + 32;
System.out.println(degrees + " degrees C = "+ convertedDegrees + " degrees Fahrenheit.");
break;
default:System.out.println("Unknown units -");
System.out.println(" cannot do calculation -");
System.out.println(" next time enter either "+ "'F' for Fahrenheit or 'C' for Celsius.");
  
} //end switch
  
  
}
}

Test case:

Input:

Enter a temperature in degress :- 29.5

Enter for Fahrenheit for Celsius:- 15

Output:

Unknown units -
cannot do calculation -
next time enter either 'F' for Fahrenheit or 'C' for Celsius.

Hint points:

1.Convert Fahrenheit into Celsius.

celsius = (fahrenheit-32)*5)/9;

ex:fahrenheit =15,celsius=-9.4452

2.Convert Celsius into Fahrenheit .

Fahrenheit =(9*celsius/5)*32;

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in java need uml diagram import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String...
in java need uml diagram import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String work=""; boolean completed=false; boolean important=false; public TodoList(String a,String b,boolean c,boolean d){ this.date=a; this.work=b; this.completed=c; this.important=d; } public boolean isCompleted(){ return this.completed; } public boolean isImportant(){ return this.important; } public String getDate(){ return this.date; } public String getTask(){ return this.work; } } class Main{ public static void main(String[] args) { ArrayList<TodoList> t1=new ArrayList<TodoList>(); TodoList t2=null; Scanner s=new Scanner(System.in); int a; String b="",c=""; boolean d,e; char...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
Write a method that returns the sum of all the elements in a specified column in...
Write a method that returns the sum of all the elements in a specified column in a 3 x 4 matrix using the following header: public static double sumColumn(double[][] m, int columnIndex) The program should be broken down into methods, menu-driven, and check for proper input, etc. The problem I'm having is I'm trying to get my menu to execute the runProgram method. I'm not sure what should be in the parentheses to direct choice "1" to the method. I'm...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. b. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor. The duty...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...
please can you make it simple. For example using scanner or hard coding when it is...
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm 1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...