Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1. RightTriangle.java (right triangle) Write a program to enter the two sides, a and b, of a right triangle from keyboard, calculate its area

Problem 1. RightTriangle.java (right triangle) Write a program to enter the two sides, a and b, of a right triangle from keyboard, calculate its area and perimeter.

(1)The area is defined as ab.

(2)The perimeter is defined as the sum of three edges: two sides plus the hypotenuse.

(3)The hypotenuses is calculated by

(4)Print out the area and perimeter of this right triangle.

Problem 2. Sum.java: Enter a series of ints (-1 to stop) and sum up all the numbers that can be divided by 3, that is, the remainder of that number divided by 3 is zero. Print out the total.

For example: given the following input:

Enter an int (-1 to stop): -1

Output for the above input:

The sum is 0.

Another instance of running can be:

Enter an int (-1 to stop): 6 (return key)

Enter an int (-1 to stop): 3 (return key)

Enter an int (-1 to stop): 2 (return key)

Enter an int(-1 to stop): -1 (return key)

Output for the above inputs:

The sum is 9.

Problem 3. Game.java:

(1)Ensure user to enter an integer in [1, 6] from the keyboard, that is, an integer from 1 to 6. Note that if a user enters an integer other than 1, 2, 3, 4, 5, 6, your program would force the user to re-enter again.

(2)Afterwards, let computer generate a random integer in [1, 6]. Print it out. To generate a random int, you may use Random class or random method of Math class.

(3)If the user and computer generate the same integer, print out a tie; otherwise, if the users input and the computers number add up to 9, print out user wins; otherwise, if the computers number and the users input add up to 5 or 7, print out computer wins; otherwise, print out undecided.

For example, suppose the user inputs 2 and the computer generates 3, then the result is computer wins. Suppose the user inputs 6 and the computer generates 3, then the result is user wins. Suppose the user inputs 2 and the computer generates 2, then the result is tie. Suppose the user inputs 2 and the computer generates 1, then the result is undecided.

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions