SlideShare a Scribd company logo
can someone fix the errors in this code? the name needs to be FractionDemo.java
//author: Jazmine Tapia
//date: 20 February 2023
//file: FractionDemo.java
/*
Lab 13 will also be using demonstation the
the multiplication of two factors.
*/
//import statements for Scanner class
import java.util.Scanner;
// Define a public class called Fraction
public class FractionDemo
{
// Define private instance variables for the numerator and denominator
private int numerator;
private int denominator;
// Define a constructor for the Fraction class that takes a numerator and denominator as
arguments
public FractionDemo(int numerator, int denominator)
{
// Set the denominator using the setDenominator() method defined below
setDenominator(denominator);
// Set the numerator
this.numerator = numerator;
// Reduce the fraction
reduce();
// Adjust the signs of the numerator and denominator if necessary
adjustSigns();
}
// Define a getter method for the numerator
public int getNumerator()
{
return numerator;
}
// Define a setter method for the numerator
public void setNumerator(int numerator)
{
this.numerator = numerator;
}
// Define a getter method for the denominator
public int getDenominator()
{
return denominator;
}
// Define a setter method for the denominator
public void setDenominator(int denominator)
{
// Set the denominator using the setDenominator() method defined below
setDenominator(denominator);
// Reduce the fraction
reduce();
// Adjust the signs of the numerator and denominator if necessary
adjustSigns();
}
// Define a private method to set the denominator
private void setDenominator(int denominator)
{
// If the denominator is zero, throw an exception
if (denominator == 0)
{
throw new IllegalArgumentException("Denominator cannot be zero");
}
// Set the denominator
this.denominator = denominator;
}
// Define a private method to calculate the greatest common divisor of two integers
private int gcd(int a, int b)
{
if (b == 0)
{
return a;
} else {
return gcd(b, a % b);
}
}
// Define a public method to reduce the fraction
public void reduce()
{
// Calculate the greatest common divisor of the numerator and denominator
int gcd = gcd(numerator, denominator);
// Divide both the numerator and denominator by the greatest common divisor to reduce the
fraction
numerator /= gcd;
denominator /= gcd;
}
// Define a private method to adjust the signs of the numerator and denominator if necessary
private void adjustSigns()
{
// If the denominator is negative, multiply both the numerator and denominator by -1 to adjust
the signs
if (denominator < 0)
{
numerator *= -1;
denominator *= -1;
}
}
// Define a public method to add two fractions
public FractionDemo add(FractionDemo other)
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
// Get the numerator and denominator for the first fraction
System.out.print("Enter the numerator of the first fraction: ");
int num1 = input.nextInt();
System.out.print("Enter the denominator of the first fraction: ");
int den1 = input.nextInt();
// Get the numerator and denominator for the second fraction
System.out.print("Enter the numerator of the second fraction: ");
int num2 = input.nextInt();
System.out.print("Enter the denominator of the second fraction: ");
int den2 = input.nextInt();
// Create the two Fraction objects
Fraction f1 = new Fraction(num1, den1);
Fraction f2 = new Fraction(num2, den2);
// Display the fractions
System.out.println("f1==" + f1);
System.out.println("f2==" + f2);
// Perform arithmetic operations and display the results
System.out.println(f1 + " + " + f2 + " = " + f1.add(f2));
System.out.println(f1 + " - " + f2 + " = " + f1.subtract(f2));
System.out.println(f1 + " * " + f2 + " = " + f1.multiply(f2));
System.out.println(f1 + " / " + f2 + " = " + f1.divide(f2));
}
FractionDemo.java:110: error: illegal start of expression
public static void main(String[] args)
^
FractionDemo.java:139: error: reached end of file while parsing
}
^
2 errors
The code has to be a combination of these two codes
//import statements for Scanner class
import java.util.Scanner;
public class FractionDemo
{
public static void main(String[] args)
{
// Variables for two fractions
int num1, num2, den1, den2;
// Create Scanner object to read keyboard input
Scanner keyboard = new Scanner(System.in);
// Get integers for f1 numerator and denominator
System.out.print("Enter the numerator of the first fraction: ");
num1 = keyboard.nextInt();
System.out.print("Enter the denominator of the first fraction: ");
den1 = keyboard.nextInt();
// Get integers for f2 numerator and denominator
System.out.print("Enter the numerator of the second fraction: ");
num2 = keyboard.nextInt();
System.out.print("Enter the denominator of the second fraction: ");
den2 = keyboard.nextInt();
// Instantiate the two fractions using the input values
Fraction f1 = new Fraction(num1, den1);
Fraction f2 = new Fraction(num2, den2);
// Display the two fractions and their product
System.out.println("f1 == " + f1);
System.out.println("f2 == " + f2);
System.out.println(f1 + " * " + f2 + " == " + f1.multiply(f2));
}
}
// Define a class for fractions
class Fraction
{
private int numerator;
private int denominator;
// Constructor for Fraction class
public Fraction(int num, int den)
{
this.numerator = num;
this.denominator = den;
// Check if denominator is zero and set it to 1 if true
if (den == 0)
{
System.out.println("For Fraction: ( " + num + " / " + den + " ):");
System.out.println("Denominator cannot be zero; denominator value is being reset to one.");
this.denominator = 1; // Reset denominator to 1
System.out.println("The Fraction is now: " + this);
}
}
// Define a method for multiplying two fractions
public Fraction multiply(Fraction other)
{
int num = this.numerator * other.numerator;
int den = this.denominator * other.denominator;
return new Fraction(num, den);
}
// Override the toString() method to display the Fraction objects as strings
public String toString()
{
if (denominator == 1)
return " ( " + numerator + " ) ";
else
return " ( " + numerator + " / " + denominator + " ) ";
}
}
can someone fix the errors in this code- the name needs to be Fraction.pdf

More Related Content

Similar to can someone fix the errors in this code- the name needs to be Fraction.pdf

Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
annapurnnatextailes
 
Write a program that works with fractions. You are first to implemen.pdf
Write a program that works with fractions. You are first to implemen.pdfWrite a program that works with fractions. You are first to implemen.pdf
Write a program that works with fractions. You are first to implemen.pdf
leventhalbrad49439
 
JAVA Write a class called F.pdf
JAVA  Write a class called F.pdfJAVA  Write a class called F.pdf
JAVA Write a class called F.pdf
santanadenisesarin13
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
yash production
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdf
manjan6
 
When we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfWhen we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdf
arihantkitchenmart
 
Import java
Import javaImport java
Import java
heni2121
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdf
archgeetsenterprises
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdf
eyeonsecuritysystems
 
prog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docx
prog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docxprog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docx
prog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docx
wkyra78
 
Functions
FunctionsFunctions
Functions
Swarup Boro
 
Lecture 11 compiler ii
Lecture 11 compiler iiLecture 11 compiler ii
Lecture 11 compiler ii
鍾誠 陳鍾誠
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdfTask #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
info706022
 
Here is the code with comments to solve the question. Please do rate.pdf
Here is the code with comments to solve the question. Please do rate.pdfHere is the code with comments to solve the question. Please do rate.pdf
Here is the code with comments to solve the question. Please do rate.pdf
angelfragranc
 
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
#ifndef RATIONAL_H    if this compiler macro is not defined #def.pdf#ifndef RATIONAL_H    if this compiler macro is not defined #def.pdf
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
exxonzone
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
MohamoudAbdiHussein
 
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
Interfacepackage PJ1; public interface SimpleFractionInterface.pdfInterfacepackage PJ1; public interface SimpleFractionInterface.pdf
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
sutharbharat59
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
udit652068
 

Similar to can someone fix the errors in this code- the name needs to be Fraction.pdf (20)

Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
 
Write a program that works with fractions. You are first to implemen.pdf
Write a program that works with fractions. You are first to implemen.pdfWrite a program that works with fractions. You are first to implemen.pdf
Write a program that works with fractions. You are first to implemen.pdf
 
JAVA Write a class called F.pdf
JAVA  Write a class called F.pdfJAVA  Write a class called F.pdf
JAVA Write a class called F.pdf
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdf
 
When we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfWhen we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdf
 
Import java
Import javaImport java
Import java
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdf
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdf
 
prog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docx
prog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docxprog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docx
prog 5~$AD FOR WHAT TO DO.docxprog 5alerts.txt2009-09-13.docx
 
Functions
FunctionsFunctions
Functions
 
Lecture 11 compiler ii
Lecture 11 compiler iiLecture 11 compiler ii
Lecture 11 compiler ii
 
Qe Reference
Qe ReferenceQe Reference
Qe Reference
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdfTask #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
Task #1 Correcting Logic Errors in FormulasCopy and compile the so.pdf
 
Here is the code with comments to solve the question. Please do rate.pdf
Here is the code with comments to solve the question. Please do rate.pdfHere is the code with comments to solve the question. Please do rate.pdf
Here is the code with comments to solve the question. Please do rate.pdf
 
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
#ifndef RATIONAL_H    if this compiler macro is not defined #def.pdf#ifndef RATIONAL_H    if this compiler macro is not defined #def.pdf
#ifndef RATIONAL_H   if this compiler macro is not defined #def.pdf
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
 
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
Interfacepackage PJ1; public interface SimpleFractionInterface.pdfInterfacepackage PJ1; public interface SimpleFractionInterface.pdf
Interfacepackage PJ1; public interface SimpleFractionInterface.pdf
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 

More from vinaythemodel

c) Consider the case where a sender S continuously sends frames to a r.pdf
c) Consider the case where a sender S continuously sends frames to a r.pdfc) Consider the case where a sender S continuously sends frames to a r.pdf
c) Consider the case where a sender S continuously sends frames to a r.pdf
vinaythemodel
 
Carolyn is a server at an Olive Garden restaurant and enjoys meeting n.pdf
Carolyn is a server at an Olive Garden restaurant and enjoys meeting n.pdfCarolyn is a server at an Olive Garden restaurant and enjoys meeting n.pdf
Carolyn is a server at an Olive Garden restaurant and enjoys meeting n.pdf
vinaythemodel
 
Capillary exchange- Describe how materials move out of and into capill.pdf
Capillary exchange- Describe how materials move out of and into capill.pdfCapillary exchange- Describe how materials move out of and into capill.pdf
Capillary exchange- Describe how materials move out of and into capill.pdf
vinaythemodel
 
Capillary exchange- Describe how materials move out of and into capill (1).pdf
Capillary exchange- Describe how materials move out of and into capill (1).pdfCapillary exchange- Describe how materials move out of and into capill (1).pdf
Capillary exchange- Describe how materials move out of and into capill (1).pdf
vinaythemodel
 
Can you please show the truth table as well There are three inputs r-s.pdf
Can you please show the truth table as well There are three inputs r-s.pdfCan you please show the truth table as well There are three inputs r-s.pdf
Can you please show the truth table as well There are three inputs r-s.pdf
vinaythemodel
 
Can you find the mutation (difference) between the two sequences- High.pdf
Can you find the mutation (difference) between the two sequences- High.pdfCan you find the mutation (difference) between the two sequences- High.pdf
Can you find the mutation (difference) between the two sequences- High.pdf
vinaythemodel
 
Can you fix the problem with the following code #include -iostream- #.pdf
Can you fix the problem with the following code  #include -iostream- #.pdfCan you fix the problem with the following code  #include -iostream- #.pdf
Can you fix the problem with the following code #include -iostream- #.pdf
vinaythemodel
 
Can you answer questions 30- 31 and 32 30- anterferons b- Respond be.pdf
Can you answer questions 30- 31 and 32   30- anterferons b- Respond be.pdfCan you answer questions 30- 31 and 32   30- anterferons b- Respond be.pdf
Can you answer questions 30- 31 and 32 30- anterferons b- Respond be.pdf
vinaythemodel
 
Can someone please answer this question -2 Eligibility Requirements- Y.pdf
Can someone please answer this question -2 Eligibility Requirements- Y.pdfCan someone please answer this question -2 Eligibility Requirements- Y.pdf
Can someone please answer this question -2 Eligibility Requirements- Y.pdf
vinaythemodel
 
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
Can somebody solve the TODO parts of the following problem- Thanks   D.pdfCan somebody solve the TODO parts of the following problem- Thanks   D.pdf
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
vinaythemodel
 
Can a student attending an American university raise First Amendment o.pdf
Can a student attending an American university raise First Amendment o.pdfCan a student attending an American university raise First Amendment o.pdf
Can a student attending an American university raise First Amendment o.pdf
vinaythemodel
 
can a groundwater sample with a low redox potential could indicate a-.pdf
can a groundwater sample with a low redox potential could indicate a-.pdfcan a groundwater sample with a low redox potential could indicate a-.pdf
can a groundwater sample with a low redox potential could indicate a-.pdf
vinaythemodel
 
Calculate FIS-FST- and FIT for the population with genotype frequencie.pdf
Calculate FIS-FST- and FIT for the population with genotype frequencie.pdfCalculate FIS-FST- and FIT for the population with genotype frequencie.pdf
Calculate FIS-FST- and FIT for the population with genotype frequencie.pdf
vinaythemodel
 
C language Make a program to get utime and stime From -proc-pid-stat-.pdf
C language Make a program to get utime and stime  From -proc-pid-stat-.pdfC language Make a program to get utime and stime  From -proc-pid-stat-.pdf
C language Make a program to get utime and stime From -proc-pid-stat-.pdf
vinaythemodel
 
Calculate the Current Ratios- (Please show the formula) CompanyCurre.pdf
Calculate the Current Ratios- (Please show the formula)   CompanyCurre.pdfCalculate the Current Ratios- (Please show the formula)   CompanyCurre.pdf
Calculate the Current Ratios- (Please show the formula) CompanyCurre.pdf
vinaythemodel
 
Calculate the amount of money Sean had to deposit in an investment fun.pdf
Calculate the amount of money Sean had to deposit in an investment fun.pdfCalculate the amount of money Sean had to deposit in an investment fun.pdf
Calculate the amount of money Sean had to deposit in an investment fun.pdf
vinaythemodel
 
Calculate FST for the random-mating subpopulations below based on the.pdf
Calculate FST for the random-mating subpopulations below based on the.pdfCalculate FST for the random-mating subpopulations below based on the.pdf
Calculate FST for the random-mating subpopulations below based on the.pdf
vinaythemodel
 
CALCIUM PATHWAY trace a calcium ion from the small intestine to the in.pdf
CALCIUM PATHWAY trace a calcium ion from the small intestine to the in.pdfCALCIUM PATHWAY trace a calcium ion from the small intestine to the in.pdf
CALCIUM PATHWAY trace a calcium ion from the small intestine to the in.pdf
vinaythemodel
 
Cadux Candy Company's income statement for the year ended December 31-.pdf
Cadux Candy Company's income statement for the year ended December 31-.pdfCadux Candy Company's income statement for the year ended December 31-.pdf
Cadux Candy Company's income statement for the year ended December 31-.pdf
vinaythemodel
 
Calcium - Selonosis- characterized by hair loss- weile blotchy mail- g.pdf
Calcium - Selonosis- characterized by hair loss- weile blotchy mail- g.pdfCalcium - Selonosis- characterized by hair loss- weile blotchy mail- g.pdf
Calcium - Selonosis- characterized by hair loss- weile blotchy mail- g.pdf
vinaythemodel
 

More from vinaythemodel (20)

c) Consider the case where a sender S continuously sends frames to a r.pdf
c) Consider the case where a sender S continuously sends frames to a r.pdfc) Consider the case where a sender S continuously sends frames to a r.pdf
c) Consider the case where a sender S continuously sends frames to a r.pdf
 
Carolyn is a server at an Olive Garden restaurant and enjoys meeting n.pdf
Carolyn is a server at an Olive Garden restaurant and enjoys meeting n.pdfCarolyn is a server at an Olive Garden restaurant and enjoys meeting n.pdf
Carolyn is a server at an Olive Garden restaurant and enjoys meeting n.pdf
 
Capillary exchange- Describe how materials move out of and into capill.pdf
Capillary exchange- Describe how materials move out of and into capill.pdfCapillary exchange- Describe how materials move out of and into capill.pdf
Capillary exchange- Describe how materials move out of and into capill.pdf
 
Capillary exchange- Describe how materials move out of and into capill (1).pdf
Capillary exchange- Describe how materials move out of and into capill (1).pdfCapillary exchange- Describe how materials move out of and into capill (1).pdf
Capillary exchange- Describe how materials move out of and into capill (1).pdf
 
Can you please show the truth table as well There are three inputs r-s.pdf
Can you please show the truth table as well There are three inputs r-s.pdfCan you please show the truth table as well There are three inputs r-s.pdf
Can you please show the truth table as well There are three inputs r-s.pdf
 
Can you find the mutation (difference) between the two sequences- High.pdf
Can you find the mutation (difference) between the two sequences- High.pdfCan you find the mutation (difference) between the two sequences- High.pdf
Can you find the mutation (difference) between the two sequences- High.pdf
 
Can you fix the problem with the following code #include -iostream- #.pdf
Can you fix the problem with the following code  #include -iostream- #.pdfCan you fix the problem with the following code  #include -iostream- #.pdf
Can you fix the problem with the following code #include -iostream- #.pdf
 
Can you answer questions 30- 31 and 32 30- anterferons b- Respond be.pdf
Can you answer questions 30- 31 and 32   30- anterferons b- Respond be.pdfCan you answer questions 30- 31 and 32   30- anterferons b- Respond be.pdf
Can you answer questions 30- 31 and 32 30- anterferons b- Respond be.pdf
 
Can someone please answer this question -2 Eligibility Requirements- Y.pdf
Can someone please answer this question -2 Eligibility Requirements- Y.pdfCan someone please answer this question -2 Eligibility Requirements- Y.pdf
Can someone please answer this question -2 Eligibility Requirements- Y.pdf
 
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
Can somebody solve the TODO parts of the following problem- Thanks   D.pdfCan somebody solve the TODO parts of the following problem- Thanks   D.pdf
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
 
Can a student attending an American university raise First Amendment o.pdf
Can a student attending an American university raise First Amendment o.pdfCan a student attending an American university raise First Amendment o.pdf
Can a student attending an American university raise First Amendment o.pdf
 
can a groundwater sample with a low redox potential could indicate a-.pdf
can a groundwater sample with a low redox potential could indicate a-.pdfcan a groundwater sample with a low redox potential could indicate a-.pdf
can a groundwater sample with a low redox potential could indicate a-.pdf
 
Calculate FIS-FST- and FIT for the population with genotype frequencie.pdf
Calculate FIS-FST- and FIT for the population with genotype frequencie.pdfCalculate FIS-FST- and FIT for the population with genotype frequencie.pdf
Calculate FIS-FST- and FIT for the population with genotype frequencie.pdf
 
C language Make a program to get utime and stime From -proc-pid-stat-.pdf
C language Make a program to get utime and stime  From -proc-pid-stat-.pdfC language Make a program to get utime and stime  From -proc-pid-stat-.pdf
C language Make a program to get utime and stime From -proc-pid-stat-.pdf
 
Calculate the Current Ratios- (Please show the formula) CompanyCurre.pdf
Calculate the Current Ratios- (Please show the formula)   CompanyCurre.pdfCalculate the Current Ratios- (Please show the formula)   CompanyCurre.pdf
Calculate the Current Ratios- (Please show the formula) CompanyCurre.pdf
 
Calculate the amount of money Sean had to deposit in an investment fun.pdf
Calculate the amount of money Sean had to deposit in an investment fun.pdfCalculate the amount of money Sean had to deposit in an investment fun.pdf
Calculate the amount of money Sean had to deposit in an investment fun.pdf
 
Calculate FST for the random-mating subpopulations below based on the.pdf
Calculate FST for the random-mating subpopulations below based on the.pdfCalculate FST for the random-mating subpopulations below based on the.pdf
Calculate FST for the random-mating subpopulations below based on the.pdf
 
CALCIUM PATHWAY trace a calcium ion from the small intestine to the in.pdf
CALCIUM PATHWAY trace a calcium ion from the small intestine to the in.pdfCALCIUM PATHWAY trace a calcium ion from the small intestine to the in.pdf
CALCIUM PATHWAY trace a calcium ion from the small intestine to the in.pdf
 
Cadux Candy Company's income statement for the year ended December 31-.pdf
Cadux Candy Company's income statement for the year ended December 31-.pdfCadux Candy Company's income statement for the year ended December 31-.pdf
Cadux Candy Company's income statement for the year ended December 31-.pdf
 
Calcium - Selonosis- characterized by hair loss- weile blotchy mail- g.pdf
Calcium - Selonosis- characterized by hair loss- weile blotchy mail- g.pdfCalcium - Selonosis- characterized by hair loss- weile blotchy mail- g.pdf
Calcium - Selonosis- characterized by hair loss- weile blotchy mail- g.pdf
 

Recently uploaded

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

can someone fix the errors in this code- the name needs to be Fraction.pdf

  • 1. can someone fix the errors in this code? the name needs to be FractionDemo.java //author: Jazmine Tapia //date: 20 February 2023 //file: FractionDemo.java /* Lab 13 will also be using demonstation the the multiplication of two factors. */ //import statements for Scanner class import java.util.Scanner; // Define a public class called Fraction public class FractionDemo { // Define private instance variables for the numerator and denominator private int numerator; private int denominator; // Define a constructor for the Fraction class that takes a numerator and denominator as arguments public FractionDemo(int numerator, int denominator) { // Set the denominator using the setDenominator() method defined below setDenominator(denominator); // Set the numerator this.numerator = numerator; // Reduce the fraction reduce(); // Adjust the signs of the numerator and denominator if necessary adjustSigns(); } // Define a getter method for the numerator public int getNumerator() { return numerator; } // Define a setter method for the numerator public void setNumerator(int numerator) {
  • 2. this.numerator = numerator; } // Define a getter method for the denominator public int getDenominator() { return denominator; } // Define a setter method for the denominator public void setDenominator(int denominator) { // Set the denominator using the setDenominator() method defined below setDenominator(denominator); // Reduce the fraction reduce(); // Adjust the signs of the numerator and denominator if necessary adjustSigns(); } // Define a private method to set the denominator private void setDenominator(int denominator) { // If the denominator is zero, throw an exception if (denominator == 0) { throw new IllegalArgumentException("Denominator cannot be zero"); } // Set the denominator this.denominator = denominator; } // Define a private method to calculate the greatest common divisor of two integers private int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } // Define a public method to reduce the fraction public void reduce() {
  • 3. // Calculate the greatest common divisor of the numerator and denominator int gcd = gcd(numerator, denominator); // Divide both the numerator and denominator by the greatest common divisor to reduce the fraction numerator /= gcd; denominator /= gcd; } // Define a private method to adjust the signs of the numerator and denominator if necessary private void adjustSigns() { // If the denominator is negative, multiply both the numerator and denominator by -1 to adjust the signs if (denominator < 0) { numerator *= -1; denominator *= -1; } } // Define a public method to add two fractions public FractionDemo add(FractionDemo other) { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Get the numerator and denominator for the first fraction System.out.print("Enter the numerator of the first fraction: "); int num1 = input.nextInt(); System.out.print("Enter the denominator of the first fraction: "); int den1 = input.nextInt(); // Get the numerator and denominator for the second fraction System.out.print("Enter the numerator of the second fraction: "); int num2 = input.nextInt(); System.out.print("Enter the denominator of the second fraction: "); int den2 = input.nextInt(); // Create the two Fraction objects Fraction f1 = new Fraction(num1, den1); Fraction f2 = new Fraction(num2, den2); // Display the fractions System.out.println("f1==" + f1); System.out.println("f2==" + f2);
  • 4. // Perform arithmetic operations and display the results System.out.println(f1 + " + " + f2 + " = " + f1.add(f2)); System.out.println(f1 + " - " + f2 + " = " + f1.subtract(f2)); System.out.println(f1 + " * " + f2 + " = " + f1.multiply(f2)); System.out.println(f1 + " / " + f2 + " = " + f1.divide(f2)); } FractionDemo.java:110: error: illegal start of expression public static void main(String[] args) ^ FractionDemo.java:139: error: reached end of file while parsing } ^ 2 errors The code has to be a combination of these two codes //import statements for Scanner class import java.util.Scanner; public class FractionDemo { public static void main(String[] args) { // Variables for two fractions int num1, num2, den1, den2; // Create Scanner object to read keyboard input Scanner keyboard = new Scanner(System.in); // Get integers for f1 numerator and denominator System.out.print("Enter the numerator of the first fraction: "); num1 = keyboard.nextInt(); System.out.print("Enter the denominator of the first fraction: "); den1 = keyboard.nextInt(); // Get integers for f2 numerator and denominator System.out.print("Enter the numerator of the second fraction: "); num2 = keyboard.nextInt(); System.out.print("Enter the denominator of the second fraction: "); den2 = keyboard.nextInt(); // Instantiate the two fractions using the input values Fraction f1 = new Fraction(num1, den1); Fraction f2 = new Fraction(num2, den2);
  • 5. // Display the two fractions and their product System.out.println("f1 == " + f1); System.out.println("f2 == " + f2); System.out.println(f1 + " * " + f2 + " == " + f1.multiply(f2)); } } // Define a class for fractions class Fraction { private int numerator; private int denominator; // Constructor for Fraction class public Fraction(int num, int den) { this.numerator = num; this.denominator = den; // Check if denominator is zero and set it to 1 if true if (den == 0) { System.out.println("For Fraction: ( " + num + " / " + den + " ):"); System.out.println("Denominator cannot be zero; denominator value is being reset to one."); this.denominator = 1; // Reset denominator to 1 System.out.println("The Fraction is now: " + this); } } // Define a method for multiplying two fractions public Fraction multiply(Fraction other) { int num = this.numerator * other.numerator; int den = this.denominator * other.denominator; return new Fraction(num, den); } // Override the toString() method to display the Fraction objects as strings public String toString() { if (denominator == 1) return " ( " + numerator + " ) "; else return " ( " + numerator + " / " + denominator + " ) "; } }