Question

In Java. I am getting confused with this assignment, my confusion starts where I stopped. Create a package named tempera...

In Java. I am getting confused with this assignment, my confusion starts where I stopped.

Create a package named temperature and create a program that has a while loop.

• Inside the while loop, your program will prompt the user for temperature in Centigrade.

• If the Centigrade value read in is <= -100, the loop will exit.

• Otherwise, your program will compute the Fahrenheit equivalent temperature.

• Inside the while loop, your program will print out the Centigrade and Fahrenheit temperatures. • Keep a count of the valid user inputs and a running total of your Fahrenheit and Centigrade temperatures.

• When the user terminates the while loop, print out the average Centigrade and Fahrenheit temperatures.

• Note that o Average_Fahrenheit = Total_of_Fahrenheit/ total_user_inputs o Average_Centigrade = Total_of_Centigrade / total_use_inputs

• Also note that: o Fahrenheit = (9.0/5.0)*Centigrade + 32.0

************************ Here is some sample output from your program: ***************************

Enter Temp in Centigrade or <= -100.0 to quit: 20 Temperature: F(68.0) C(20.0)

Enter Temp in Centigrade or <= -100.0 to quit: 30

Temperature: F(86.0) C(30.0)

Enter Temp in Centigrade or <= -100.0 to quit: 40

Temperature: F(104.0) C(40.0)

Enter Temp in Centigrade or <= -100.0 to quit: 1

Temperature: F(33.8) C(1.0) Enter Temp in Centigrade or <= -100.0 to quit: -10

Temperature: F(14.0) C(-10.0) Enter Temp in Centigrade or <= -100.0 to quit: -100 Average: Centigrade(16.2)

Average: Fahrenheit(61.160000000000004)

This is what I have started with, where the coding stops is where I am lost.  

package temperature;
import java.util.Scanner;

public class Temperature {
   public static void main(String[] args) {
       Scanner userInput = new Scanner(System.in);
       double celsius, Centigrade, averageFahrenheit, averageCentigrade, totalUserInput = 0;
      
do {
   System.out.println("Enter Temp in Centigrade or <= -100.0 to quit: ");
   celsius = userInput.nextDouble();
   double fahrenheit = (9.0/5.0)*Centigrade +32.0;
      
      
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java program

import java.util.Scanner;

public class Temperature {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
double celsius, fahrenheit, averageFahrenheit, averageCentigrade, totalUserInput = 0;
double totalFahrenheit=0, totalCentigrade=0;
  
do {
      System.out.print("Enter Temp in Centigrade or <= -100.0 to quit: ");
      celsius = userInput.nextDouble();
      if(celsius>-100) {
          totalUserInput++;
          fahrenheit = (9.0/5.0)*celsius +32.0;
          System.out.printf("Temperature : F(%.1f) C(%.1f)\n", fahrenheit,celsius);
          totalFahrenheit+=fahrenheit;
          totalCentigrade+=celsius;}
      }while(celsius>-100);
     
      if(totalUserInput>0) {
          averageFahrenheit = totalFahrenheit/totalUserInput;
          averageCentigrade = totalCentigrade/totalUserInput;
   }
      else {
          averageFahrenheit=0;
          averageCentigrade=0;
      }
      System.out.printf("Average: Centigrade:(%.1f)\n", averageCentigrade);
      System.out.printf("Average: Fahrenheit:(%.1f)\n", averageFahrenheit);
      userInput.close();

}
}

//sample output

<terminated> Tempreture [Java Applicationl C:AProgram FilesJavaidk1.8.0 151 bin avaw.exe Enter Temp in Centigrade or<-100.0 t

Add a comment
Know the answer?
Add Answer to:
In Java. I am getting confused with this assignment, my confusion starts where I stopped. Create a package named tempera...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in Java, temperature problem Create a package named temperature and create a program that has a...

    in Java, temperature problem Create a package named temperature and create a program that has a while loop. • • Inside the while loop, your program will prompt the user for temperature in Centigrade. If the Centigrade value read in is <= -100. the loop will exit. Otherwise, your program will compute the Fahrenheit equivalent temperature. Inside the while loop, your program will print out the Centigrade and Fahrenheit temperatures. Keep a count of the valid user inputs and a...

  • Modify this code to display the message "That's hot!" if the temperature entered is greater than...

    Modify this code to display the message "That's hot!" if the temperature entered is greater than 90 degrees Farenheit or equivalent Celsius, or the message "That's cold!" if the temperature entered is less than -10 degrees Farenheit or equivalent Celsius. And to show one in between where it doesn't show any message. #include <iostream> #include <iomanip> using namespace std; // a temperature conversion program int main() { char tempType; double temp, fahren, celsius; cout << "Enter the temperature to be...

  • For this assignment you will create a program converting Fahrenheit temperatures to Celsius temperatures. The formula...

    For this assignment you will create a program converting Fahrenheit temperatures to Celsius temperatures. The formula for converting a temperature from Celsius to Fahrenheit is: F = C x 1.8 + 32, where F is the Fahrenheit temperature and C is the Celsius temperature. Write a function named Fahrenheit that accepts a Celsius temperature as an argument and returns the temperature converted to Fahrenheit. Demonstrate the function by accepting a Celsius temperature from a user and displaying the temperature converted...

  • IN JAVA…PLEASE comment the code thoroughly so I can understand the thought process. Write a GUI...

    IN JAVA…PLEASE comment the code thoroughly so I can understand the thought process. Write a GUI application that converts Celsius temperatures to Fahrenheit temperatures. The user should be able to enter a Celsius temperature, click a button, and then see the equivalent Fahrenheit temperature. Use the following formula to make the conversion: F = (9/5)C + 32 F is the Fahrenheit temperature and C is the Celsius temperature. Instead of only converting from Celsius to Fahrenheit, also convert from Fahrenheit...

  • CIST 1305 – Program Design and Development Chapter 4 Assignment #7 [Decisions/If Statements & Loops] (50...

    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...

  • I need help with the following assignment: Write an application named DailyTemps that continuously prompts a...

    I need help with the following assignment: Write an application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message: Valid temperatures range from -20 to 130. Please reenter temperature. Before the program ends, display the...

  • package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task...

    package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task #1 before adding Task#2 where indicated. */ public class NumericTypesOriginal { public static void main (String [] args) { //TASK #2 Create a Scanner object here //identifier declarations final int NUMBER = 2 ; // number of scores int score1 = 100; // first test score int score2 = 95; // second test score final int BOILING_IN_F = 212; // boiling temperature double fToC;...

  • Process Create a City structure. The structure will hold the name of a city and its temperature. ...

    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...

  • I need help on creating a while loop for my Java assignment. I am tasked to...

    I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...

  • C# I am having trouble this program. So far my temperature converter program is converting temps...

    C# I am having trouble this program. So far my temperature converter program is converting temps from C to F. However, whenever I try to convert F to C, it's keep crashing and displaying an error message, which I can not figure it out and do not know how to fix it. Attached are two screenshots are of message. Do you know what is causing the issue? I would much appreciate your assistance. namespace Temp Conv { public partial class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT