Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer values, a and b, where b is not zero. The class has attributes for the numerator and denominator of this ratio. The ratio should always be stored in its simplest form. That is, any common factor of a and b should be removed. For example, the rational number 40/12 should be stored as 10/3.

The class has the following constructors and methods:
• A default constructor that sets the rational number to 0/1.
• A constructor that has parameters for the numerator and denominator, and converts the resulting ratio to simplified form.
• simplify—a private method that converts the rational number to simplified
form.
• getGCD(x, y)—a private static method that returns the largest common factor of the two positive integers x and y, that is, their greatest common divisor. For example, the greatest common divisor of 40 and 12 is 4.
• value—returns the rational number as a double value.
• toString—returns the rational number as a string in the form a/b.

This project demonstrates a class that uses a couple private methods to accomplish some small tasks.



See the code in Rational.java.

Computer Science & Information Technology

You might also like to view...

The ____ folder is the default location for all saved messages.

A. Drafts B. Documents C. Messages D. Downloads

Computer Science & Information Technology

Items drawn in merge mode are called ____________________.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Match each item with a statement below.

A. any activity that represents a potential danger or attack on a system or network B. any type of network service that permits users elsewhere on a network to use the network to log on to a system as if they were attached locally while operating remotely C. an ICMP Echo-based operation used to locate active devices on a network D. the process of examining the "footprints" that an attacker leaves behind E. a special-purpose software tool that cycles through all possible TCP and UDP port addresses looking for open ports that then can be probed for access or exploited for vulnerabilities F. a manager system in a DDoS attack G. an IP attack technique whereby an impostor takes over an ongoing communications session between a client and server H. a document that represents the concrete manifestation of an organization's requirements for security practices, rules, and procedures I. a computer system deliberately set up to attract, entice, and entrap would-be attackers, often by being made to appear part of a larger network

Computer Science & Information Technology

What do the first 24 bits of a MAC address represent??

A. ?Organizationally Unique Identifier B. device ID C. ?extension ID D. ?network ID

Computer Science & Information Technology