Constructs a new rational number to represent the ratio

Assignment Help Basic Computer Science
Reference no: EM131413068

Write a class called RationalNumber that represents a fraction with an integer numerator and denominator. A RationalNumber object should have the following methods:
public RationalNumber(int numerator, int denominator)

Constructs a new rational number to represent the ratio (numerator/denominator). The denominator cannot be 0, so throw an IllegalArgumentException if 0 is passed.
public RationalNumber()

Constructs a new rational number to represent the ratio (0/1).
public int getDenominator()

Returns this rational number's denominator value; for example, if the ratio is (3/5), returns 5.
public int getNumerator() Returns this rational number's numerator value; for example, if the ratio is (3/5), returns 3. public String toString()

Returns a String representation of this rational number, such as "3/5". You may wish to omit denominators of 1, returning "4" instead of "4/1".

An extra challenge would be to maintain your RationalNumber objects in reduced form, avoiding rational numbers such as 3/6 in favor of 1/2, or avoiding 2/-3 in favor of -2/3. Another possible extra feature would be methods to add, subtract, multiply, and divide two rational numbers.

Reference no: EM131413068

Questions Cloud

Difference between master data and transaction data : Integrated Enterprise Systems - IT 402 - Explain the difference between master data and transaction data in an enterprise system and how are they related. Support your answer with examples.
What is the output of the following sequence of loops : What is the output of the following sequence of loops? Notice that the code is the same as that in the previous exercise, except that the placement of the braces has changed.
Find the variances for both revenue and expenditures sides : Find the variances for both the revenue and expenditures sides and then discuss two to three problematic areas for the agency. Provide the results of the variances in a table (Excel or Word).
Describe the process of strategy mapping : Explain the process of strategy mapping and how it relates to performance management and establishing value propositions.
Constructs a new rational number to represent the ratio : Write a class called RationalNumber that represents a fraction with an integer numerator and denominator. A RationalNumber object should have the following methods:
Discuss about the imaginative futurism : Imaginative futurism in science fiction novels has a tendency to begin as predictions of technologies that are not yet realized. In this assessment, you are to research a technology or scientific plot device that originated in science fiction and ..
Identify three objectives for improving organizations growth : Identify at least three objectives for improving the organization's learning and growth, and show how they relate to the mission, vision and strategy of the organization.
How do you examine every key (or every value) of a map : It doesn't even have an iterator method like a Set does, nor can you use a for-each loop on it directly. How do you examine every key (or every value) of a Map?
Identify one specific example of a measure of learning : For your first posting in this Discussion, identify one specific example of a measure of learning and growth measure that you feel could be critical to an organization, but difficult to measure.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Write an assembly program to divide hexadecimal number by 2

Write an assembly program to divide a hexadecimal number by 2. The number to be divided should be kept in a suitable memory location of the MSP430G2553. The division result will be kept in register R5 and the remainder will be kept in register R6

  What windows server 2008 capability

The IT Department wants to install Windows Server 2008 Standard Edition on 14 new servers in its primary location. The servers have arrived, are unpacked, and have been tested.

  Modular approach for designing networks

Why is it important to use modular approach for designing Networks? Could you anticipate what problems can occur if such methods are not used? Describe your response in two paragraphs.

  Jeremy make monthly investments

He's investing his savings in an annuity yielding an annual interest rate of 6.5% compounded monthly. If the annuity requires that Jeremy make monthly investments, what annuity payment must Jeremy make to save $10,000?

  Describing online services provided by selected companies

Identify and briefly describe the online services provided by the selected companies (e.g. online catalogue search, online information search.

  To what class does the following constructor belong

How many parameters does the following constructor have, and what are their types? public Book(String title, double price)

  Write the definition of the function

Write the definition of the function, leavesCount, that takes as a parameter a pointer to the root node of a binary tree and returns the number of leaves in a binary tree. Add this function to the class binaryTreeType and create a program to test ..

  Perform some defect trend analyses based on data

Perform some defect trend analyses based on data from your organization or data reported in literature. Pay special attention to time measurement: Is idle time counted or only activity time? Is the granularity proper?

  Find the optimal location for oliveira two distribution

Find the optimal location for Oliveira's two distribution centers in this expanded version of the problem.

  What is the rms voltage of the signal

An AM transmitter with a carrier power of 10 W at a frequency of 25 MHz operates into a 50-? load. It is modulated at 60% by a 2-kHz sine wave.

  What is branching on a configuration management system

Which is a better configuration management system: a centralized system or a decentralized system? Explain the benefits and drawbacks of each. What is branching on a configuration management system?

  What change management initiatives should km group have

What change management initiatives should the KM group have initiated at Infosys before attempting to develop and implement knowledge management at the company?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd