 # The Program: You need to create an ArrayList with 10 Fraction ob...

## Question

The Program:

You need to create an ArrayList with 10 Fraction objects. Each fraction should be created with a random numerator and denominator between 1 and 100. The fractions should be printed to the screen, sorted from low decimal value to high, then, reprinted to the screen as a sorted list of fractions.

Sample Output: (Your fraction values will vary)

Before sort:
0 The fraction is 67/37 Decimal value is 1.81
1 The fraction is 97/77 Decimal value is 1.26
2 The fraction is 40/53 Decimal value is 0.75
3 The fraction is 5/47 Decimal value is 0.11
4 The fraction is 15/18 Decimal value is 0.83
5 The fraction is 41/33 Decimal value is 1.24
6 The fraction is 22/74 Decimal value is 0.30
7 The fraction is 40/71 Decimal value is 0.56
8 The fraction is 32/93 Decimal value is 0.34
9 The fraction is 99/27 Decimal value is 3.67

After sort:
0 The fraction is 5/47 Decimal value is 0.11
1 The fraction is 22/74 Decimal value is 0.30
2 The fraction is 32/93 Decimal value is 0.34
3 The fraction is 40/71 Decimal value is 0.56
4 The fraction is 40/53 Decimal value is 0.75
5 The fraction is 15/18 Decimal value is 0.83
6 The fraction is 41/33 Decimal value is 1.24
7 The fraction is 97/77 Decimal value is 1.26
8 The fraction is 67/37 Decimal value is 1.81
9 The fraction is 99/27 Decimal value is 3.67

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.ArrayList;
import java.util.Collections;

public class Solution {

public static void main(String[] args)
{
ArrayList<Fraction> list = new ArrayList<Fraction>();
for(int i = 0; i < 10; i++)
{
Fraction temp = new Fraction();
temp.setDenominator((int)(Math.random()*100 + 1));
temp.setNumerator((int)(Math.random()*100 + 1));
System.out.println(i + " The fraction is " + temp.getNumerator() + "/" + temp.getDenominator() + " Decimal value is " + temp.getValue());
}
System.out.println("After sort");
Collections.sort(list);

for(int i = 0; i < 10; i++)
{
System.out.println(i + " The fraction is " + list.get(i).getNumerator() + "/" + list.get(i).getDenominator() + " Decimal value is " + list.get(i).getValue());
}
}
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

\$12.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.