(Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a
a) Add two Rational numbers: The result of the addition should be stored in reduced form. Implement this as a static method.
b) Subtract two Rational numbers: The result of the subtraction should be stored in reduced form. Implement this as a static method.
c) Multiply two Rational numbers: The result of the multiplication should be stored in reduced form. Implement this as a static method.
d) Divide two Rational numbers: The result of the division should be stored in reduced form. Implement this as a static method.
e) Return a String representation of a Rational number in the form a/b, where a is the numerator and b is the denominator.
f) Return a String representation of a Rational number in floating-point format. (Consider providing formatting capabilities that enable the user of the class to specify the number of digits of precision to the right of the decimal point.)
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Can I get help writing this with these parameters To give you an idea of the general criteria that will be used for grading, here is a checklist that you might find helpful: Executes without crashing Appropriate Internal Documentation Pet Class Data members: name, type, weight Constructor/destructor Getters/setters as appropriate Main: The following items must be implemented in main() or by functions called from main() They must not be implemented in the Pet class Prompts user for the number of pets Creates the pet array using dynamic memory allocation Dynamically creates a pet object Generates a random weight (between 1-100 inclusive) for each pet Seed is 100 Prints contents of array as illustrated in diagram De-allocates memory (both the array and the contents of the array) before exiting Style: Modular design, no global variables, etc.arrow_forward!! E! 4 2 You are in process of writing a class definition for the class Book. It has three data attributes: book title, book author, and book publisher. The data attributes should be private. In Python, write an initializer method that will be part of your class definition. The attributes will be initialized with parameters that are passed to the method from the main program. Note: You do not need to write the entire class definition, only the initializer method lili lilıarrow_forwardInstructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and…arrow_forward
- 50- What does it mean for an object to be "immutable"? a. The object can't be used in calculations. b. The object can't have its value changed. c. The object can't be passed as an argument to a function. d. The value of the object can't be accessed.arrow_forward1) Do you think it is possible to create another constructor with the same set of parameters? For example, adding the following constructor to Volunteer. Place a check (✓) beside your answer.Volunteer(): name_("Default"), branch_("CSU Long Beach") { } Yes, because you can overload constructors much like how you overload member functions. No, because the program will not know which constructor to use. No, because the body of the constructor is empty. 2) Much like constructors, member functions can also be overloaded. Write the name of Volunteer's overloaded member function. Take note that member function overloads need to have the same return type. 3) How do you think the compiler knows which member function overload it should call? Place a check (✓) beside your answer. It checks the name of the member function that was called. It compares the number of arguments and their data types with the member function's parameters. It always calls the overload with the least number of…arrow_forward(Java) The Abstract Art Class Write an abstract class as follows: The class is named Art It inherits from the Comparable interface It has a private String member variable named name It has a private String member variable named artist It has a private int member variable called year It has a default constructor that assigns the values "No name" to name, "No artist" to artist and -1 to the year. This default constructor calls the three argument constructor. It has a three-argument constructor to assign values to the name, artist and year variables. It has a copy constructor that makes a copy of another non-null Art object It has getters and setters for the name, artist and year variables It has a toString() method that creates a string of artist, with name and year tabbed once on subsequent lines (see sample output) It has an equals method that compares this Art to another Object It has a compareTo method that compares in this order: 1) artist, 2) name, 3) year This class contains no…arrow_forward
- (Java) Open up Eclipse and create a new class called ArrayListPractice.java Next, copy and paste the below program into your file and run the code. Your job is to take the given code, remove all the arrays and replace them with the identical ArrayLists. There should be no arrays in your program. You will need to call the ArrayList methods as defined in the lesson notes above. Note that you will not be able to do method overloading with ArrayLists so you should assign different names to your methods. Once you have made the changes, you should get identical output as the given version of the program. Submit your program when you are finished. /** * @author * CIS 36B * Activity 5.2 */ import java.util.ArrayList; import java.util.Scanner; public class ArrayListPractice { public static void main(String[] args) { int scores[] = {95, 96, 97, 98, 99}; System.out.println("Integer test scores:"); print(scores); System.out.println();…arrow_forward(Java) Q 5,6 Explain the answer step-by-step . I want to understand how to do it so please include verbal explanation. Thank you! Part 1 Write the class described below: The name of the class is Student The class has two public member variables: A String called name and a double called gpa The class has a public member method called printStudent. This method prints out the message: "Hi! My name is " + name + ".\nAnd my gpa is " + gpa It returns nothing Part 2 Now, declare a new Student object named jackie, and assign it the values "Jackie Chan" for the name and 3.5 for the gpa. Finally insert the object jackie into the below ArrayList: ArrayList<Student> al = new ArrayList<Student>();arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY