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
Use C++ Create a class called Fruit. Add one member variables name. Add only one getter function for the name. The get function returns name. Implement a constructor that expects name value and assigns it to the member variable. This class doesn't have an empty constructor. Create a subclass of Fruit named CitrusFruit. The CitrusFruit class has two member variables weight and color.  Add a constructor which expects weight and  name and color.Pass name to the base constructor and set weight and color to it's member variable. Write a program that has an array of  3 Fruits, and an array of 3 CitrusFruits. Feel free to give the name , weight and color to the object as your choice. Use loops to print out the array properties to the terminal screen.
Do the following program in Java Eclipse. Java Class that can be used to create a Fruit object as described below: A fruit has - a: - Date of Harvest -Color -Weight -Number of seeds a. Add all instance variables. b. The class must have getters and setters for all instance variables. c. The class must have two constructors, a no-args and a constructor that receives input for each instance variables. d. The parent class is abstract. e. its 1 abstract method and has toString() method f. its 2 children (concrete) also have toString() methods.
WRITE PLEASEJAVA write grading program for a class with the following grading policies. thers a total of 2 quizzes, each graded on the basis of 10 points. theeres  is 1 midterm exam and one final exam, each graded on the basis of 100 points. final exam counts for 50% of the grade, the midterm counts for 25%, and the 2 quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores.) letter grade will be given based on the following criterion: 90 – 100  A 80 – 89    B 70 – 79    C 60 – 69    D 0 – 59      E             program will read student’s scores from a txf file, save them in an arrayor arrays), process the arrays),  print the student’s record, which consists of the name, 2 quiz and 2 exam scores as well along with students avg numscore for the course and final letter rade.         please noteAll the scores are integers and a student name consists of no more than 10 characters. justify output file

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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education