Write declarations for storing the following quantities. Choose between integers and floating-point numbers. Declare constants when appropriate.
- a. The number of days per week
- b. The number of days until the end of the semester
- c. The number of centimeters in an inch
- d. The height of the tallest person in your class, in centimeters
a.
Explanation of Solution
Declaration for the first statement:
- The given statement is “The number of days per week”.
- Totally, there are seven days in a week and there is no change of days in a week.
- Hence, the number of days in a week is fixed forever.
- The declaration for storing the number of days in a week is as follows:
/* Declaration for storing the number of days in a week */
public static final int DAYS_PER_WEEK = 7;
b.
Explanation of Solution
Declaration for the second statement:
- The given statement is “The number of days until the end of the semester”.
- The number of days in a semester varies from time to time and the days may either increase or decrease based on the semester time-table.
- Hence, the number of days in a semester is an integer variable.
- The declaration for storing the number of days in a semester is as follows:
/* Declaration for storing the number of days in a semester */
public int daysInSemester;
c.
Explanation of Solution
Declaration for the third statement:
- The given statement is “The number of centimeters in an inch”.
- The number of centimeters in an inch is a fixed type of float value.
- The declaration for storing the number of centimeter in an inch is as follows:
/* Declaration for storing the number of centimeters in an inch */
public static final float CENTIMETERS_IN_INCH = 2.54;
d.
Explanation of Solution
Declaration for the fourth statement:
- The given statement is “The height of the tallest person in your class, in centimeters”.
- The height of the tallest person in a class is a float value since height contains decimal values.
- The height of a person varies over time.
- Hence, the height of a person is not fixed and it is float type value.
- The declaration for storing the height of the tallest person in a class is as follows:
/* Declaration for storing the height of the tallest person in a class*/
public float tallestHeight;
Want to see more full solutions like this?
Chapter 2 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Data Mining for Business Analytics: Concepts, Techniques, and Applications with XLMiner
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: Early Objects (6th Edition)
Java How To Program (Early Objects)
Problem Solving with C++ (9th Edition)
- Declare int variables x and y. Initialize x to 25 and y to 18.arrow_forwardDo this question: Write the following statements in symbolic form using the symbols ~, and and the indicated letters to represent the component statements. 1. DATAENDFLAG is off but ERROR is not equal to 0. (Note: p = the statement “DATAENDFLAG is off,” q= the statement “ERROR equals 0) 2. Either this polynomial has degree 2 or it has degree 3 but not both. (Note: n = “This polynomial has degree 2,” k = “This polynomial has degree 3”)arrow_forwardThe formula below decribes Newton's second law of motion Force = Mass x acceleration Using the variables below Write one line of code that will calculate the acceleration of a object. // Mass in Kg float mass = 50.3; // Froce in N int force = 720; //acceleration float accel; //One line of code to calculate temperature in Kelvin the acceleration of a objectarrow_forward
- The following equation estimates the average calories burned for a person when exercising, which is based on a scientific journal article (source): Calories = ( (Age x 0.2757) + (Weight x 0.03295) + (Heart Rate x 1.0781) — 75.4991 ) x Time / 8.368 Write a program using inputs age (years), weight (pounds), heart rate (beats per minute), and time (minutes), respectively. Output the average calories burned for a person. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print('Calories: {:.2f} calories'.format(calories)) Ex: If the input is: 49 155 148 60 then the output is: Calories: 736.21 calories ''' Calories = ((Age x 0.2757) + (Weight x 0.03295) + (Heart Rate x 1.0781) — 75.4991) x Time / 8.368 ''' ''' Type your code here. '''arrow_forwardThe following equation estimates the average calories burned for a person when exercising, which is based on a scientific journal article (source): Calories = ( (Age x 0.2757) + (Weight x 0.03295) + (Heart Rate x 1.0781) — 75.4991 ) x Time / 8.368 Write a program using inputs age (years), weight (pounds), heart rate (beats per minute), and time (minutes), respectively. Output the average calories burned for a person. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print(f'calories: {calories:.2f} calories') Ex: If the input is: 49 155 148 60 then the output is: Calories: 736.21 caloriesarrow_forwardThe following equation estimates the average calories burned for a person when exercising, which is based on a scientific journal article (source): Calories = ( (Age x 0.2757) + (Weight x 0.03295) + (Heart Rate x 1.0781) — 75.4991 ) x Time / 8.368 Write a program using inputs age (years), weight (pounds), heart rate (beats per minute), and time (minutes), respectively. Output the average calories burned for a person. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print(f'Calories: {calories:.2f} calories')arrow_forward
- Write in symbolic form:For all integers x,there exists an integer y such that the sum of x and y equals 0.Write in symbolic form:arrow_forwardSuppose you have a certain amount of money in a savings account that earns compound monthly interest, and you want to calculate the amount that you will have after a specific number of months. The formula, which is known as the future value formula, is:F=P×(1+i)tThe terms in the formula are as follows:o F is the future value of the account after the specified time period.o P is the present value of the account.o i is the monthly interest rate.o t is the number of months.Write a program that prompts the user to enter the account’s present value, monthly interest rate, and the number of months that the money will be left in the account. The program should pass these values to a function named futureValue that returns the future value of the account, after the specified number of months. The program should display the account’s future value. i attached the screenshot of the output so the output should look like that.arrow_forwardEnter the year in two epochs, determine the leap year during this period, and print ten years each on the output. Please write it as a function, the parameter you pass is the year of the two epochs. The format of the output result is the same. In Javaarrow_forward
- 20.If A, B, and C are Boolean variables, which of the following statements are correct?a) A ∧ (B ∨ C) = (A ∧ B) ∨ (A ∧ C)b) A ∨ (B ∧ C) = (A ∨ B) ∧ (A ∨ C)c) (A ∧ B) ∨ C = C ∨ (B ∧ A)arrow_forwardThe correct declaration statement is: int X; Y; int X, Y; int X, Y int X, Y,arrow_forward1. What is the value of x and y for the following code: int y = 10; int x = ++y;arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning