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;
}
�...
Want to see the full answer?
Check out a sample textbook solutionChapter 9 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- Use java and use proper code indentation.arrow_forwardWrite C# equivalent statements for the following: An “Account” class will be created having properties: accountName, accountNumber, accountType, totalBalance and methods: WithdrawAmount(), CheckBlance(), DepositAmount(). Derive child classes, that is, “SavingAccount” and “CurrentAccount” from the Account class and implement the following functionality. While taking input from user, check whether the account type is Saving or Current. If user enters “Saving”, an object of Saving Account will be instantiated and while depositing amount in the account an extra 3% of the amount will be deposited (as an extra profit) with the actual amount entered by user. If user enters “Current”, an object of Current Account will be instantiated and while depositing amount in the account, no extra amount will be deposited. Only the actual amount will be deposited. Also implement all the methods mentioned above.arrow_forwardlanguage is c++ sample output included with user input in boldarrow_forward
- Solve this program in C++ and attach the screenshot of output also. Solve this ASAParrow_forwardDefine a new "Exam" class that manages the exam name (string) and its score (integer). For example, an exam can have - "Midterm Exam", 100 - "Final Exam", 50 The class must not provide the default constructor. It must require the exam name and score in order to initialize the Exam object. The class must provide only the following methods (no more and no less): - isPerfect method that returns true if the score is exactly 100 and false otherwise. - isPassing method that returns true if the score is equal or greater than 70 and false otherwise. - toString method must return all the exam information including the result of the exam as a string in the following format: EXAM(<name>) SCORE(<score>) RESULT(Pass/Fail) such asEXAM(Midterm Exam) SCORE(100) RESULT(Pass) EXAM(Final Exam) SCORE(50) RESULT(Fail) "Pass" means the score is greater or equal 70. "Fail" is whenever the score is below 70. - isGreater method that compares with another Exam object and return true if the score…arrow_forward82. Write a class definition for a class named Fraction that contains two integer fields named numerator and denominator. Include in the class a prototype for a method (function) named add that takes two Fraction objects as input arguments and returns a Fraction object as output. You do not need to provide an implementation of the add method.arrow_forward
- Help of what these errors mean. In C# • Create a Class, named Student, to hold properties of Student Last Name, Student First Name, Student ID (9 digits), Course Prefix and Number, and the tests (Test 1, Test 2, Test 3, Test 4). Create appropriate setter and getter accessors, and constructors. Use access modifiers. Example: First Name : Pat Last Name : Smythe Student ID : ABC111333 Course Prefix : CIST Course Name : 2431 Test 1 : 100 Test 2 : 90 Test 3 : 80 Test 4 : 88 • Prompt the user for the Student Last and First Name, Student ID, Course Prefix and Number and the tests. • Include at least one exception handling function. • Use an array to store the 4 test grades. • Use a looping structure to populate the array. • Calculate the numeric average based upon the 4 equally-weighted numeric grades. • Display all the data for each of student using a looping structure. • Display the numeric average for each student. • Create a function that will convert the numeric average to a…arrow_forwardSolve this Program in C++ And attach the screen shot of the output. Solve this ASAParrow_forwardINSTRUCTIONS: Write a C++ script/code to do the given problem. Write a class called profileID, which has data members firstName,lastName, age, birthday and ageCompany (the age when you entered in the company). Remember to use set and get methods to access the data members this time. Also, write another class called bonusAward that has a method getBonus()with arguments yos and etype which are both integer data types. This method calculates the bonus received by an employee using this formula: yos*1000 + etype*1000. Write two derived classes, ASE and SE, using multiple inheritance usingprofileID and bonusAward as parent classes. Both classes must have amethod named getyos()that returns the yos of an employee using the formula age–ageCompany; and a method named getetype() which returns a constant based on the employee type. For ASE, the constant is 10 while for SE that constant is 20. Last, write a main program where you instantiate ASE as employee1 and SE as employee2. Get their…arrow_forward
- Pythonarrow_forwardproblem statement: Write a java classStringCheckto do the below given checks on accepted string or strings. Each function should be coded in separate methods of the class. Give appropriate instance variables to implement the method. The user should be able to enter the string through the main function in Main class. Use a constructor to initialize the String entered by the user. Use the Main class to test all the methods in StringCheckclass. The programs should have the below given checklist: 1)Define classStringCheck with required instance variables 2)The StringCheck class should have six methods to do the below functions: *Check if the user entered string is a simple sentence? (Starts with capital letter, Ends with period, space between words). *Check if the user entered string is a question? (Check if the string starts with ac apital letter ends with a question mark, space between words) *Check if the user entered string have numbers in it? *Check if string is a valid email *Check…arrow_forwardUse the definition of the class productType to answer the questions a,b,c,d, and e pictured below. *class productType is also pictured below *Everything is in C++arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning