Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm in java one and i need help with this program. please follow the directions. I will appreciate your help. thank you. Programming Concepts 1.

I'm in java one and i need help with this program. please follow the directions. I will appreciate your help. thank you.

Programming Concepts

1. Methods 2. do-whileorwhileloop

Assignment Description

You will write a program that converts a fraction to a decimal.

To do this, you must ask the user to input the numerator and denominator, and you will calculate and print out the result.

You must implement the following methods:

The main method

A method to get the numerator

A method to get the denominator

A method to calculate the result

A method to print the result

Assignment Requirements

You must write five total methods: the main() method, plus four more, to complete the program.

Use nextDouble() to get a double from user input.

You must print out the result up to three numbers after the decimal point.

You must re-prompt the user if the denominator is 0.

Assignment Suggestions

1. The main() method a. Declare three variables:

i. double numerator: to store the numerator ii. double denominator: to store the denominator

iii. double result: to store the result of numerator / denominator

b. Call the method getNumerator() and store it into numerator

c. Call the method getDenominator() and store it into denominator

d. Call the method calculateResult() and store it into result, passing in the values of numerator and denominator as arguments

e. Call the method printResult(), passing in result as its argument

2.getNumerator()Noparameters

a.Prompt the user to enter in the numerator

b.Get the number from the user, and store it into a double

c.Return the number (a double)

3. getDenominator()Noparameters

a. Prompt the user to enter in the denominator

b. Get the number from the user, and store it into a double

c. Return the number (a double)

4. calculateResult()Takesintwoparameters,thenumerator(adouble),andthedenominator (a double)

a. Divide the two numbers and store it into a double

b. Return the result (a double)

5. printResult()Takesinoneparameter,theresult(adouble)

a. Print out the result

sample output

user@loki:~$ java Fraction

Enter the numerator: 2

Enter the denominator: 5

The decimal value is 0.400

user@loki:~$ java Fraction

Enter the numerator: 10

Enter the denominator: 5

The decimal value is 2.000

user@loki:~$ java Fraction

Enter the numerator: 1

Enter the denominator: 3

The decimal value is 0.333

user@loki:~$ java Fraction

Enter the numerator: 5

Enter the denominator: 0

Enter the denominator: 0

Enter the denominator: 1

The decimal value is 5.000

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 And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago