Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please help me code this using Java. ixed Fraction n this assignment, you will implement and create a Fraction class for mixed fraction

Can someone please help me code this using Java. image text in transcribed
image text in transcribed
ixed Fraction n this assignment, you will implement and create a Fraction class for mixed fraction numbers. omplete the following interface for the Fraction class and save it as Feaction.java: blie class Fraction private int whole; peivate int nunerator private int denoninator Create a paranaterless construetor, whieh sets the vhole nunber and nunerator to 0 and the denoninator to 1 pablie Fraction) Create a constructor that accepts two parameters // for the nunerator and denoninator, When the constructor // S gsed, the vho2@ sumber value is 0 publie Fraction(int umerator, int denonisator) Create a constructor that accepts three paraneters / for the whole number, numerator, and denoninator pablic Fraction int whole, int nunerator, int denominator) This ealeulates greatest eonmon divisor (GCD) I expeet that you will find it useful int god(int , int b) return ged(b,atb) /Redaces the Fraction value to the lovest possible denominator example 72/20 should be redueed to 18/5, vhich is also 3 3/5 publie void reduce Add the eurrent Traction to Praction A, return the result as a new FractLon (reduced, of course) publie Fraction add(Fraction A) Subtract the current Fraction Praction A, return the result as a new Fraction (reduced, of course pablic Fraction substract (FractLon A) Multiply the current Fraction to Praction A, return the result as a new Fraction (reduced, of course Fraction multiply(Praction A) Divide Practions (this/A), return the result as a new Fraction (reduced, of course) // Youa may assume that A 11 be a non-zero value publie Fraction divido(Fraction A) / ratarns a string that contains a fraction in the formats whole nunber, a space, the namerator, a slash and a denominator (e.g: 2 3/4 // when the whole number 0. just display the traction part (-g: 1/2 instead of 0 1/2 When the nunerator is 0, Just display the whole nunber (e-g: 2 instead ot 2 0/3 Also, just display 3 instead ot 3/1 ic string tostring) Notes Make sure you understand the problem before you start coding (start on paper). . Test your program on mutiple test cases. . You only need to submit Fraction.java. The following main program is a trivial example of how your class will be tested. import java.uti1.. public class sample public static void nain(String args) int v, n, di Scanner se nev Scanner (Systen.in): System.out-print( "Enter whole humber for X: SC.nextint) System.out-print( Enter namerator for X) sC.nextInt) System.out-print( Enter denominator for Xi dse.nextint)a Praction nev Fraction(w, n. d) System.out-print( "Enter whole number for T sc.nextintO System.out.print("Enter numerator for Y1 ); se.nextine System.out-print( "Enter denominator for Y d se.nextIntO Praction nev Fraction(w, n, d) System.out printin): System.out-printiax:X.toString System.out-println(YY.toString Fraction A .add(Y); System.out .print 1n("ADD.. A.toString( )) ; + Praction $ .sub@traet (Y); System.out-printin SUB:s.toStringt)) Fraction M . .multiply(Y); System.out-printin( "MULM.tostring)) Praction D x.divide(Y) System.out-println( DIV:D.toStringt)) Here are two sample runs of the program Enter numerator for X Enter denomisator for 2 Ent@r whol@ suabe for Y; 0 Ent@r umerate for Y: ! Enter denomisator for T 2 X1 4 1/2 Y: 1/2 ADDi 5 MUL 2 1/4 Enter whole unber for X3 Enter numerator for 2 Enter denomisator for : 3 Enter umerator tor Enter denominator for T 1 Xi 3 2/3 ADD: 6 2/3 DIV: 12/9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

Learning is a good thing for everyone. Discuss.

Answered: 1 week ago

Question

What should be the role of managers in HRD?

Answered: 1 week ago

Question

What should be the role of government in HRD?

Answered: 1 week ago