java program coding – www.savvyessaywriters.net

java program coding – www.savvyessaywriters.net

 

Problem

For this programming assignment, you are to implement the Fraction class design given below. You are also to develop an appropriate test driver that thoroughly tests the class.

Fraction Class Design

Implement the following class design.

public class Fraction {_x000D_
    private int numer;_x000D_
    private int denom;_x000D_

// alternate constructor (general fraction construction)
public Fraction(int numer, int denom) throws InvalidDenominatorException

// alternate constructor (unit fraction construction)
public Fraction(int denom) throws InvalidDenominatorException

    // copy constructor_x000D_
    public Fraction(Fraction otherFrac)_x000D_
    // getters_x000D_
    public int getNumer()_x000D_
    public int getDenom()_x000D_
    // standard methods_x000D_
    public String toString()_x000D_
    public boolean equals(Fraction rFrac)_x000D_
    // arithmetic operators_x000D_
    public Fraction abs()_x000D_
    public Fraction add(Fraction rFrac)_x000D_
    public Fraction sub(Fraction rFrac)_x000D_
    public Fraction mult(Fraction rFrac)_x000D_
    public Fraction div(Fraction rFrac)_x000D_
    public Fraction invert()_x000D_
    public double convertToDecimal()_x000D_
    public Fraction reduce()_x000D_

{
Fraction temp = new Fraction(); int GCD = gcd(numer, denom);

temp.numer = numer / GCD; // allowed to access private vars of temp.denom = denom / GCD; // another object if same type as itself

        return  temp;_x000D_
    }_x000D_
    // relational operators_x000D_
    public boolean lessThan(Fraction rFrac)_x000D_
    public boolean greaterThan(Fraction rFrac)_x000D_
    // additional operators_x000D_
    public boolean reducedForm()_x000D_
    public boolean properFrac()_x000D_
    // Private Methods_x000D_
    private int gcd(int n1, int n2) // Euclid’s Algorithm_x000D_

{
int M, N, R;

        if (n1 < n2){_x000D_
            N = n1;_x000D_

} M=n2;

else{N = n2;

M = n1; }

        R = M % N;_x000D_
        while (R != 0){_x000D_

M = N;

N = R;
} R=M%N;

return N; }

}

Note that objects of type Fraction are immutable. Also, the alternate constructor throws an InvalidDenominatorException if passed a denominator value of 0. This exception type is not predefined in Java, so you must define it as follow as another class in your Java project files:

public class InvalidDenominatorException extends RuntimeException { } // nothing to implement

This creates an exception of type RuntimeException. RuntimeExceptions do not need to be caught when thrown. However, your test driver should have the code for catching this exception where appropriate.

For example, if your test driver excutes the following,

      Fraction frac1 = new Fraction(1,2);_x000D_

then there is no need to catch the possible exception, since it is clear that the denominator is not 0. However, if the values are input by the user, then there is a chance that a denominator value of 0 could be entered. Therefore, the code for catching the possible exception is needed,

   int numer, denom;_x000D_
   Fraction frac1;_x000D_
   Scanner input = new Scanner(System.in);_x000D_
   Boolean valid_input = false;_x000D_
   while (!valid_input)_x000D_
   try_x000D_

{
System.out.print(“Enter numerator <space> denominator: “); numer = input.nextInt();
denom = input.nextInt();

      frac1 = new Fraction(numer,denom);_x000D_
   }  valid_input = true;_x000D_

catch (InvalidDenominatorException e)
{ System.out.println(“Denominator of Zero found – Please reenter”); c}atch (InputMismatchException e)
{ System.out.println(“Non-digit character found – Please reenter”);

e}tc.

Considerations

  • You must use the method names given above, with the same number and types of parameters.
  • Makes sure the equals method returns true for any two fractions that are arithmetically equal.
  • The equals, lessThan and greaterThan methods must not alter the fractions being compared.

Savvy Essay Writers

#write essay #research paper #blog writing #article writing #academic writer #reflective paper #essay pro #types of essays #write my essay #reflective essay #paper writer #essay writing service #essay writer free #essay helper #write my paper #assignment writer #write my essay for me #write an essay for me #uk essay #thesis writer #dissertation writing services #writing a research paper #academic essay #dissertation help #easy essay #do my essay #paper writing service #buy essay #essay writing help #essay service #dissertation writing #online essay writer #write my paper for me #types of essay writing #essay writing website #write my essay for free #reflective report #type my essay #thesis writing services #write paper for me #research paper writing service #essay paper #professional essay writers #write my essay online #essay help online #write my research paper #dissertation writing help #websites that write papers for you for free #write my essay for me cheap #pay someone to write my paper #pay someone to write my research paper #Essaywriting #Academicwriting #Assignmenthelp #Nursingassignment #Nursinghomework #Psychologyassignment #Physicsassignment #Philosophyassignment #Religionassignment #History #Writing #writingtips #Students #universityassignment #onlinewriting #savvyessaywriters #onlineprowriters #assignmentcollection #excelsiorwriters #writinghub #study #exclusivewritings #myassignmentgeek #expertwriters #art #transcription #grammer #college #highschool #StudentsHelpingStudents #studentshirt #StudentShoe #StudentShoes #studentshoponline #studentshopping #studentshouse #StudentShoutout #studentshowcase2017 #StudentsHub #studentsieuczy #StudentsIn #studentsinberlin #studentsinbusiness #StudentsInDubai #studentsininternational