Java Program:
import java.util.*;
class TemperatureConversions
{
//Main method
public static void main(String args[])
{
char ch;
int tempF, tempC;
Scanner sc = new
Scanner(System.in);
//Loop till user wants to
quit
while(true)
{
//Displaying
menu
ch =
displayMenu();
switch(ch)
{
//Celsius to Fahrenheit
case 'C':
System.out.print("\n Enter the Celsius
temperature: ");
tempC = sc.nextInt();
tempF = CtoF(tempC);
System.out.print("\n The temperature " + tempC +
" Celsius is " + tempF + " Fahrenheit. ");
break;
//Fahrenheit to Celsius
case 'F':
System.out.print("\n Enter the Fahrenheit
temperature: ");
tempF = sc.nextInt();
tempC = FtoC(tempF);
System.out.print("\n The temperature " + tempF +
" Fahrenheit is " + tempC + " Celsius. ");
break;
//Quit
case 'Q': return;
default: break;
}
}
}
//Displaying menu
public static char displayMenu()
{
Scanner sc = new
Scanner(System.in);
char ch;
do
{
//Printing
menu
System.out.print("\n\n Please select one of the following: \n\t F -
Fahrenheit to Celsius \n\t C - Celsius to Fahrenheit \n\t Q - Quit.
\n\n\t Choice: ");
//Accepting user
input
ch =
((sc.next()).toUpperCase()).charAt(0);
}while(ch != 'F' && ch !=
'C' && ch != 'Q');
return ch;
}
//Celsius to Fahrenheit
public static int CtoF(int c)
{
int tempF;
//Converting temperature from
Celsius to Fahrenheit
tempF = (int)( c * (9/5.0)) +
32;
return tempF;
}
//Fahrenheit to Celsius
public static int FtoC(int f)
{
int tempC;
//Converting temperature from
Fahrenheit to Celsius
tempC = (int)(( f - 32) *
(5/9.0));
return tempC;
}
}
_______________________________________________________________________________________________________
Sample Run:
solve using java Q6: (Temperature Conversions) Implement the following integer methods: a) Method celsius returns the...
Using the latest version of Java JDK, Create a version of this TempConverter program to convert from Fahrenheit to Kelvin. Read the Fahrenheit temperature from the user. public class TempConverter { //----------------------------------------------------------------- // Computes the Fahrenheit equivalent of a specific Celsius // value using the formula F = (9/5)C + 32. //----------------------------------------------------------------- public static void main (String[] args) { final intBASE = 32; final double CONVERSION_FACTOR = 9.0 / 5.0; double fahrenheitTemp; intcelsiusTemp= 24; // value to convert fahrenheitTemp= celsiusTemp*...
using C Process Create a City structure. The structure will hold the name of a city and its temperature. In the main function, read in a series of city names and their temperature expressed in Fahrenheit. Store the data in an array of City structures. Stop reading when either: The user enters the word "quit" for a city name, or The size of the array is about to be exceeded. Create a function that determines the highest temperature of the...
Java program Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating- point number for the temperature and a character for the scale, eitherでfor Celsius or 'F' for fahrenheit. The class should have Four constructors: one for the number of degrees, one for the scale, one for both the degrees and scale, and a default constructor. For each of these constructors, assume zero degrees if no value is specified and celsius if no...
WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length, and depth. It will return the total surface area (6 sides) of the rectangular box it represents. 2. Implement a method named rightTriangle that accepts 2 double arameters named sideA and hypotenuseB. The method will return the length of the third side. NOTE To test, you should put all of these methods into a ‘MyMethods’ class and then write an application that will instantiate...
I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...
Using Java solve recursively without the use of loops or modifying the method signatures. /** * Given a sorted input array a, return a sorted array of size a.length + 1, * consisting of all elements of array a and integer i. * * @param a an array that is sorted in a non-descending order * @param i an integer * @return a sorted array of size a.length + 1, consisting of all elements of * array a and integer...
CIST 1305 – Program Design and Development Chapter 4 Assignment #7 [Decisions/If Statements & Loops] (50 Points) Please do the following exercises: Pastoral College is a small college in the Midwest. Design the pseudo-code for a program that accepts a student name, major field of study, and grade point average. Display a student’s data with the message “Dean’s list” if the student’s grade point average is above 3.5, “Academic probation” if the grade point average is below 2.0, and no...
By using Java public static methods solve following problem Write a method called vowelCount that accepts a String as its only parameter, and returns an array int[5] containing the count of vowels a,e,i,o,u in that String, using ignoreCase. For example, vowelCount("") returns {0,0,0,0,0}, and for the callvowelCount("Bill Iverson") your method returns {0,1,2,1,0} because there is one 'e' and two 'i' vowels (ignore case) and one 'o' with zero counts for 'a' and 'u' vowels.
USING JAVA Consider the following methods: StringBuilder has a method append(). If we run: StringBuilder s = new StringBuilder(); s.append("abc"); The text in the StringBuilder is now "abc" Character has static methods toUpperCase() and to LowerCase(), which convert characters to upper or lower case. If we run Character x = Character.toUpperCase('c');, x is 'C'. Character also has a static isAlphabetic() method, which returns true if a character is an alphabetic character, otherwise returns false. You will also need String's charAt()...