1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mars1129 [50]
3 years ago
10

Write a program to convert a fraction to a decimal. Have your program ask for the numerator first, then the denominator. Make su

re to check if the denominator is zero. If it is, print out "Error - cannot divide by zero."
Computers and Technology
1 answer:
Anton [14]3 years ago
3 0
<h2>Answer:</h2>

import java.util.Scanner;

public class FractionToDecimal {

   public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       

       System.out.println("Please enter the numerator");

       double numerator = input.nextDouble();

       System.out.println("Please enter the denominator");

       double denominator = input.nextDouble();

       

       if(denominator == 0){

           System.err.println("ERROR - Cannot divide by zero.");

       }

       else {

           System.out.println("The result is " + (numerator/denominator));

       }

       

   }

   

}

<h2>Explanation:</h2>

// import the Scanner class to allow for user input

import java.util.Scanner;

// 1. Declare a class

public class FractionToDecimal {

   // 2. Write the main method

   public static void main(String[] args) {

       

       // 3. Create an object of the Scanner class called <em>input</em>

       Scanner input = new Scanner(System.in);

       

       // 4. Prompt the user to supply the numerator

       System.out.println("Please enter the numerator");

       

       // 5. Declare and initialize a variable <em>numerator </em>to hold the numerator

       // supplied by the user.

       // The numerator is of type double since the program does not

       // specify any. With a double both integer and floating point numbers

       // will be supported.

       double numerator = input.nextDouble();

       

       // 6. Prompt the user to enter the denominator

       System.out.println("Please enter the denominator");

       // 7. Declare and initialize a variable <em>denominator </em>to hold the

       // denominator supplied by the user.

       // The denominator is also of type double since the program does not

       // specify any. With a double, both integer and floating point numbers

       // will be supported.

       double denominator = input.nextDouble();

       // 8. Check if the denominator is or is not zero.

       // if it is zero, display an error message        

       if(denominator == 0){

           System.err.println("ERROR - Cannot divide by zero.");

       }

       // if it is not zero, then print out the result of the division

       else {

           System.out.println("The result is " + (numerator/denominator));

       }

       

   }                       // end of main method

   

}                            // end of class declaration

Please Note:

The code above has been written in Java.

The explanation segment contains comments to explain every line of the code.

But a few things are still worth noting;

i. Dividing the numerator by the denominator will convert a fraction to decimal.

ii. The object of the Scanner class <em>input </em> is used to get the inputs (numerator and denominator) from the user. Since the inputs are going to be integers or doubles, the nextDouble() method of the the Scanner class is used.

iii. If the denominator is zero, an error message will be displayed. I have used the System.err.println() method for that rather than the regular System.out.println() method. The difference is that the former will print out the error text in red color.

iv. Notice also that the else statement in the code will perform the division and also print out the result of the division along side with some text.

<em>Hope this helps!</em>

You might be interested in
Communication between a computer and a keyboard involves ______________ transmission.
4vir4ik [10]

Answer:

Simplex transmission

Explanation:

Communication between computer and keyboard involves which transmission? Answer: Simplex transmission requires communicating between a computer and a keyboard. The simple transmission & communication channel allows data from only one direction.

8 0
1 year ago
Examine the efficiency the various recovery algorithms used in deadlock handling
sineoko [7]

Solution:

The process of transaction can guarantee the reliability of business applications. Locking resources is widely used in distributed transaction management (e.g; two phase commit, 2PC) to keep the system consistent. The locking mechanism, however, potentially results in various deadlocks. In service oriented architecture, the deadlock problem becomes even worse because multiple transactions try to lock shared resources in the unexpectable way due to the more randomicity of transaction requests, which has not been solved by existing research results. In this paper, we investigate how to prevent local deadlocks, caused by the resource competition among multiple sub-transactions of a gl obal transaction, and global deadlocks from the competition among different global transactions. We propose a replication based approach to avoid the local deadlocks, and a timestamp based approach to significantly mitigate the global deadlocks. A general algorithm is designed for both local and global deadlock prevention. The experimental results demonstrate the effectiveness and efficiency of our deadlock prevention approach. Further, it is also proved that our approach provides higher system performance than traditional resource allocation schemes.

This is the required answer.

4 0
3 years ago
Memorex Disks sells computer disk drives with right-of-return privileges. Returns are material and reasonably predictable. Memor
pychu [463]

Memorex should: iv. record a refund liability in the year of the sale.

<h3>What is a right-of-return privilege?</h3>

A right-of-return privilege can be defined as a special right, advantage or entitlement that is accorded to a customer, which avails them an opportunity to return a product they have purchased.

Since Memorex Disks offers its customers right-of-return privileges, it is expected that it should record a refund liability in the year of the sale i.e recording an allowance for sales returns in the year the sale was made.

Read more on right-of-return privilege here: brainly.com/question/17165436

#SPJ1

5 0
2 years ago
Indentation is useful to make the document easier to read. To increase the indentation of the paragraph, you press the increase
jeka94

Answer:

The correct answer to this question is given below in the explanation section.

Explanation:

The correct answer is Home.

Indentation is useful to make the document easier to read. To increase the indentation of the paragraph, you press the increase indentation in the   <u>Home</u> tab.

you can increase/ decrease indentation in Home tab under the Paragraph groups of command.

Othe options are not correct because:

View tab has settings related to how the document looks like. Insert tab has settings related to the insertion of image, shape, pages, tables, illustration, and links, etc into a document. The review tab allows you to review the document with different available settings.

4 0
3 years ago
What color is excel?​
Eduardwww [97]

Answer:

green

Explanation:

5 0
2 years ago
Read 2 more answers
Other questions:
  • Define a function setheight, with int parameters feetval and inchesval, that returns a struct of type heightftin. the function s
    6·1 answer
  • Write a function named times_ten. the function should accept an argument and display the product of its argument multiplied time
    13·1 answer
  • How is the cia triad used to evaluate encryption methods?
    6·1 answer
  • Charles would like to move his internet browser window so that he can see his desktop.He should
    5·1 answer
  • Most hand sewing begins and ends with
    5·1 answer
  • Quick!!!!!
    13·2 answers
  • What is professional education? <br><br><br><br><br>Please help me to do this.​
    7·2 answers
  • A group of two or more computer systems linked together via communication devices is called:.
    10·1 answer
  • How does Virtual Reality help to make work experiences more inclusive?
    13·1 answer
  • Hypertext enables you to navigate through pieces of information by clicking the __________, that connect them.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!