bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 9, Problem 8E

Explanation of Solution

Creating a class "Rational.java":

  • Import required package.
  • Define the class "Rational".
    • Declare the private variables "the_numerator", and "the_denominator".
    • Define parameterized constructor.
      • Assign "numerator" to "the_numerator".
      • Check if the value of "denominator" is equal to 0.
        • Throw "Arithmetic Exception".
      • Assign "denominator" to "the_denominator".
    • Give mutator methods to set numerator and denominator.
    • Give accessor methods to get the value of numerator and denominator.
    • Give function definition for "value ()".
      • Return the value produced by "the_numerator / the_denominator".
    • Given function "toString ()".
      • Return the string "the_numerator / the_denominator".
    • Define the "main ()" method.
      • Create an object for "Scanner" class.
      • Declare the variables "n", and "d".
      • Get the numerator and denominator from the user.
      • Call the constructor by passing "n", and "d".
      • Call the function "value".
      • Call the function to get the numerator and denominator.
      • Print new line.

Program:

Rational.java:

import java.util.Scanner;

//Define a class

public class Rational

{

//Declare required variables

private int the_numerator;

private int the_denominator;

//Parameterized constructor

public Rational(int numerator, int denominator)

{

//Assign the value of numerator

the_numerator = numerator;

//check if the value is equal to 0

if(denominator == 0)

//Throw an exception with a message

throw new ArithmeticException("Denominator of rational is zero");

//Assign the value of denominator

the_denominator = denominator;

}

//Function to set the value of numerator

public void setNumerator(int numerator)

{

//Set the value

the_numerator = numerator;

}

//Function to set the denominator

public void setDenominator(int denominator)

{

//Check if the value of denominator is equal to 0

if(denominator == 0 )

//Throw an exception

throw new ArithmeticException("Denominator of rational is zero");

...

Blurred answer
Students have asked these similar questions
You are tasked with developing a portable system that can be worn to collect health and fitness data. The challenge is to integrate all functions into the smaller form of an ear clip. The device should include heart rate, movement and temperature sensor and wireless communication with a mobile app. Draw a diagram- hardware architecture of the system- including the selection of suitable sensors, communication modules, and an energy-efficient microcontroller. (visualize the components and their connections)
Draw out an example of 3 systems using Lamport’s logical clock and explain the steps in words.
"Systems have become very powerful and sophisticated, providing quality information fordecisions that enable the firm to coordinate both internally and externally."With reference to the above statement compare the operations of any three data gatheringsystems today’s organisations use to aid decision making.

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Chapter 9.1, Problem 11STQ Chapter 9.1, Problem 12STQ Chapter 9.1, Problem 13STQ Chapter 9.1, Problem 14STQ Chapter 9.2, Problem 15STQ Chapter 9.2, Problem 16STQ Chapter 9.2, Problem 17STQ Chapter 9.2, Problem 18STQ Chapter 9.2, Problem 19STQ Chapter 9.2, Problem 20STQ Chapter 9.2, Problem 21STQ Chapter 9.2, Problem 22STQ Chapter 9.2, Problem 23STQ Chapter 9.3, Problem 24STQ Chapter 9.3, Problem 25STQ Chapter 9.3, Problem 26STQ Chapter 9.3, Problem 27STQ Chapter 9.3, Problem 28STQ Chapter 9.3, Problem 29STQ Chapter 9.3, Problem 30STQ Chapter 9.3, Problem 31STQ Chapter 9.3, Problem 32STQ Chapter 9.3, Problem 33STQ Chapter 9.3, Problem 34STQ Chapter 9.3, Problem 35STQ Chapter 9.4, Problem 36STQ Chapter 9.4, Problem 37STQ Chapter 9.4, Problem 38STQ Chapter 9, Problem 1E Chapter 9, Problem 2E Chapter 9, Problem 3E Chapter 9, Problem 4E Chapter 9, Problem 5E Chapter 9, Problem 6E Chapter 9, Problem 8E Chapter 9, Problem 9E Chapter 9, Problem 10E Chapter 9, Problem 11E Chapter 9, Problem 12E Chapter 9, Problem 13E Chapter 9, Problem 1P Chapter 9, Problem 2P Chapter 9, Problem 3P Chapter 9, Problem 2PP Chapter 9, Problem 3PP Chapter 9, Problem 7PP Chapter 9, Problem 10PP Chapter 9, Problem 11PP

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
The expression for material removal rate for drilling.

Degarmo's Materials And Processes In Manufacturing

Show that the force of the circular motion is, F=mv2R.

Thinking Like an Engineer: An Active Learning Approach (4th Edition)

By discussing the difference between an error and a residual.

Elementary Surveying: An Introduction To Geomatics (15th Edition)

When a data needs to be used for a program later, the data can be stored in the form of file. The data present ...

Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    Text book image
    C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781305480537
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Programming with Microsoft Visual Basic 2017
    Computer Science
    ISBN:9781337102124
    Author:Diane Zak
    Publisher:Cengage Learning
    Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s; License: Standard YouTube License, CC-BY