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 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 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

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 04:00
Acetylene is a gas which burns rapidly on its own, and is considered highly explosive. a) true b) false
Answers: 2
question
Computers and Technology, 22.06.2019 10:00
You need a reliable network for about twenty-five computers that will be distributed across a large building. it is important that the network be relatively cheap. which topology should you use?
Answers: 1
question
Computers and Technology, 22.06.2019 18:00
When is it appropriate to use an absolute reference
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
What are two ways to access the options for scaling and page orientation? click the home tab, then click alignment, or click the file tab. click the file tab, then click print, or click the page layout tab. click the page layout tab, or click the review tab. click the review tab, or click the home tab?
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, 27.08.2020 22:01
question
English, 27.08.2020 22:01
question
Advanced Placement (AP), 27.08.2020 22:01
Questions on the website: 13722361