Question: answer the following with java and python implementation Use this for testing Requirements / specification Create a class named Rational. Follow each language's rules and

answer the following with java and python implementationanswer the following with java and python implementation Use this for testing

Use this for testingRequirements / specification Create a class named Rational. Follow each language's rules

Requirements / specification Create a class named Rational. Follow each language's rules and conventions to name your source files Python.java and python.py respectively. Your class must have: the name Rational a constructor (initializer) that takes two integers as its parameters. a method named equals that takes another Rational as its parameter and returns true if you can determine that the two Rationals are equal; false otherwise. Your class must specify the data type of the following values, replacing "type" with the name of the type (int, boolean, bool, or Rational): Java syntax (won't compile if omitted) Python PEP 484 syntax (lose points if omitted!) method's return type (not used for constructors) type method_name(...) {...} def method_name(...) -> type: parameter type method_name(type parameter, ...])...) ... method_name(parameter: type, ...])... type of property/field of class type property_name; (not needed this exercise) In these syntax examples, an ellipsis ... means some arbitrary amount of code goes there (possibly none), square brackets ll mean something is optional, and bold italic is just for emphasis. method_name, parameter, and type all need to be replaced with appropriate names. Java requires these declarations. In Python, type hints are syntactically optional and have no semantics (they don't affect the running of the program). Nevertheless, I expect you to use them because they help you communicate with other developers and avoid making mistakes. Do as little as possible to satisfy those requirements! Do not (yet) implement any error/bounds checking; don't worry about encapsulation (public/private); don't reduce the Rational to its canonical form, provide accessors or string representations, mathematical operations, or any of those very appropriate good things to do. You don't even have to write comments. We'll get there! Testing Python: place the following code at the bottom of your file starting at the left margin (the if line must not be indented), so you can run the file and make sure it works: if name main ! rational12 = Rational(1, 2) rational23 = Rational(2,3) print("Test rational12 equals another Rational(1,2):", "passed" if rational12.equals(Rational(1, 2)) else "failed") print("Test rational12 not equals rational23:", "passed" if not rational12.equals(rational23) else "failed") (There are five lines, beginning with if, and then indented: rational12, rationas123, print and print. The word wrap may add line breaks that cannot be in the code.) Java: insert the following method within your class definition (before the closing curly brace; it can be indented or not) so you can run the file: public static void main(String[] args) { Rational rational12 = new Rational(1, 2); Rational rational23 = new Rational(2, 3); System.out.println("Test rational12 equals another Rational(1,2): " + (rational 12.equals(new Rational(1, 2)) ? "passed" : "failed")); System.out.println("Test rational12 not equals rational23: " + (! rational12.equals(rational23) ? "passed" : "failed")); } (In Java, the linebreaks don't matter; I moved the bit after each + to the next line because the lines were getting too long)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!