Rational Numbers

Ads
 

Rational Numbers

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.

getValue‚??returns the rational number as a double value.

toString‚??returns the rational number as a string in the form a/b.

View Answers

Ads









Related Tutorials/Questions & Answers:
Rational Numbers
Rational Numbers   Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer..., the rational number 40/12 should be stored as 10/3. The class has the following
ModuleNotFoundError: No module named 'lets_be_rational'
ModuleNotFoundError: No module named 'lets_be_rational'  Hi, My... named 'lets_be_rational' How to remove the ModuleNotFoundError: No module named 'lets_be_rational' error? Thanks   Hi, In your
Advertisements
ModuleNotFoundError: No module named 'lets_be_rational'
ModuleNotFoundError: No module named 'lets_be_rational'  Hi, My... named 'lets_be_rational' How to remove the ModuleNotFoundError: No module named 'lets_be_rational' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'lets_be_rational'
ModuleNotFoundError: No module named 'lets_be_rational'  Hi, My... named 'lets_be_rational' How to remove the ModuleNotFoundError: No module named 'lets_be_rational' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'py_lets_be_rational'
ModuleNotFoundError: No module named 'py_lets_be_rational'  Hi, My... named 'py_lets_be_rational' How to remove the ModuleNotFoundError: No module named 'py_lets_be_rational' error? Thanks   Hi
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String...=input.nextInt(); list.add(num); } System.out.println("Numbers
Prime Numbers
Prime Numbers  Create a complete Java program that allows the user to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents
Numbers pyramid
Numbers pyramid  Hi sir, Can you please tell me how to output this using nested for loops? 1 2, 1 1, 2, 3 4, 3, 2, 1 1, 2, 3, 4, 5 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7 8, 7, 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 9, 8
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi, You function will take 2 numbers and the find the even numbers between
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
Hexadecimal numbers multiplication
Hexadecimal numbers multiplication  Sir, I have to multiply 128 bit hexadecimal numbers. Do u have any logic for this?? The numbers are like ab7564fa342b5412c34d9e67ab341b58
Addition of two numbers
Addition of two numbers  addition of two numbers
ModuleNotFoundError: No module named 'numbers'
ModuleNotFoundError: No module named 'numbers'  Hi, My Python... 'numbers' How to remove the ModuleNotFoundError: No module named 'numbers... to install padas library. You can install numbers python with following command
multiply of 100 digits numbers
multiply of 100 digits numbers  multiplying 100 digits numbers to eachother
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
odd numbers with loop
odd numbers with loop  get the odd numbers till 100 with for,while loop   Java find odd numbers: class OddNumbers { public static void main(String[] args) { for(int i=1;i<=100;i
Sum of positive and negative numbers
; import java.util.*; class Numbers { public static void main(String...=0,sum2=0; int num[]=new int[10]; System.out.println("Enter 10 numbers...]; } } System.out.println("Sum of positive numbers: "+sum2); System.out.println
Application for print pyramid of numbers
Application for print pyramid of numbers  What is the code for printing the numbers like 1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
Sum of first n numbers
Sum of first n numbers  i want a simple java program which will show the sum of first n numbers....   import java.util.*; public class...; } System.out.println("Sum of Numbers from 1 to "+n+" : "+sum
Generating random numbers in a range with Java
Generating random numbers in a range with Java  Generating random numbers in a range with Java
How to put text file numbers to array and check the position of numbers?
How to put text file numbers to array and check the position of numbers?   I have numbers in text file data.txt 12 9 8 3 1
Divide 2 numbers
Divide 2 numbers  Write a java program to divide 2 numbers. Avoid division by zeor by catching the exception.   class Divide { public static void main(String[] args) { try{ int num1=8
Formatting numbers in Velocity Templates?
Formatting numbers in Velocity Templates?  I need to display amount in following formats: 1099 -> 1,099.00 100 -> 100.00 100.251 -> 100.25 10999 -> 10,999.00 1110999 -> 11,10,999.00 Right now I am using
print numbers in traingle shape
print numbers in traingle shape  1 22 333 4444 i want output like this please help me   class Pyramid { public static void main(String[] args) { for(int i=1;i<=4;i++){ for(int j=1;j<
finding the prime numbers
finding the prime numbers  Hi, I am a beginner to java and I have problem with the code in finding the prime numbers, can someone tell me about the problem. Thanks.   Want to know about how to find out the given
Formatting numbers in Velocity Templates?
Formatting numbers in Velocity Templates?  I need to display amount in following formats: 1099 -> 1,099.00 100 -> 100.00 100.251 -> 100.25 10999 -> 10,999.00 1110999 -> 11,10,999.00 Right now I am using
Prime Numbers from range
Prime Numbers from range  how to find prime numbers in a given range which are palindromes??   Hi Friend, Try the following code: import java.util.*; public class PrimeAndPalindrome { static final int MAXNUMBER
Applet for add two numbers
Applet for add two numbers  what is the java applet code for add two numbers?   import java.awt.Graphics; import javax.swing.*; public...); add(text2); label3 = new Label("Sum of Two Numbers
ModuleNotFoundError: No module named 'add_numbers'
ModuleNotFoundError: No module named 'add_numbers'  Hi, My Python... 'add_numbers' How to remove the ModuleNotFoundError: No module named 'add_numbers' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'authorizenet-numbers'
ModuleNotFoundError: No module named 'authorizenet-numbers'  Hi...: No module named 'authorizenet-numbers' How to remove the ModuleNotFoundError: No module named 'authorizenet-numbers' error? Thanks   Hi
ModuleNotFoundError: No module named 'fair-numbers'
ModuleNotFoundError: No module named 'fair-numbers'  Hi, My Python... 'fair-numbers' How to remove the ModuleNotFoundError: No module named 'fair-numbers' error? Thanks   Hi, In your python

Ads