1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vivado [14]
3 years ago
8

Make a program that (i) asks the user for a temperature in Fahrenheit degrees and reads the number; (ii) computes the correspond

ing temperature in Celsius degrees; and (iii) prints out the temperature in the Celsius scale.
Computers and Technology
1 answer:
Lerok [7]3 years ago
5 0
<h2>Answer:</h2><h2></h2>

//import the Scanner class to allow for user's input

import java.util.Scanner;

//Create a class declaration with appropriate name

public class FahrenheitToCelsius {

   //Begin the main method where execution starts from

   public static void main(String[] args) {

       //Create an object of the Scanner class to allow reading from standard

       // input

       Scanner input = new Scanner(System.in);

       

       //Prompt the user to enter the temperature

       System.out.println("Enter a temperature in Fahrenheit degrees");

       

       //Read the number and store in a variable of type double

       double fahrenheit = input.nextDouble();

       

       

       //Convert the temperature to Celsius

       double celsius  = (fahrenheit - 32) * (5 / 9.0);

       

       //Print out the result

       System.out.println("The temperature in Celsius is " + celsius);

       

   } //End of main method

   

}   //End of class declaration

==============================================================

<h2>Sample Output 1:</h2><h2 />

>> Enter a temperature in Fahrenheit degrees

32

>> The temperature in Celsius is 0.0

==============================================================

<h2>Sample Output 2:</h2><h2 />

>> Enter a temperature in Fahrenheit degrees

78

>> The temperature in Celsius is 25.555555555555557

===============================================================

<h2>Explanation:</h2>

The code has been written in Java and it contains comments explaining every segment of the code. Please go through the comments.

The actual lines of code are written in bold face to separate them from the comments.

Sample outputs have also been given to show how the result of the program looks like.

You might be interested in
(The Location class) Design a class named Location for locating a maximal value and its location in a two-dimensional array. The
-Dominant- [34]

Answer:

Here is the Location class:

public class Location {   //class name

   public int row;  // public data field to hold the value of no. of rows

   public int column;  // public data field to hold the value of no. of columns

   public double maxValue;   //public data field to hold the maximum value

   public Location(int row, int column, double maxValue) { //parameterized constructor of Location class

//this keyword is used to refer to a current instance variable and used to avoid naming conflicts between attributes and parameters with the same name

       this.row = row;  

       this.column = column;  

       this.maxValue = maxValue;     }  

   public static Location locateLargest(double[][] a) {   //method that takes a 2 dimensional array a as argument and returns the location of the largest element

       int row = 0;  //initializes row to 0

       int column = 0;  //initializes column to 0

       double maxValue = a[row][column];   //stores largest element

       for (int i = 0; i < a.length; i++) {  //iterates through rows of a[] array

           for (int j = 0; j < a[i].length; j++) {  //iterates through columns of array

               if (maxValue < a[i][j]) {  //if the maxValue is less than the element of 2 dimensional array at ith row and jth column

                   maxValue = a[i][j];  //then set that element to maxValue

                   row = i;  // i is set to traverse through rows

                   column = j;   }             }         }  // i is set to move through columns

       return new Location(row,column,maxValue);     }  } //calls constructor of class by passing row, column and maxValue as argument

Explanation:

Here is the Main class with a main() function to  test program  

import java.util.Scanner;   //to accept input from user

public class Main {   //class name

   public static void main(String[] args) {   //start of main function

       Scanner scan = new Scanner(System.in);  //creates Scanner class object to scan the input from user

 System.out.print("Enter the number of rows and columns in the array: ");  //prompt for user

       int row = scan.nextInt();  // reads value of row from user

       int column = scan.nextInt();  //reads input value of column

       double[][] array = new double[row][column];   //declares a 2 dimensional array named array

       System.out.println("Enter the array:");  //prompts to enter array elements

       for (int i = 0; i < array.length; i++) {  //iterates through the rows of array until the size of array is reaced

           for (int j = 0; j < array[i].length; j++) {  //iterates through the columns of array

               array[i][j] = scan.nextDouble();    }    }   //reads each element at i-th row and j-th column

       Location location = Location.locateLargest(array);  //calls locateLargest method by passing array to it in order to locate the largest element in the array

System.out.println("The largest element in a two-dimensional array is: " + location.maxValue);  //displays the largest element of array

       System.out.println("The location of the largest element is at (" + location.row + ", " + location.column + ")");       }    } //displays the location of the largest element in the two dimensional array

Suppose the user enters 2 rows and 2 columns. The elements are:

1         5.5

4.5      3

The program works as follows:

for (int i = 0; i < array.length; i++) this outer loop iterates through rows

i = 0

inner loop for (int j = 0; j < array[i].length; j++) iterates through columns

array[i][j] = scan.nextDouble(); reads the element at position i-th row and j-th column. This becomes:

array[0][0] = scan.nextDouble();

so element at 0th row and 0th column is 1

Location location = Location.locateLargest(array); now this calls the method which works as follows:

double maxValue = a[row][column]; this becomes:

double maxValue = a[0][0];

so maxValue = 1

for (int i = 0; i < a.length; i++) this loop in method iterates through rows and  for (int j = 0; j < a[i].length; j++) this iterates through columns of array

if (maxValue < a[i][j]) this becomes:

if (maxValue < a[0][0])

As we know that maxValue = 1 so this if condition is true.

                   maxValue = a[i][j];  this becomes:

             maxValue = a[0][0];  

maxValue = 1

Now set row = 0 and column = 0

Now the inner loop value of j is incremented to 1. So j = 1

At next iteration array[0][1] is checked. The element at this position is 5.5

if (maxValue < a[i][j]) is true because 1<5.5 so now value of maxValue becomes:

maxValue = 5.5

and

i = 0  j = 1

This way at each iteration of inner loop the columns are traversed and at each iteration of outer loop rows are traversed.

At next iteration element at array[1][0] is checked which is 4.5. This is not greater than maxValue so maxValue remains 5.5

At next iteration element at array[1][1] is checked which is 3. This is not greater than maxValue so maxValue remains 5.5 .

After both the loops end the statement:

return new Location(row,column,maxValue);

returns row , column and maxValue

where row = 0  column = 1 and maxValue = 5.5

So the output is:

The largest element in a two-dimensional array is: 5.5

The location of the largest element is at (0,1)

3 0
4 years ago
When a CPU executes each instruction in a program, it uses a process known as the __________.
lapo4ka [179]

Answer:

The answer is "fetch-decode-execute cycle"

Explanation:

The FDE cycle stands for Fetch-Decode-Execute cycle, It is a computing operation, in which a CPU process, to retrieves the system in its order memory form, it also decides that what instruction is supposed to do, and executes certain activities.  In this process, the operating system loads the files and the program on a disc to the main memory (RAM).

8 0
4 years ago
A customer seeks to buy a new computer and for a private use at home.The customer primarily needs the computer to use the Micros
sergeinik [125]

Answer: I would suggest a Solid State Drive (SSD)

Explanation: An SSD is faster than a HDD and can be compartmentalized easier. If your only option is an HDD, than I suggest the cheapest (the one with less data.) Especially, if you're only using it Microsoft PowerPoint. Is it a laptop or a desktop?

7 0
3 years ago
What is the primary advantage of a 64-bit operating system versus 32-bit
Natasha2012 [34]
A 64-bit operating system can handle more data at once as compared to that of a 32-bit operating system. The former is able to access over four billion times the physical memory of the latter.
8 0
3 years ago
Make the correct match.
faltersainse [42]
<span>1. E 2. B 3. D 4. F 5. C 6. A Let's go about solving this problem in a process of elimination. So I'll be making each match in the easiest (for me) order. Initially I'm not sure about 1 & 2. But the match for #3 is rather obvious. So 3. Blending non-related clips and images to make a new video. This is a "D. Mashup" The next obvious answer is for #6. That is 6. Everything that happens to the video and audio after the footage has been shot. This is "A. Post production" Now of the remaining 4 choices, "Final Cut Pro" sounds like an actual program. And there's only 1 option that's asking for a specific program. So we have 2. Most popular post-production editing package by Apple Answer "B. Final Cut Pro" This leaves us with 3 options "C. Non-linear editing", "E. AVID", and "F. Timeline" Of these 3, only "F. Timeline" sounds list an element in the interface of a video editing package. So we have 4. An element in the interface of editing software Answer "F. Timeline" Now a quick google search reveals that "AVID" is a software company that makes video editing software. So 1. Company that makes high-end post-production software. Answer "E. AVID" And we're left with 5. Transferring film onto Beta, digitizing it to the computer, and editing it Answer "C. Non-linear editing" Now the only questionable choice is Non-linear editing (NLE) for #5. So doing a quick google search and I see that #5 over specified the task. The key characteristic of NLE is having the video and audio in digital form that can be readily accessed via a computer. And #5 does qualify for that task. So here's the final answers 1. E 2. B 3. D 4. F 5. C 6. A</span>
6 0
3 years ago
Other questions:
  • Write a program LotheryPrinter that picks a combination in a lottery. In this lottery, players can choose 6 numbers ( possibly r
    9·1 answer
  • An___ is a rectangular work area in the desk top that contains a program, text, files, it other data and tools.
    5·1 answer
  • How auto insurance companies manage risk?
    12·1 answer
  • how do i create an advanced search using the search criteria in the range K2:S3 and the inventory data where the results will be
    8·1 answer
  • Question 7 of 10
    13·1 answer
  • anyone here done intro to tech course on edgenuity yet? I failed the first unit test twice and it's prob gonna be a third if i r
    14·2 answers
  • Work-based learning can be defined as educational experiences that focus on
    11·1 answer
  • Write a program (using functions) starting from directives to compute and display the transpose of a matrix of dimension m x n.
    13·1 answer
  • Write a static generic method PairUtil.minmax that computes the minimum and maximum elements of an array of type T and returns a
    7·1 answer
  • Hahaahhaahahuahaahahhahqha
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!