Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You may use any of the techniques described in the textbook in Chapters 13. Specifically, you may not use conditional statements in any of these

image text in transcribedimage text in transcribedimage text in transcribed

You may use any of the techniques described in the textbook in Chapters 13. Specifically, you may not use conditional statements in any of these programs. The purpose of this lab is to better understand Java's mathematical operators. All the requirements of this lab can be met by the clever application of these mathematical operators. Housekeeping This assignment has four parts. You should write four small Java programs, with each program addressing one of the parts. You can create a single Eclipse project (possibly named Lab02) and add four Java classes to the project, or you may create four separate projects, each containing their own single Java class. Use the java. util. Scanner console input stream object when user input is required. Choose your variable names thoughtfully. The names you choose should reflect their purpose within the program. For example, don't use the name x (a popular variable name in algebra class) when the name seconds would better represent the purpose of a variable participating in a time calculation. What to do 1. Midpoint Calculation In mathematics, you can compute the midpoint between the two points (x1,y1) and (x2,y2) with the following formula: (2x1+x2,2y1+y2) Write a Java program that allows the user to enter the coordinates of two points (x1,y1), and (x2,y2). The variables for the coordinates should be of type doubleprecision floating-point. The program then should compute and print the midpoint. A sample run of the program produces Please enter the coordinates of the two points (x1,y1,x2,y2):0011 The midpoint of (0.0,0.0) and (1.0,1.0) is (0.5,0.5) The user literally enters the "0 011, " and the program prints the rest. Your program should use floating-point arithmetic for its computation. 2. Hours, Minutes, Seconds to Seconds Write a Java program that receives three integer values from the user. These three integer values represent respectively hours, minutes, and seconds. The program should display the total number of seconds represented by this time value. For example, if the user enters the values 312 and 50 , the program would print 11570 . The following shows a sample execution of the program: Please enter hours, minutes, and seconds: 31250 That is 11570 seconds Here the user enters the "3 1250 ," and the program prints everything else. Use only integer (int) variables and literals to solve this problem. Seconds to hours, minutes, seconds Write a Java program that does the reverse of the previous problem. Your program should request a single integer value from the user. This integer represents some number of seconds. The program should display the number of hours, minutes, and seconds that correspond to the exact time expressed by the number of seconds the user entered. For example, the following shows a sample run where the user enters 11570: Please enter the total number of seconds: 11570 That is 3hrs12min50sec Again, use only integer (int) variables and literals to solve this problem. Hint: A good way to solve this problem is to use the division (/) and modulus () operators in succession to pare off progressively the higher time units. ExerciseComputer The following table lists the Calorie contents of several foods at a popular fast-food restaurant: Also, running or walking burns off about 100 Calories per mile. Write a Java program that requests three values from the user: the number of bean burritos, salads, and shakes consumed (in that order). The program then should display the number of miles that a person must run or walk to burn off the Calories represented by that quantity of food. The program should run as follows (the user types in the 21): How many bean burritos, bowls of salad, and milkshakes did you consume? 321 You ingested 1829 Calories 4. ExerciseComputer The following table lists the Calorie contents of several foods at a popular fast-food restaurant: Also, running or walking burns off about 100 Calories per mile. Write a Java program that requests three values from the user: the number of bean burritos, salads, and shakes consumed (in that order). The program then should display the number of miles that a person must run or walk to burn off the Calories represented by that quantity of food. The program should run as follows (the user types in the 211 ): How many bean burritos, bowls of salad, and milkshakes did you consume? 321 You ingested 1829 Calories You will have to run 18.29 miles to expend that much energy

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions