Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8.1 Programming Fraction - Write in Java and include comments Consider the follo

ID: 3920264 • Letter: 8

Question

8.1 Programming Fraction - Write in Java and include comments

Consider the following class:

public class Fraction{
private int numerator;
                private int denominator;
                private static char slash = ‘/’,
}

Write a program to instantiate an object of the Fraction class to test the class.. Add a constructor(s), set and get methods to the Fraction class appropriately. Using the Serializable Interface, instantiate and write three Fraction objects to a file called “SerialF.dat.” A loop must be used when creating and writing the three objects to the file. You can select the values you wish to use for the denominator and numerator.

Directions

Create the Fraction Class.

Add a constructor(s), set and get methods to the Fraction class appropriately.

Ensure the class is Serializable.

Use a loop to create three Fraction objects.

Initialize the three objects,

Write each object to the file“SerialF.dat.”

Display an appropriate message if an exception occurs.

Grading Rubric

Task

Points

Fraction class implements Serializable

0.5

The main method throws an IOException

1

The file "SerialF.dat" is created properly

1

Loop used to instantiate objects

1

Objects are correctly written to file "SerialF.dat"

1

The file "SerialF.dat" is closed appropriately

0.5

Proper documentation

1

Program works effectively

1

Total

7

Task

Points

Fraction class implements Serializable

0.5

The main method throws an IOException

1

The file "SerialF.dat" is created properly

1

Loop used to instantiate objects

1

Objects are correctly written to file "SerialF.dat"

1

The file "SerialF.dat" is closed appropriately

0.5

Proper documentation

1

Program works effectively

1

Total

7

Explanation / Answer

Solution

Fraction.java

FractionDemo.java

}

Feel free to reach out regarding any queries . And please do rate the answer . Thank you .

import java.io.Serializable; public class Fraction implements Serializable { private int numerator; private int denominator; private static char slash; public Fraction() { super(); this.slash = '/'; // TODO Auto-generated constructor stub } public Fraction(int numerator, int denominator) { super(); this.slash = '/'; this.numerator = numerator; this.denominator = denominator; } public int getNumerator() { return numerator; } public void setNumerator(int numerator) { this.numerator = numerator; } public int getDenominator() { return denominator; } public void setDenominator(int denominator) { this.denominator = denominator; } public static char getSlash() { return slash; } public static void setSlash(char slash) { Fraction.slash = slash; } @Override public String toString() { return "Fraction [numerator=" + numerator + ", denominator=" + denominator + "]"; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote