Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.9, Problem 13.9.1CP
Show the output of the following code:
Rational r1 = new Rational(–2, 6);
System.out.println(r1.getNumerator());
System.out.println(r1.getDenominator())
System.out.println(r1.intValue());
System.out.println(r1.doubleValue());
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that reads HAND_SIZE cards from the user, then analyzes the cards and prints out the type of poker hand that they represent. (HAND_SIZE will be a global constant, typically 5, but your program must still work if it is set to something other than 5.)
Poker hands are categorized according to the following hand-types: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card.
To simplify the program we will ignore card suits, and face cards. The values that the user inputs will be integer values from LOWEST_NUM to HIGHEST_NUM. (These will be global constants. We'll use LOWEST_NUM = 2 and HIGHEST_NUM = 9, but your program must work if these are set to something different.) When your program runs it should start by collecting HAND_SIZE integer values from the user and placing the integers into an array that has HAND_SIZE elements. It might look like this:
Enter 5 numeric cards, no face cards. Use 2 - 9.
Card 1: 8
Card 2: 7
Card…
Write a program that reads HAND_SIZE cards from the user, then analyzes the cards and prints out the type of poker hand that they represent. (HAND_SIZE will be a global constant, typically 5, but your program must still work if it is set to something other than 5.)
Poker hands are categorized according to the following hand-types: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card.
To simplify the program we will ignore card suits, and face cards. The values that the user inputs will be integer values from LOWEST_NUM to HIGHEST_NUM. (These will be global constants. We'll use LOWEST_NUM = 2 and HIGHEST_NUM = 9, but your program must work if these are set to something different.) When your program runs it should start by collecting HAND_SIZE integer values from the user and placing the integers into an array that has HAND_SIZE elements. It might look like this:
Enter 5 numeric cards, no face cards. Use 2 - 9. Card 1: 8 Card 2: 7 Card…
What is the probability that in a classroom of x people, at least 2 will be born on the same day of the year (ignore leap year)? Use a Monte Carlo Simulation and a frequency table to write a program that calculates this probability, where the number of people (x) in the simulated class is given by the user. The probability for a class of size 23, should be right around 50%.
NO language of "break" or "true" please!
Please use the outline given below for the code:
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
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...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What is a decision structure?
Starting Out with Python (3rd Edition)
In Exercises 53 through 56, determine the output produced by the lines of code where Courier New is the font se...
Introduction To Programming Using Visual Basic (11th Edition)
Why are field values sometimes coded?
Modern Database Management
Distinguish among data definition commands, data manipulation commands, and data control commands.
Modern Database Management (12th Edition)
Determine by row and column number which fusible links must be blown in the programmable AND array of Figure 3-...
Digital Fundamentals (11th Edition)
What will the following program display? public class Checkpoint { public static void main(String[] args) { int...
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
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.Similar questions
- Write a program that computes the following summation series using the Rational class:arrow_forwardWrite a unit test for addInventory(), which has an error. Call redSweater.addInventory() with parameter sweaterShipment. Print the shown error if the subsequent quantity is incorrect. Sample output for failed unit test given initial quantity is 10 and sweaterShipment is 50: Beginning tests. UNIT TEST FAILED: addInventory() Tests complete. // ===== Code from file InventoryTag.java =====public class InventoryTag {private int quantityRemaining; public InventoryTag() {quantityRemaining = 0;} public int getQuantityRemaining() {return quantityRemaining;} public void addInventory(int numItems) {if (numItems > 10) {quantityRemaining = quantityRemaining + numItems;}}}// ===== end ===== // ===== Code from file CallInventoryTag.java =====import java.util.Scanner; public class CallInventoryTag {public static void main(String [] args) {Scanner scnr = new Scanner(System.in);InventoryTag redSweater = new InventoryTag();int sweaterShipment;int sweaterInventoryBefore; sweaterInventoryBefore =…arrow_forwardJava - public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); } What is printed by the call test_b(6)?arrow_forward
- Determine the output for the following code. Box in your final output result. public class Beta extends Baap { public int h = 44; public int getH( ) { System.out.println("Beta " + h); return h; } public static void main(String[ ] args) { Baap b = new Beta(); System.out.println(b.h + " " + b.getH( )); Beta bb = (Beta) b; System.out.println(bb.h + " " + bb.getH( )); } } public class Baap { public int h = 4; public int getH( ) { System.out.println("Baap " + h); return h; } }arrow_forwardWhat are the differences between call by value and call by reference? What kindof problems can be arised if we want to swap the value of two variables using callby value method? How can we solve that problem using call by referencemethod? Explain with examples.arrow_forwardWrite a program in C++ that reads HAND_SIZE cards from the user, then analyzes the cards and prints out the type of poker hand that they represent. (HAND_SIZE will be a global constant, typically 5, but your program must still work if it is set to something other than 5.) Poker hands are categorized according to the following hand-types: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card. To simplify the program we will ignore card suits, and face cards. The values that the user inputs will be integer values from LOWEST_NUM to HIGHEST_NUM. (These will be global constants. We'll use LOWEST_NUM = 2 and HIGHEST_NUM = 9, but your program must work if these are set to something different.) When your program runs it should start by collecting HAND_SIZE integer values from the user and placing the integers into an array that has HAND_SIZE elements. It might look like this: Enter 5 numeric cards, no face cards. Use 2 - 9. Card 1: 8 Card 2:…arrow_forward
- This is a debugging question - The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Code given - public abstract class DebugBoat { String boatType = new String(); int passengers String power = new String(); public FebugBoat(String bt) { boatType = bt; } public boolean equals(otherBoat) { boolean result; if((passengers == otherBoat.passengers) && (power.equals(otherBoat.power))) result = true; else result = true; return result } public String toString() { return("This " + boatType + "boat carries " + passengers + " and is powered by + power); } public abstract void setPower(); public abstract void setPassengers(); } // Creates and displays an array of boats - // some are rowboats; some are ocean liners import…arrow_forwardImplement the design of the Pizza class so that the following output is produced:[Your code should work for any number of parameters added in the set_toppings_info method]# Write your codes here.print("Pizza Count:", Pizza.pizza_count)print("=======================")p1 = Pizza("Chicken")p1.set_toppings_info(25, 1, 4, 0)p1.display()print("------------------------------------")p2 = Pizza("Olives")p2.set_toppings_info(15, 1.5, 0, 0)p2.display()print("------------------------------------")p3 = Pizza("Sausage")p3.set_toppings_info(50, 5, 2, 0)p3.display()print("=======================")print("Pizza Count:", Pizza.pizza_count)Output:Pizza Count: 0=======================Toppings: Chicken25 calories1 g fat4 g protein0 g carbs------------------------------------Toppings: Olives15 calories1.5 g fat0 g protein0 g carbs------------------------------------Toppings: Sausage50 calories5 g fat2 g protein0 g carbs=======================Pizza Count: 3arrow_forwardIn a method that takes stack parameters and uses local variables, what kinds of statements should be included in the conclusion?arrow_forward
- Write a method (in C++), called CheckLetter. The method receives a letter as a parameter and returns whether the letter is a lowercase vowel (a, e, i, o, u) or not. Sample outputs are: The entered letter is: aa is a vowel. The entered letter is: bb is not a vowel.arrow_forwardWrite an application in java that prints the sum of cubes. Promptfor and read two integer values and print the sum of eachvalue raised to the third power.arrow_forwardpublic void TestValues( int a, int b, ref int x ) { if (a > 0) && (b > 0) x = 1; if (a < 0) && (b < 0) x = -1; } Generate test cases for the code based on MC/DC coverage criteriaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY