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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 16:00, natasniebow
Kenny works with an it company. his company is about to launch new software in the market. he has to ensure that this new software is functional and meets all of the quality standards set up at the planning stage. which job profile is kenny likely to have? kenny is likely to have the job profile of a blank .
Answers: 2
image
Computers and Technology, 24.06.2019 14:30, ari313
Two students are discussing the flow of electricity. student a says that voltage is a measure of the amount of electron flow in a circuit. student b says that power is the product of voltage and current. which of the following statements is correct? a. only student a is correct b. only student b is correct c. both of the two students are correct d. neither of the two students is correct
Answers: 1
image
Computers and Technology, 24.06.2019 21:30, breannaasmith1122
Along what line of action can the camera move to follow the movement of actors for screen direction? a. along a 90-degree arcb. along a 120-degree arcc. along a 180-degree arcd. along a 360-degree arc
Answers: 1
image
Computers and Technology, 25.06.2019 10:00, kyleryoung0602
Most common level of education for a programmer or software developer
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 in other subjects:

Konu
Biology, 12.11.2020 18:30
Konu
Chemistry, 12.11.2020 18:30
Konu
Mathematics, 12.11.2020 18:30
Konu
English, 12.11.2020 18:30