Answer the given question with a proper explanation and step-by-step solution. I need help with this Java code using this Rational class:

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
icon
Related questions
Question

Answer the given question with a proper explanation and step-by-step solution.

I need help with this Java code using this Rational class:

I need to create a Test file that input this example:
• You are going to build a constructor for class
Rational with an input string such as:
- Ex1: "-5/7" or Ex2: "-5/ 7" or
- Ex3: "-75"
- Ex4: " 1 1/ 3" (a new form)
Transcribed Image Text:I need to create a Test file that input this example: • You are going to build a constructor for class Rational with an input string such as: - Ex1: "-5/7" or Ex2: "-5/ 7" or - Ex3: "-75" - Ex4: " 1 1/ 3" (a new form)
import java.util.Scanner:
class Rational {
private a myte new sc():
Scanter
istum;
ist den
Rational (ins, int n) [
in myde.find(m, n)
/g/
den/97
Rational (
zum D:
den - 11
new Scanner(System.in);
Rational (int) (
21:
den = 1:
Rational (String input) (
String[] parts input.trim().split("\\+1)
if (parts.length-1) (
I
nun Integer.parseins (parsa (03)
den - 1/
} else if (parta.length2) |
num= Integer.parseInt (pars[0])
den
Integer.parseInt (part1))
int gaysc.findGCD(n, den);
tum/g:
den /-g
else if (parts.length31 (
int whole
int numerator Integer.parseInt(parte(11)
int denominator Integer.parseInt (parta[3
un shole denominator numerator!
den denominato
int gaysc.findGCD(n, den);
tu/g:
den /-g
Integer.parseInt(part (03)
els [
throw new IllegalArgumentException ("Invalid input format"):
public sering string(
Sering a
if (den
1) (
return
= "/" den!
And this findGCD class:
public class sc {
public static int findGCD (int n, int m) {
while (n != m) {
if (n> m) {
n = n - m;
} else {
}
m = m = n;
return n;
private int findGCD2 (int n, int m) {
if (m== 0) {
I return n;
} else {
return findGCD2 (m, n8 m);
Transcribed Image Text:import java.util.Scanner: class Rational { private a myte new sc(): Scanter istum; ist den Rational (ins, int n) [ in myde.find(m, n) /g/ den/97 Rational ( zum D: den - 11 new Scanner(System.in); Rational (int) ( 21: den = 1: Rational (String input) ( String[] parts input.trim().split("\\+1) if (parts.length-1) ( I nun Integer.parseins (parsa (03) den - 1/ } else if (parta.length2) | num= Integer.parseInt (pars[0]) den Integer.parseInt (part1)) int gaysc.findGCD(n, den); tum/g: den /-g else if (parts.length31 ( int whole int numerator Integer.parseInt(parte(11) int denominator Integer.parseInt (parta[3 un shole denominator numerator! den denominato int gaysc.findGCD(n, den); tu/g: den /-g Integer.parseInt(part (03) els [ throw new IllegalArgumentException ("Invalid input format"): public sering string( Sering a if (den 1) ( return = "/" den! And this findGCD class: public class sc { public static int findGCD (int n, int m) { while (n != m) { if (n> m) { n = n - m; } else { } m = m = n; return n; private int findGCD2 (int n, int m) { if (m== 0) { I return n; } else { return findGCD2 (m, n8 m);
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Top down approach design
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education