Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 9, Problem 9E

Explanation of Solution

Creating a class “RationalAssert.java”:

  • Import required package.
  • Define the class “RationalAssert”.
    • Declare the private variables “the_numerator”, and “the_denominator”.
    • Define parameterized constructor.
      • Assign “numerator” to “the_numerator”.
      • Assign “denominator” to “the_denominator”.
      • Create an assertion with the condition “assert the_denominator != 0”.
    • 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 RationalAssert

{

    //Declare required variables

    private int the_numerator;

    private int the_denominator;

    //Parameterized constructor

    public RationalAssert(int numerator, int denominator)

    {

        //Assign the value of numerator

        the_numerator = numerator;

        //Assign the value of denominator

        the_denominator = denominator;

        //Declare an assertion

        assert the_denominator != 0;

    }

    //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)

    {

        //Declare an assertion

        assert the_denominator != 0;

        //Assign the value

        the_denominator = denominator;

    }

 �...

Blurred answer
Students have asked these similar questions
solve and show the tree on paper
I need help to resolve the following activity
Modern life has been impacted immensely by computers. Computers have penetrated every aspect of oursociety, either for better or for worse. From supermarket scanners calculating our shopping transactionswhile keeping store inventory; robots that handle highly specialized tasks or even simple human tasks,computers do much more than just computing. But where did all this technology come from and whereis it heading? Does the future look promising or should we worry about computers taking over theworld? Or are they just a necessary evil? Provide three references with your answer.

Chapter 9 Solutions

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

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning