Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.9, Problem 13.9.4CP
Simplify the code in lines 82–85 in Listing 13.13 Rational.java using one line of code without using the if statement. Simply the code in lines 110-115 using a conditional operator.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a code in Java Programming
Your task is to simulate a coffee shop using the observer pattern (do not use the deprecate one). The coffee shop serves two types of coffee: espresso and cappuccino. The shop has two baristas, EspressoBarista and CappuccinoBarista.
EspressoBarista generates random espresso orders between 1 and 3 every 2 seconds, while CappuccinoBarista generates random cappuccino orders between 1 and 3 every 3 seconds.
The UML design diagram is shown below.
Property ChangeListenerfac Observablenerfacto Coffeeshop HashMap Sting, integer> ingredients ExpresssCartate
The CoffeeShop class holds the current stock of ingredients and the CoffeeShop constructor initializes the count for each ingredient. The required ingredients for each type of coffee are as follows:
• Espresso: 1 shot of espresso, 1 ounce of milk
Cappuccino: 1 shot of espresso, 2 ounces of milk, 1 ounce of foam
If an order cannot be fulfilled because there are not enough ingredients, a warning message…
Write the Program in C language.
Write a program where you have to take 2 numerical inputs and 1 input for operator {theoperator input has to be either ‘+’, ’-’, ’*’). Depending on some comparisons, you need to carryout three operations: addition ( + ), subtraction ( - ), and multiplication ( * ). Each of theseoperations will be implemented in separate methods.
i. If the first number is greater than the second number, do subtraction and print theresult.ii. If the first number is less than the second number, perform addition and print the result.iii. If the first number is equal to the second number, do multiplication and print the result.
For the code in java below it shows a deck of 52 cards and asks the name of the two players and makes both players draw five cards from the deck. The code also makes Player A pick a card and Player B has to pick two cards that equal the same value as Player A's card.
What I want to be added to the code if for the cards that have been used to be removed and replaced with the other cards in the deck and for the next round to begin with Player B picking a card and Player A picking two cards that equal the same value as Player B's card.
I also want the game to keep going between Player A and B until the cards in the deck run out.
Main class code:
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
import java.util.Random;
class Main {
publicstaticvoid main(String[] args) {
String[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"};
String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
for(String oneSuit : suits){
for(String num :…
Chapter 13 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global 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
True or False: In a nested loop, the inner loop goes through all of its iterations for every iteration of the o...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Why is the study of database technology important?
Database Concepts (8th Edition)
ICA 8-34
A sensor is submerged in a silo to detect any bacterial growth in the stored fluid. The stored fluid h...
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Fill in the blanks in each of the following statements: A relation that has no partial functional dependencies ...
Modern Database Management
List Template Create a list class template based on the list class you created in the previous programming chal...
Starting Out with C++ from Control Structures to Objects (9th Edition)
The current source in the circuit shown generates the current pulse
Find (a) v (0); (b) the instant of time gr...
Electric Circuits. (11th 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
- A postfix expression is an expression in which each operator follows its operands. Figureabove shows an examples of postfix expressions.The advantage of postfix form is that there is no need to group subexpressions in parentheses or to consider operator precedence. One may have used pocket calculators that require entry of expressions in postfix form.Write a program that simulates the operation of a calculator by scanning an integer expression in postfix form and displaying its result. The program should push eachinteger operand onto the stack. When an operator is encountered, the top two operands are popped, the operation is performed on its operands, and the result is pushed back onto the stack. The final result should be the only value remaining on the stack when the end of the expression is reached. This program scans a postfix expression and evaluates it. The Postfix expression must be followed by a space and a '?' to mark the end of the expression. One must use stack and the…arrow_forwardJava considers the String data type as non-primitive, because it contains a sequence of characters and hence there is a predefined class called String dedicated to String processing. The String class has a lot of functions and continues to grow. See https://www.tutorialspoint.com/java/java_strings.htm for more on strings. Your task is to then create a java program that when give a sentence will replace the first occurrence of NUST with Namibia University of Science and Technology. Sample run 1: --- Input ---Welcome to my NUST --- Expected output (text)---Welcome to my Namibia University of Science and Technology. Sample run 2: --- Input ---The nust is a great institution of high learning. --- Expected output (text)---The Namibia University of Science and Technology is a great institution of high learning. Sample run 3: --- Input ---The NuSt was renamed from Polytechnic Of Namibia under Act No. 7 of 2015. --- Expected output (text)---The Namibia University of Science and…arrow_forwardFor the code in java below it shows a deck of 52 cards and asks the name of the two players and makes both players draw five cards from the deck. What I want to be added onto the code is the possibility for Player A too chose whatever card they want from his/her 5 cards and Player B has to chose two cards from his/her 5 cards that equal in value of Player A's card. I also want the cards that have been used to be replaced by different cards in the deck of 52 cards and that game to go on until the deck runs out of cards. Main class code: import java.util.ArrayList; import java.util.Scanner; import java.util.List; import java.util.Random; class Main { publicstaticvoid main(String[] args) { // card game, two players, take turns. String[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"}; String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; for(String oneSuit : suits){ for(String num : numbers){ System.out.println(oneSuit + " " + num); } }…arrow_forward
- WRITE A JAVA PROGRAM? Tags: String Problem Description Puan Ruqayyah, Madam Chong and Miss Lela teach their dyslexia students to identify characters. They tested randomly on strings of characters and numbers. They found that a few children get excited when they read certain series of strings. The teachers were curious and began to find out that these kids love strings that have series of characters that can be read similarly from right and from left.There are not that many meaningful words and numbers with such pattern. The teachers are interested to collect these meaningful words and numbers to share with their dyslexia students. Examples of such strings are CIVIC, KAPAK, 2102012 (which is 2nd Oct 2012), 1102011 (which is 1st Oct 2011), among others.Now, you are to help Puan Ruqayyah and her colleagues to select such strings. Write a program that reads in a sequence of characters and determine if it can be read similarly from right and from left. InputThe first line of…arrow_forwardIn c++ code. Correct code and output screenshot.else you get downvote. grouping of round and square sections is given. You can change the arrangement by playing out the accompanying activities: shift the bearing of a section from opening to shutting as well as the other way around without changing the type of the section: for example you can change '(' to ')' and ')' to '('; you can change '[' to ']' and ']' to '['. The activity costs 0 burles. change any square section to adjust section having a similar course: for example you can change '[' to '(' yet not from '(' to '['; comparably, you can change ']' to ')' however not from ')' to ']'. The activity costs 1 burle. The activities can be acted in any request quite a few times. You are given a string s of the length n and q inquiries of the kind "l r" where 1≤l<r≤n. For each substring s[l… r], track down the base expense to pay to make it a right section grouping. It is ensured that the substring s[l… r] has an even length.…arrow_forwardFinish the 2 "TODO" in the ASM Language! A palindrome is a word that is spelled the same way forwards and backwards. For example, "radar", "racecar", "civic", "kayak", and "madam" are all palindromes. The definition can be extended to phrases and sentences when ignore case and punctuation, but for this exercise we will stick to a single word. The starter code provided uses the C library functions printf and scanf to prompt for an input a word. The word that is entered from the keyboard is a null-terminated string placed in the byte array at address buf. There are also two output strings provided at addresses str_is_palindrome and str_is_not_palindrome. The starter code provided simply outputs the string at str_is_not_palindrome. The code contains two TODO comments... At the first TODO comment, the byte array at buf is filled with input from the keyboard. This input is a null-terminated character string (i.e. the array contains the characters entered on the keyboard, followed by ASCII…arrow_forward
- C++arrow_forwardDraw the JSP diagram of this program ?Write a program that prompts the user of his age. If he is younger than 15, the text “you will got to the stick to the bike some more time” should be printed. Otherwise the text “you allowed to drive moped” should be printed.arrow_forwardWrite a C program for a match-stick game between the computer and a user. Your program should ensure that the computer always wins. Rules for the game are as follows: • There are 21 match-sticks. • The computer asks the player to pick 1, 2, 3, or 4 match sticks. • After the person picks, the computer does its picking. • Whoever is forced to pick up the last match-stick loses the game.arrow_forward
- Language: Java Write a program that reads a sentence from the keyboard. Depending on the last character of the sentence, print the message identifying the sentence as declarative (ends with a period), interrogative (ends with a question mark), exclamatory (end with an exclamation point), or other. Hint: you can use charAt() method from the String class to extract the last character of the input line. The character of a String str is at str.length()-1 position. For taking a sentence as input use the nextLine() method from the Scanner class. You have to use if/else if selection. Sample input and output: Sample 1 Input: How are you? Output: Interrogative Sample 2 Input: I am good. Output: Declarative Sample 3 Input: That is amazing! Output: Exclamatory Sample 4 Input: Although, Output: Other Answer:arrow_forwardWrite a Java program Consider the structure of one example of inputs and outputs that is given in the first picture The structure of the code must be as it is shown in the second picturearrow_forwardIN C++ programming This question is inspired by the famous Uno card game. Write an activity that takes two arguments: (1) the player's current hand and (2) the current upward card on the table. Work will be back true if the player is able to make the game, or false if the player must draw on the deck. A player can make a game if: They have a card the same color as the upside card. They have the same number card as the upside card. canPlay (["yellow 3", "yellow 7", "blue 8", "red 9", "red 2"], "red 1") => trutharrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY