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 11:10
The total cost of textbooks for the term was collected from 36 students. create a histogram for this data. $140 $160 $160 $165 $180 $220 $235 $240 $250 $260 $280 $285 $285 $285 $290 $300 $300 $305 $310 $310 $315 $315 $320 $320 $330 $340 $345 $350 $355 $360 $360 $380 $395 $420 $460 $460
Answers: 2
question
Computers and Technology, 23.06.2019 15:00
Jake really works well with numbers and is skilled with computers but doesn't work well with others. which of the jobs discussed in this unit might be best for jake? why?
Answers: 3
question
Computers and Technology, 23.06.2019 16:00
Which analyst position analyzes information using mathematical models to business managers make decisions?
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
What does the faves button do? a. users mark a web page as a favorite b. leads other readers to favor a specific page c. readers sort and align their favicons, or favorite icons d. leads users to a message board where they can post questions
Answers: 1
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, 19.07.2019 13:50
question
Chemistry, 19.07.2019 14:00
Questions on the website: 13722363