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
Q4: Consider the following MAILORDER relational schema describing the data for a mail order company. (Choose five only). PARTS(Pno, Pname, Qoh, Price, Olevel) CUSTOMERS(Cno, Cname, Street, Zip, Phone) EMPLOYEES(Eno, Ename, Zip, Hdate) ZIP CODES(Zip, City) ORDERS(Ono, Cno, Eno, Received, Shipped) ODETAILS(Ono, Pno, Qty) (10 Marks) I want a detailed explanation to understand the mechanism how it is Qoh stands for quantity on hand: the other attribute names are self-explanatory. Specify and execute the following queries using the RA interpreter on the MAILORDER database schema. a. Retrieve the names of parts that cost less than $20.00. b. Retrieve the names and cities of employees who have taken orders for parts costing more than $50.00. c. Retrieve the pairs of customer number values of customers who live in the same ZIP Code. d. Retrieve the names of customers who have ordered parts from employees living in Wichita. e. Retrieve the names of customers who have ordered parts costing less…
Q4: Consider the following MAILORDER relational schema describing the data for a mail order company. (Choose five only). (10 Marks) PARTS(Pno, Pname, Qoh, Price, Olevel) CUSTOMERS(Cno, Cname, Street, Zip, Phone) EMPLOYEES(Eno, Ename, Zip, Hdate) ZIP CODES(Zip, City) ORDERS(Ono, Cno, Eno, Received, Shipped) ODETAILS(Ono, Pno, Qty) Qoh stands for quantity on hand: the other attribute names are self-explanatory. Specify and execute the following queries using the RA interpreter on the MAILORDER database schema. a. Retrieve the names of parts that cost less than $20.00. b. Retrieve the names and cities of employees who have taken orders for parts costing more than $50.00. c. Retrieve the pairs of customer number values of customers who live in the same ZIP Code. d. Retrieve the names of customers who have ordered parts from employees living in Wichita. e. Retrieve the names of customers who have ordered parts costing less than$20.00. f. Retrieve the names of customers who have not placed…
ut da Q4: Consider the LIBRARY relational database schema shown in Figure below a. Edit Author_name to new variable name where previous surname was 'Al - Wazny'. Update book_Authors set Author_name = 'alsaadi' where Author_name = 'Al - Wazny' b. Change data type of Phone to string instead of numbers. عرفنه شنو الحل BOOK Book id Title Publisher_name BOOK AUTHORS Book id Author_name PUBLISHER Name Address Phone e u al b are rage c. Add two Publishers Company existed in UK. insert into publisher(name, address, phone) value('ali','uk',78547889), ('karrar', 'uk', 78547889) d. Remove all books author when author name contains second character 'D' and ending by character 'i'. es inf rmar nce 1 tic عرفته شنو الحل e. Add one book as variables data? عرفته شنو الحل

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