From health tips to tech hacks, find it all on IDNLearn.com. Discover the information you need from our experienced professionals who provide accurate and reliable answers to all your questions.
2.8.9: Concatenating Fractions
Implement getNumerator and getDenominator. Then fill in the toString method so that it returns a Fraction in the form "numerator/denominator", such as "1/2" or "16/20".
FractionTester.java
import java.util.Scanner;
public class FractionTester
{
public static void main(String[] args)
{
// Create objects
Scanner input = new Scanner(System.in);
// Ask for input
// Create new Fraction with the user's input
// Add the fractions
// Make use of the getDenominator and getNumerator methods
// Print out the fractions as an equation
// Remember you don't have to call toString yourself!
}
}
Fraction.java
public class Fraction
{
private int numerator;
private int denominator;
public Fraction(int numer, int denom)
{
numerator = numer;
denominator = denom;
numer = 0;
denom = 1;
}
public Fraction1 (int getNumerator, int getDenominator);
{
getNumerator = numer;
getDenominator = denom;
}
// Returns the numerator
public int getNumerator()
{
return numer;
}
// Returns the denominator
public int getDenominator()
{
int denom;
return denom;
}
// Returns a string representing a fraction
// in the form
// numerator/denominator
public String toString()
{
return numerator + "/" + denominator;
}
}
Sagot :
We appreciate your participation in this forum. Keep exploring, asking questions, and sharing your insights with the community. Together, we can find the best solutions. Your questions find clarity at IDNLearn.com. Thanks for stopping by, and come back for more dependable solutions.