Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the following problems. You are welcome to work in small groups for this assignment, but each student should submit their own work for grading,

Complete the following problems. You are welcome to work in small groups for this assignment, but each student should submit their own work for grading, and include everyones names in comments.

You will write two programs for this assignment, but the second will be a modification of the first. Be sure to save both versions so that you can demonstrate both and turn both files into Talon. Remember to include your name, the names of any collaborators, the date, and a quick description in comments at the top of both programs.

Write a complete Java program that performs the following steps:

First, ask the user to enter the lengths of two sides of a triangle (one length at a time), and then asks the user to enter the angle measured between the two sides.

With this information, your program should calculate the length of the third side of the triangle using the Law of Cosines. (In that equation below, a and b are the two side lengths, and is the angle between them assumed to be in degrees.)

Length=a2+b2-2abcos

Once the length is calculated, print the result to the screen. A good check to see if your program works at this point: If the user picks the two side lengths to be 11 units and 8 units, and the user picks the angle to be 37 degrees, the result should be a calculated third side length of approximately 6.6663 units.

Your output will probably show more digits than are listed here thats okay! If you get a significantly different value, the most common mistake to check for is if you forgot to convert the 37 degree input to Radians.

Once you are confident that your program is calculating the third side length correctly using the Law of Cosines, move on to part 2, but make sure to keep a copy of your code as it is right now, since youll need to demonstrate it to your instructor and turn it in on Talon.

Copy your code from part one into a new file so that you can make the following changes without losing your original code from part one (youll also need to give it a slightly different class name so that both can exist in the same project). Youll also demonstrate and turn in this file.

Create a Random object with the seed 4. (Hint: Random rg = new Random(4);)

Because we specified a seed for our Random object, we can know ahead of time what the random (actually pseudorandom) numbers will be.

For the first side length, generate a random integer value from 1 to 8 (including both 1 and 8) instead of asking the user for that side length. Print out this first side length (it should be 6).

Hint: By default, random ints will be given between 0 and the specified bound minus 1. Youll need to figure out how to modify this range of results to give values from 1 to 8.

For the second side length, generate a random integer value from 5 to 13 instead of asking the user for that side length. Print out this second side length (it should be 12).

For the angle between the two sides, generate a random decimal number from 5.0 to 85.0 degrees instead of asking the user for the angle. Print out this angle in degrees (it should be 78.497).

Hint: By default, random doubles will be given between 0.0 and 1.0. Youll have to figure out how to modify this range to the desired 5.0 to 85.0.

Your program should still print out the third side length, which should be about 12.29975.

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions