subject

For this assignment, you will create a class to store fractions. The class will hold two integer values: a numerator and a denominator. For your class we will stick to positive fractions, meaning the numerator and the denominator must both be greater than 0.

In previous assignments, we had a requirement that your class be named Main. In this assignment, the class is required to be named Fraction.

To get started, download the template file Fraction. java (Links to an external site.). Your job will be to add the constructors and methods described in the following sections to the class Fraction that is declared in this template file.

Fraction should include two constructors:

Fraction(): default constructor which creates a fraction 1/1
Fraction(int n, int d): If n is positive, set numerator to n. Otherwise, set numerator to 1. If d is positive, set denominator to d. Otherwise, set denominator to 1.
Fraction should include the following methods:

String toString(): Returns the fraction as a string in the format "numerator/denominator". For example 1/2 or 5/3.
String mixedNumber(): Returns any improper (top-heavy) fraction as a mixed number, for example, 2 3/5. If the numerator of the fraction part is 0, return only the integer part of the mixed number. If the fraction is proper, return only the fraction part.
void add(int n, int d): If n and d are both positive, add the fraction n/d to this fraction. Otherwise, leave the fractions unchanged. In general the sum of the fractions a/b and c/d is(a*d + c*b)/(b*d).
To test your code, download the runner class student_fraction_runner. java (Links to an external site.) into the same folder that holds your Fraction. java. Execute the method student_fraction_runner. main and verify that the output matches the sample run listed below.

We will use a similar but different runner to grade the program. In order to pass all tests, you will need to change student_fraction_runner. java to test different values to make sure your program fits the requirements. Note: You will not be submitting student_fraction_runner. java. This file is provided to help you test your implementation of the class Fraction.

When you are done coding and testing, copy and paste your entire Fraction class into the Code Runner and press "Submit Answers" in order for your assignment to count as turned in. We will be returning to and improving the Fraction class in a later assignment (you may have already spotted some potential flaws in how the class is implemented) so be sure to save your work.

Sample Run

Fraction 1: 7/4
As a mixed number: 1 3/4

Fraction 2: 1/1
As a mixed number: 1

Fraction 3: 2/7
As a mixed number: 2/7
Add 2/5: 24/35

Fraction 4: 24/6
As a mixed number: 4
Attempt to add 1/-2: 24/6

Fraction 5: 5/2
As a mixed number: 2 1/2
Add 2/3: 19/6
As a mixed number: 3 1/6

Here is the template:

/* Term 2 Assignment 1 - Fraction */
/* A class which is used to represent fractions*/
public class Fraction
{
private int numerator;
private int denominator;

// TODO write default constructor
public Fraction()
{
}

// TODO write constructor for fraction n/d where n, d > 0
public Fraction(int n, int d)
{
}

// TODO write method to return fraction as a String
public String toString()
{
}

// TODO write method to return fraction as a mixed number String
public String mixedNumber()
{
}

// TODO write method to add fraction n/d to this Fraction
public void add(int n, int d)
{
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 07:30
Write a program that inserts the digits of an integer into an array in originalorderfollowed by reverse order. first, promptthe user to enter a positive integer(> 0). determine the number of digits of the integer. create a dynamically allocated integer arrayof a size twice the number of digits.now insert the digits in original order which will occupy half of the array. then, insert the digits in reverse order.finally, output thedigits in thearray.use at least two functions to organize your program.
Answers: 3
question
Computers and Technology, 24.06.2019 10:00
1. which of these is not true about torsion bars? a. they can be used to adjust ride height b. they can be adjusted anytime since they don't affect alignment angles c. they attach between the frame and the lower control arm d. they twist to produce a spring effect
Answers: 1
question
Computers and Technology, 24.06.2019 15:20
Local area networks use many of the same network technologies and the internet, only on a smaller scale. devices that access lans are equipped with a network interface that contains circuitry for wireless or wired connections. devices also have a physical address, in addition to the ip addresses acquired from a dhcp server. the most popular wired technology is . the most popular wireless technology is , which can be configured as a(n) or star topology. setting up a lan and configuring its router is fairly easy. the first step is to change the standard to one that is secure. next, create a(n) that uniquely identifies the network by name. it is also important to activate wireless to prevent wireless signals from being intercepted during transmission. a limited-access network can be created for visitors to use. by activating , the router will be able to assign ip addresses to each device that joins the network. to connect to a secure lan that is protected by encryption, an encryption , or password, is required. lans can be used to access data collected by iot devices and the networks that tie these devices together. technologies such as rfid, nfc, bluetooth smart, zigbee, and z-wave offer -power links, essential for battery-powered devices that can’t expend excess amounts of energy transmitting data.
Answers: 1
question
Computers and Technology, 24.06.2019 21:30
Write an algorithm to check if a number is even or odd and show with flow chart step by step
Answers: 2
You know the right answer?
For this assignment, you will create a class to store fractions. The class will hold two integer val...
Questions
question
Mathematics, 07.04.2020 17:02
question
Mathematics, 07.04.2020 17:02
question
Mathematics, 07.04.2020 17:02
Questions on the website: 13722362