Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task In this case program name is MathExpressions which is the name of the class and file of this program. In the corresponding space in

Task

In this case program name is MathExpressions which is the name of the class and file of this program.

In the corresponding space in the coding template, translate the following expressions into Java and print the results:

For A-E you will be using four variables a-d and they will be of type int:

A. resultA = a + b - c / 15 B. resultB = 2 / 3 - 2 + 5 + d C. resultC is equal to the difference between results of A and B D. resultD is equal to the area of a rectangle if the side lengths are equal to the results of A and C E. resultE is equal to the average of results A-D 

For F-J repeat A-E but using four variables e-h of type double (the only difference is the .0s added to the numbers):

F. resultF = e + f - g / 15.0 G. resultG = 2 .0/ 3.0 - 2.0 + 5.0 + h H. resultH is equal to the difference between results of F and G I. resultI is equal to the area of a rectangle if the side lengths are equal to the results of F and H J. resultJ is equal to the average of results F-I 

We can compare the differences between the outputs. Use your intuition to determine which set of numbers (int or double) makes more sense for which cases.

Also take notice of the format of the MathExpression.java file. Starting from the top, there are import statements, the class header, the main() header, and the code belonging to main().

The code to create the Scanner is also important to familiarize yourself with. It was provided for you this time, but next lab you will be responsible for coding it if you need user input.

image text in transcribed

image text in transcribed

learn.zybooks.com + D 8.12 Lab 3d: GeometryPointDistance Instructions Write a program prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance The formula for computing the distance between two points is d=1/(x2 2l)+ (y2 yl)?. Use Math.pow(). For example, you would use Math. powla, 0.5) to compute va Here is a sample of the program at runtime. *Note: the values entered are shown under the prompt but are not actually part of the output of the program. Erter first point as numberl rumber2 on one line: -1.1 -4.9 Enter second point as number3 number on one lire: 6.2 Distance between points is: 10.97862 Choosing test values The sample run above using +/- fractional values. This is not as easy to test while the program is under development. A better set of test values is easy to type (you will enter these values multiple times) easy to calculate when done quickly by hand Choosing values that form a horizontal or vertical line makes calculating distance simple. For yamnle distance bet 21 and 1 51 i 2 On the program pretlanutee the value onto test other mainte 0 learn.zybooks.com U + D Choosing test values The sample run above using +/- fractional values. This is not as easy to test while the program is under development. A better set of test values is: easy to type you will enter these values multiple times) easy to calculate when done quickly by hand Choosing values that form a horizontal or vertical line makes calculating distance simple. For example, distance between (1, 3) and (1, 5) is 2. Once the program correctly computes this value, go on to test other points. 204400.1909192 LAB ACTIVITY 8.12.1: Lab 3d: GeometryPointDistance 0/10 GeometryPointDistance.java Load default template... 1 // header comments 2 3 // Scanner import 4 5 public class GeometryPointDistance { 5 7 // main 8 9 // Get four numbers for point coordinates 10 11 // Compute distance 12 13 // Print distance using printf() 14 System.out.printf("Distance between points is 2.5f ", '* FIXME: distance variable goes here */); 15 16 } Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box Enter program input (optional)

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

2. How were various roles filled?

Answered: 1 week ago