Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 13, Problem 13.15PE
Program Plan Intro

BigInteger.Java

Program Plan:

  • Include a class name named “Exercise_13_15”.
    • Declare package.
    • Declare main method.
    • Declare variables to create and initialize two rational numbers “r1” and “r2” using BigInteger() method.
    • Print addition of two rational numbers.
    • Print subtraction of two rational numbers.
    • Print multiply of two rational numbers.
    • Print division of two rational numbers.
    • Print double value of rational number.
    • Close the main method.
  • Close the class.
  • Include a class name named “Rational”.
    • Declare package.
    • Declare main method.
    • Create Data fields for numerator and denominator.
    • Create a rational constructor with default properties.
    • Create a rational constructor and assign numerator and denominator.
      • Declare variable gcd.
      • Compare the denominator with 0 and use of ternary operator.
    • Define a method to find GCD of two numbers.
      • Declare variable n1 and n2.
      • Compare n1 and n2 using the comapreTo() method.
      • return the gcd of n1 and n2.
    • Define a method to return numerator.
    • Define a method to return denominator.
    • Define a method to add a rational number to this rational.
      • Add rational number.
    • Declare a method to subtract a rational number from this rational.
    • Declare a method to multiply a rational number by this rational.
    • Declare a method to divide a rational number by this rational.
    • Declare an override method to implement the abstract intValue() method in Number.
    • Declare an override method to implement the abstract floatValue() method in Number.
    • Declare an override method to implement the doubleValue() method in number.
    • Declare an override method to implement the abstract longValue() method in number.
    • Declare an override method to implement the compareTo method in Comparable
    • Close the main method.
  • Close the class.

Blurred answer
Students have asked these similar questions
(Conversions between feet and meters) Write a class that contains the following two methods: /** Convert from feet to meters */ public static double footTOMeter(double foot) /** Convert from meters to feet */ public static double meterToFoot(double meter) The formula for the conversion is: meter = 0.305 * foot foot = 3.279 * meter Write a test program that invokes these methods to display the following tables: Feet Meters Meters Feet 1.0 0.305 20.0 65.574 2.0 0.610 25.0 81.967 ... 9.0 2.745 60.0 196.721 10.0 3.050 65.0 213.115
(Convert decimals to fractions) Write a program that prompts the user to enter a decimal number and displays the number in a fraction. Hint: read the decimal number as a string, extract the integer part and fractional part from the string, and use the Rational class  to obtain a rational number for the decimal number. Sample Run 1Enter a decimal number: 3.25 The fraction number is 13/4 Sample Run 2Enter a decimal number: -0.45452 The fraction number is -11363/25000
(Game: ATM machine) Use the Account class created in our previous Lab Exercise to simulate an ATM machine. Create ten accounts in an array with id 0, 1, . . ., 9, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. Thus, once the system starts, it will not stop.

Chapter 13 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning