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

I am working on a program for a class right now and have a driver and class file

ID: 3639718 • Letter: I

Question

I am working on a program for a class right now and have a driver and class files, both files compile properly but when I go to run the program I get the following errors. can anyone tell me why, what I need to do, or point me in the right direction of a possible web site to help me correct the issues?
Enter numerator; then denominator.
5
3
5/Exception in thread "main" java.util.MissingFormatArgumentException: Format sp
ecifier 's'
at java.util.Formatter.format(Formatter.java:2432)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at Fraction.printIt(Fraction.java:42)
at FractionProg7.main(FractionProg7.java:19)
Press any key to continue . . .

Attached are the two programs
/*********************************************************************************************************
*FractionProg7.java
*Fraction
*
*Driver program to perform addition, multiplication, print fraction, and prints as double.
**********************************************************************************************************/

import java.util.*;

public class FractionProg7
{
public static void main(String[] args)
{
Scanner stdIn=new Scanner(System.in);
Fraction c, d, x; //Fraction objects

System.out.println("Enter numerator; then denominator.");
c=new Fraction(stdIn.nextInt(), stdIn.nextInt());
c.printIt();

System.out.println("Enter numerator; then denominator.");
d=new Fraction(stdIn.nextInt(), stdIn.nextInt());
d.printIt();

x=new Fraction(); //create a fraction for number 0

System.out.println("Sum:");
x.add(c).add(d);
x.printIt();
x.printAsDouble();

x=new Fraction(1, 1); //create a fraction for number 1

System.out.println("Product:");
x.multiply(c).multiply(d);
x.printIt();
x.printAsDouble();

System.out.println("Enter numerator; then denominator.");

x=new Fraction(stdIn.nextInt(), stdIn.nextInt());
x.printAsDouble();

} //end main
} //end public class FractionProg7

/*************************************************
*Fraction.java
*
*Handles fractional numbers for
*************************************************/

public class Fraction
{

private int numerator;
private int denominator;
private double quotient;

public Fraction()
{
this (0, 1);
}

public Fraction (int numerator, int denominator)
{
this.numerator = numerator;
this.denominator = denominator;
this.quotient = (double) this.numerator / this.denominator;
}

public Fraction add(Fraction d)
{
return new Fraction(numerator*d.denominator, denominator*d.denominator);
}

public Fraction multiply(Fraction d)

{
int newNumerator = numerator*d.denominator;
int newDenominator = denominator*d.denominator;
Fraction x = new Fraction(newNumerator, newDenominator);
return x;
}

public void printIt()
{
System.out.printf((numerator) + "/%s/n" + (denominator));
}

public void printAsDouble()

{
System.out.println((double) numerator / (double) denominator);

} //end printIt

} //end public class Fraction

Explanation / Answer

Following method causing error in your program.. Its trying to print division symbol format. i just changed to correct format the way it supposed to be..

   public void printIt() {

       // Update this line in your program...it will work.
        System.out.printf("%s/%s ",(numerator),(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