3.a: Write a Java class called Rational for performing arithmetic with positive rational numbers. A positive...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3.a: Write a Java class called Rational for performing arithmetic with positive rational numbers. A positive rational no. is a number that can be expressed in the form of p/q, where p,q are positive integers with q !=0 and p and q have no common divisor. Make the class implement the comparable interface so that each object should be able to compare itself to another object of the same type based on ascending order. 5 MARKS b: Write a Java program that uses an ArrayList to store a collection of 10 of the Rational objects defined in part a. Sort the ArrayList of Rational objects according to the Natural Order defined in the Comparable interface of the Rational class itself using the sort method provided in the collections framework and then finally print out the list. 8 MARKS c: Sort the ArrayList of Rational objects again using a separate Comparator class (a class that implements java.util.Comparator) that sorts them in descending order i.e. the opposite of the Natural Order defined in the Rational class itself. 7 MARKS d: Modify the program to use the built-in Collections.binarySearch() method to check if a particular fraction, inputted through the console, is contained within the list. Print out your results to the console. 5 MARKS 3.a: Write a Java class called Rational for performing arithmetic with positive rational numbers. A positive rational no. is a number that can be expressed in the form of p/q, where p,q are positive integers with q !=0 and p and q have no common divisor. Make the class implement the comparable interface so that each object should be able to compare itself to another object of the same type based on ascending order. 5 MARKS b: Write a Java program that uses an ArrayList to store a collection of 10 of the Rational objects defined in part a. Sort the ArrayList of Rational objects according to the Natural Order defined in the Comparable interface of the Rational class itself using the sort method provided in the collections framework and then finally print out the list. 8 MARKS c: Sort the ArrayList of Rational objects again using a separate Comparator class (a class that implements java.util.Comparator) that sorts them in descending order i.e. the opposite of the Natural Order defined in the Rational class itself. 7 MARKS d: Modify the program to use the built-in Collections.binarySearch() method to check if a particular fraction, inputted through the console, is contained within the list. Print out your results to the console. 5 MARKS
Expert Answer:
Answer rating: 100% (QA)
3a Heres a Java class called Rational that implements the Comparable interface and performs arithmetic with positive rational numbers csharp Edit Full ... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
A Bernoulli random variable has variance 0.21 . What are the possible values for its success probability?
-
On December 31, 2016, Acker Ltd. reported the following statement of financial position. The accumulated other comprehensive income was related only to the company's non-traded equity investments....
-
The XO Group Inc. conducted a survey of 13,000 brides and grooms married in the United States and found that the average cost of a wedding is $29,858 (XO Group website, January 5, 2015). Assume that...
-
Tolerable error, a measure of the maximum monetary error that may exist in an account balance without causing materially misstated financial statements, is directly related to: a. Precision. b. Audit...
-
The trial balance of Mr. Eko Fashion Center contained the following accounts at November 30, the end of the company?s fiscal year. Adjustment data:1. Supplies on hand totaled $2,000.2. Depreciation...
-
Altira Corporation provides the following information related to its inventory during the month of August 2024: August 1 Inventory on hand-2,300 units; cost $6.40 each. August 8 Purchased 11,500...
-
Answer the following questions. a. What are the strengths of Professor Waddocks analysis? What are the weaknesses? What does the fact that there were frauds and unethical behavior long before the...
-
The following are annual net profits(in millions of dollars) over the past four years for three divisions of Randys Wholesale: Cosmetics: $4.5, $5.5, $5.65, $5.9 Pharmaceutical: $15.4, $17.6,...
-
What is the Policing act in the State of Georgia? What is the second chance act in the State of Georgia? What is the police Reform in Georiga? References
-
When coronis refused, Gordon sued. Gordon claimed that coronis was attempting to withdraw a firm offer. who wins?
-
Identify both intentional and unintentional torts, considering issues of vicarious liability Identify two current issues relating to your business that arise from tort liability. The name of the...
-
Explore leverage as it related to the financial crisis of 2008/2009 and share what you learned?
-
Explain how each of these 4 strengths listed below, will enable a person to develop a healthy organisational compliance culture or aid in this development. The answer must provide an excellent...
-
Peter Piper Corp acquires Silly Suzy Corp for $420,000.00 Cash on 1/1/21. At the time of the purchase Silly Suzy Corporation had the following Balance Sheet: Current Liabilities $90,000 Inventory...
-
Determine the volume of the parallelepiped of Fig. 3.25 when (a) P = 4i 3j + 2k, Q = 2i 5j + k, and S = 7i + j k, (b) P = 5i j + 6k, Q = 2i + 3j + k, and S = 3i 2j + 4k. P
-
Heres another peek ahead. In this chapter, you learned about integers and the type int. Java can also represent uppercase letters, lowercase letters and a considerable variety of special symbols....
-
Modify Exercise 24.4 to provide a ComboBox and a TextArea to allow the user to perform a query that is either selected from the ComboBox or input into the TextArea. Sample predefined queries should...
-
Write an application that inputs an integer containing only 0s and 1s (i.e., a binary integer) and prints its decimal equivalent. Use the remainder and division operators to pick off the binary...
-
Has transactional selling gone the way of the dinosaur? That is, are there ever any situations in which a transactional approach to selling would be an appropriate approach today? If so, what are...
-
When a firm shifts from transactional selling to a value-added approach, a number of changes have to take place in the way a salesperson approaches customers as well as his or her own job. List as...
-
Why is it important to talk about selling solutions instead of products or services? How does selling solutions further the success of a relationship-selling approach?
Study smarter with the SolutionInn App