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...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
Selection control structure The if statement The switch statement (optional) Relational operators and logical operators Use...
Selection control structure The if statement The switch statement (optional) Relational operators and logical operators Use of relational and logical operators to check numeric ranges User friendly Use of user friendly user prompt and simple input validation Use of meaningful output labels and format Use of output manipulators Working with string type Use of getline() Project Description There are two main systems for measuring distance, weight and temperature, the Imperial System of Measurement and the Metric System of Measurement. Most...
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)...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
If you cant answer this please dont waste my question. thank you. This cryptographic program run...
If you cant answer this please dont waste my question. thank you. This cryptographic program run and produce text screen output. You are to create a GUI that uses the program. Your program (GUI) must allow a user to input of a message to be coded. It must also have an area to show the plaintext, the ciphertext, and the decrypted text. If required by your choice of cryptographic method, the user should have an area to input a key....
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT