Concept explainers
Explanation of Solution
Program:
The earthquake program is as follows:
File name: “Earth.java”
//Create a class
public class Earth
{
//Declare the variable
private double mag;
//Define the constructor
public Earth(double magnit)
{
//Assign the magnitude value
mag = magnit;
}
//Define a method "getDesc()"
public String getDesc()
{
//Declare the variable for magnitude description
String desc;
/*Check whether the value of magnitude is greater than or equal to "8.0" */
if (mag >= 8.0)
{
//Assign the description
desc = "Most structures fall";
}
/*Check whether the value of magnitude is greater than or equal to "7.0" */
else if (mag >= 7.0)
{
//Assign the description
desc = "Many buildings destroyed";
}
/*Check whether the value of magnitude is greater than or equal to "6.0" */
else if (mag >= 6.0)
{
//Assign the description
desc = "Many buildings considerably damaged, some collapse";
}
/*Check whether the value of magnitude is greater than or equal to "4.5" */
else if (mag >= 4...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Big Java Late Objects
- 21. Draw the flowchart for a program that reads the value of integer x and prints the message "Positive" if x>0, otherwise the program prints the message "Negative" if x<0.arrow_forwardWhat is the output of the following program? (6) #includeiostreamusingnamespacestd;voidfunc1();voidfunc2();intmain()intnum;coutEnter1or2:;cinnum;coutendl;coutTake;if(num1)func1();elseif(num2)func2();elsecoutInvalidinput.Youmustentera1or2endl;return0;voidfunc1()coutProgrammingI.endl;voidfunc2()coutProgrammingII.endl; What is the output if the input is 1? What is the output if the input is 2? What is the output if the input is 3? What is the output if the input is -1?arrow_forwardWrite a program that displays four clocks, as shown in Figure 12.24.arrow_forward
- Write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula isarrow_forwardWhat is the output produced by the given lines? The variables are type character a=("b"); b=("c"); c=a; printf (" %c %c %c c", a,b,c);arrow_forwardWrite a program which takes an input from the user, if the input is 1, calculate the area of the circle, if the input is 2 calculate the area of Rectangle, if input is 3 calculate the area of the square, otherwise display "Wrong Input".arrow_forward
- Write a program to print the pattern shown.arrow_forward26. Draw the flowchart for a program that reads the value of integer x and prints "Positive" if x>0, otherwise the program prints the message "Negative" if x<0.arrow_forwardWhat will the follow program print? Write your answer in the online text box. num1 = 5 num2 = num1 + 3 print (num1, num2) print (num1 % 3) str1 = str(num2)arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning