java program Add a divide method to the following program to take another Fraction as the parameter and return a new Fraction that is the division of current Fraction and the Fraction in the parameter. (public Fraction divide(Fraction f)). - Add scaleup and scaledown methods to the Fraction class. The scaleup method will take a factor as the parameter and multiply the numerator by the factor. The scaledown method will take a factor as the parameter and multiply the denominator by the factor. - Add a scale method that will have two parameters: factor and flag. The flag is boolean. If flag is true, then scale up the fraction; otherwise scale down the fraction. - Both scaledown and scale methods must check if the factor is 0. If it is 0, a warning message is printed out and no scaling is operated. - Add two more constructors. One of the constructors will have no parameters; it initializes the fraction to 0/1. The other constructor will have one parameter, representing the numerator of the fraction; the denominator of the fraction will be 1. - Write a program named FractionScale that prompts the user of a fraction and a scale factor. Here is what the user will see on the screen: This program performs the scaling operations on a fraction. Enter a fraction: 3/7 Scale up or down (1: up, 0: down): 1 Enter a scale factor: 2 Output: Scaled fraction is: 6/7 You can assume that the user always enters two integers separated by a slash (/) for the faction. However, the user may enter any number of spaces before and after each integer. Code: public class Fraction { // Instance variables private int numerator; // Numerator of fraction private int denominator; // Denominator of fraction // Constructors public Fraction(int num, int denom) { numerator = num; denominator = denom; } // Instance methods public int getNumerator() { return numerator; } public int getDenominator() { return denominator; } public Fraction add(Fraction f) { int num = numerator * f.denominator + f.numerator * denominator; int denom = denominator * f.denominator; return new Fraction(num, denom) } }
java program Add a divide method to the following program to take another Fraction as the parameter and return a new Fraction that is the division of current Fraction and the Fraction in the parameter. (public Fraction divide(Fraction f)). - Add scaleup and scaledown methods to the Fraction class. The scaleup method will take a factor as the parameter and multiply the numerator by the factor. The scaledown method will take a factor as the parameter and multiply the denominator by the factor. - Add a scale method that will have two parameters: factor and flag. The flag is boolean. If flag is true, then scale up the fraction; otherwise scale down the fraction. - Both scaledown and scale methods must check if the factor is 0. If it is 0, a warning message is printed out and no scaling is operated. - Add two more constructors. One of the constructors will have no parameters; it initializes the fraction to 0/1. The other constructor will have one parameter, representing the numerator of the fraction; the denominator of the fraction will be 1. - Write a program named FractionScale that prompts the user of a fraction and a scale factor. Here is what the user will see on the screen: This program performs the scaling operations on a fraction. Enter a fraction: 3/7 Scale up or down (1: up, 0: down): 1 Enter a scale factor: 2 Output: Scaled fraction is: 6/7 You can assume that the user always enters two integers separated by a slash (/) for the faction. However, the user may enter any number of spaces before and after each integer. Code: public class Fraction { // Instance variables private int numerator; // Numerator of fraction private int denominator; // Denominator of fraction // Constructors public Fraction(int num, int denom) { numerator = num; denominator = denom; } // Instance methods public int getNumerator() { return numerator; } public int getDenominator() { return denominator; } public Fraction add(Fraction f) { int num = numerator * f.denominator + f.numerator * denominator; int denom = denominator * f.denominator; return new Fraction(num, denom) } }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
java program
Add a divide method to the following program to take another Fraction as the parameter and return a new Fraction that is the division of current Fraction and the Fraction in the parameter. (public Fraction divide(Fraction f)).
- Add scaleup and scaledown methods to the Fraction class. The scaleup method will take a factor as the parameter and multiply the numerator by the factor. The scaledown method will take a factor as the parameter and multiply the denominator by the factor.
- Add a scale method that will have two parameters: factor and flag. The flag is boolean. If flag is true, then scale up the fraction; otherwise scale down the fraction.
- Both scaledown and scale methods must check if the factor is 0. If it is 0, a warning message is printed out and no scaling is operated.
- Add two more constructors. One of the constructors will have no parameters; it initializes the fraction to 0/1. The other constructor will have one parameter, representing the
numerator of the fraction; the denominator of the fraction will be 1.
- Write a program named
FractionScale that prompts the user of a fraction and a scale
factor. Here is what the user will see on the screen:
This program performs the scaling operations on a fraction.
Enter a fraction: 3/7
Scale up or down (1: up, 0: down): 1
Enter a scale factor: 2
Output:
Scaled fraction is: 6/7
You can assume that the user always enters two integers separated by a slash (/) for the faction. However, the user may enter any number of spaces before and after each integer.
Code:
public class Fraction {
// Instance variables
private int numerator; // Numerator of fraction
private int denominator; // Denominator of fraction
// Constructors
public Fraction(int num, int denom) {
numerator = num;
denominator = denom;
}
// Instance methods
public int getNumerator() {
return numerator;
}
public int getDenominator() {
return denominator;
}
public Fraction add(Fraction f) {
int num = numerator * f.denominator + f.numerator * denominator;
int denom = denominator * f.denominator;
return new Fraction(num, denom)
}
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education