Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 8.2, Problem 16STQ
Consider the code below, which was discussed in the previous section:
Student joe = new Student(“Joe Student”, 2001);
System.out.printin(joe.tostring());
Why is the output on two lines instead of being all on one line?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
UOWD Library is asking you to write a Java program that manages all the items in the Library. The library has books, journals, and media (DVD for example). All items have a name, author(s), and year of publication. A journal also has a volume number, while a media has a type (audio/video/interactive). The user of your program should be able to add an item, delete an item, change information of an item, list all items in a specific category (book, journal, or media), and print all items (from all categories). A menu asks the user which operation s/he wants to perform.
Important: make use of collections, inheritance, interfaces, and exception handling wherever appropriate.
Use JAVA to create a card game in which the dealer shuffles the deck and deals 13 cards out of the 52 to the player. The player sorts her hand and says whether it includes the King of Hearts. Repeat this process 4 times so that all the 52 cards are dealt. The player should return true or false without writing to the console. In response, the dealer should write on the console, "You won!" or "You loose again." Also create a unit test for the win and loose cases.
Create an orignal code with Java card graphics. Please do not reshare a similar answer!
Instructor note:
This lab is part of the assignment for this chapter.
This lab uses two Java files, LabProgram.java and SimpleCar.java. The SimpleCar class has been developed and provided to you already. You don't need to change anything in that class. Your job is to use the SimpleCar class to complete the specified tasks in the main() method of LabProgram.java
Given two integers that represent the miles to drive forward and the miles to drive in reverse as user inputs, create a SimpleCar object that performs the following operations:
Drives input number of miles forward
Drives input number of miles in reverse
Honks the horn
Reports car status
The SimpleCar class is found in the file SimpleCar.java.
Ex: If the input is:
100 4
the output is:
beep beep Car has driven: 96 miles
Chapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 8.1 - Prob. 1STQCh. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Can a derived class directly access by name a...Ch. 8.1 - Can a derived class directly invoke a private...Ch. 8.1 - Prob. 6STQCh. 8.1 - Suppose s is an object of the class Student. Base...Ch. 8.2 - Give a complete definition of a class called...Ch. 8.2 - Add a constructor to the class Student that sets...Ch. 8.2 - Rewrite the definition of the method writeoutput...
Ch. 8.2 - Rewrite the definition of the method reset for the...Ch. 8.2 - Can an object be referenced by variables of...Ch. 8.2 - What is the type or types of the variable(s) that...Ch. 8.2 - Prob. 14STQCh. 8.2 - Prob. 15STQCh. 8.2 - Consider the code below, which was discussed in...Ch. 8.2 - Prob. 17STQCh. 8.3 - Prob. 18STQCh. 8.3 - Prob. 19STQCh. 8.3 - Is overloading a method name an example of...Ch. 8.3 - In the following code, will the two invocations of...Ch. 8.3 - In the following code, which definition of...Ch. 8.4 - Prob. 23STQCh. 8.4 - Prob. 24STQCh. 8.4 - Prob. 25STQCh. 8.4 - Prob. 26STQCh. 8.4 - Prob. 27STQCh. 8.4 - Prob. 28STQCh. 8.4 - Are the two definitions of the constructors given...Ch. 8.4 - The private method skipSpaces appears in the...Ch. 8.4 - Describe the implementation of the method drawHere...Ch. 8.4 - Is the following valid if ShapeBaSe is defined as...Ch. 8.4 - Prob. 33STQCh. 8.5 - Prob. 34STQCh. 8.5 - What is an advantage of having the main...Ch. 8.5 - What Java construct allows us to define and...Ch. 8 - Consider a program that will keep track of the...Ch. 8 - Implement your base class for the hierarchy from...Ch. 8 - Draw a hierarchy for the components you might find...Ch. 8 - Suppose we want to implement a drawing program...Ch. 8 - Create a class Square derived from DrawableShape,...Ch. 8 - Create a class SchoolKid that is the base class...Ch. 8 - Derive a class ExaggeratingKid from SchoolKid, as...Ch. 8 - Create an abstract class PayCalculator that has an...Ch. 8 - Derive a class RegularPay from PayCalculator, as...Ch. 8 - Create an abstract class DiscountPolicy. It should...Ch. 8 - Derive a class BulkDiscount from DiscountPolicy,...Ch. 8 - Derive a class BuyNItemsGetOneFree from...Ch. 8 - Prob. 13ECh. 8 - Prob. 14ECh. 8 - Create an interface MessageEncoder that has a...Ch. 8 - Create a class SubstitutionCipher that implements...Ch. 8 - Create a class ShuffleCipher that implements the...Ch. 8 - Define a class named Employee whose objects are...Ch. 8 - Define a class named Doctor whose objects are...Ch. 8 - Create a base class called Vehicle that has the...Ch. 8 - Create a new class called Dog that is derived from...Ch. 8 - Define a class called Diamond that is derived from...Ch. 8 - Prob. 2PPCh. 8 - Prob. 3PPCh. 8 - Prob. 4PPCh. 8 - Create an interface MessageDecoder that has a...Ch. 8 - For this Programming Project, start with...Ch. 8 - Modify the Student class in Listing 8.2 so that it...Ch. 8 - Create a JavaFX application that uses a TextField...Ch. 8 - Prob. 10PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What output will be produced by the following code?
Absolute Java (6th Edition)
7.15 private class member function can be called by A) any other function B) only public functions in the same ...
Starting Out with C++: Early Objects
Using examples, illustrate the different types of adaptor needed to support sequential composition, hierarchica...
Software Engineering (10th Edition)
List the five major hardware components of a computer system.
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
(Count consonants and vowels) Write a program that prompts the user to enter a text file name and displays the ...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Use the following tables for your answers to questions 3.7 through 3.51 : PET_OWNER (OwnerID, OwnerLasst Name, ...
Database Concepts (7th 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
- We're going to explore the law of large numbers here with a dice rolling program. Seed the random number generator with the current time and then roll three 6-sided dice (often described as 3d6) a total of 1,000,000 times and keep track of the number of times each sum 3 - 18 occurs. Be sure to separate all functions and methods (if you chose to use a class or structure) into both the prototype and an implementation below the main. 1. Build a regular c-type function that returns a random number between 3 - 18. This will simulate a single roll of three dice. Use the prototype: int rollDice(void);2. In the main, roll the dice 1,000,000 times and tally up the results in an array. I DO NOT want each individual roll printed to screen. Let the index represent the number rolled and the value will represent the number of times that number has been rolled. For example, a[3] = 5357 a[4] = 14750...a[18] = 4981 This array set-up will mean that the result 3 occurred 5,357 times and the…arrow_forwardFirst, you need to design, code in Java, test and document a base class, Student. The Student class will have the following information: A. Title of the student (eg Mr, Miss, Ms, Mrs etc)B. A first name (given name)C. A last name (family name/surname)D. Student number (ID) – an integer number (of type long)E. A date of birth (in day/month/year format – three ints) - (Do NOT use the Date class from JAVA)The student class will have at least the following constructors and methods:(i) two constructors - one without any parameters (the default constructor), and one with parameters to give initial values to all the instance variables.(ii) a reasonable number of set and get methods.(iii) methods to compute the final overall mark and the final grade (which will be overridden in the respective child classes). These two methods will be void methods that set the appropriate instance variables. Remember one method can call another method. If you prefer, you can define a single method that sets…arrow_forwardOne last implementation, can you have the user implement their own names and employee info (like first and last name, # of hours worked, hourly rate, and their major) and it computes it for them and prints it out?arrow_forward
- Hello! I am new to Java and have nearly finished up a project involving a mortgage table, and everything is working properly, but I am running into problems with formatting. I have attached an example below comparing how my result appears compared to a friend's result looking closer to the intention. How could I make it look more like this? I can see it is due to my spacing being placed within loops, but I cannot figure out how to equalize the spacing with the principal and term printing. --------------------------------------------------------------- import java.util.Scanner;public class mortgageTest {public static void main(String args[]){Scanner inKey = new Scanner(System.in);double payment = 0;System.out.print("Enter Name: ");String name = inKey.nextLine();System.out.print("Enter Minimum Principal: ");double principal = inKey.nextDouble();System.out.print("Enter Maximum Principal: ");double endPrincipal = inKey.nextDouble();System.out.print("Enter Minimum Yearly Interest Rate:…arrow_forwardhttps://youtu.be/4hAoK54Pfdc Here is a video regarding the kit component.arrow_forwardThere are three main operations on rectangles: intersection, union, and difference. Among them, only intersection is guaranteed to return another rectangle. In general, the union of two rectangles is... two rectangles, and the difference between two rectangles is ... a whole lot of rectangles, as we will see. We let you implement rectangle intersection. Of course, the intersection is defined only if the rectangles have the same number of dimensions. The intersection is computed by taking the intersection of the intervals of the two rectangles for corresponding dimensions. If one of the intervals is empty, you should return None. [] # @ title Rectangle intersection def rectangle_and(self, other): if self.ndims != other.ndims: raise TypeError("The rectangles have different dimensions: {} and {}".format( )) self.ndims, other.ndims ### YOUR SOLUTION HERE Rectangle. _and_ = rectangle_and [ ] r1 = Rectangle((2, 3), (0, 4)) r2 = Rectangle((0, 4), (1, 3)) draw rectangles (r1, r2) draw…arrow_forward
- HangmanAA.java For this program, you will create the game Hangman. (If you are unsure of how to play Hangman, Google it.) The game will start by asking player 1 for a word or phrase (can be multiple words). Then player 1 will be asked how many missed guesses are allowed by player 2. Once this information is received, player 2 will take over. (Have the program print many blank lines of space so that player 2 can’t see what player 1 entered.) The instructions should be displayed for player 2 as well as the number of misses they’re allowed to make before they lose the game. The screen should also output dashes or underscores to represent each letter of player 1’s secret word/phrase. Player 2 should guess one letter at a time. Case should not matter. Typing x or X should give the same result. If that letter is present in the mystery phrase, then it should be displayed. (It will replace the dash/underscore in that spot. Spaces, punctuation, and all other non-alphabetic characters should…arrow_forwardIn this lab work, you will implement a coffee shop example. In this coffee shop, everything must progress as if it does in real life. It means that the program should ask a person for body temperature in Celsius, and grant or reject access to a coffee shop. When a customer orders a coffee, they have to choose a size such as Small, Medium, and Large then, depending on the order, the price has to change. The price also has to change depending on the type of coffee. For example, for coffees that are similar to espresso, you also need to take every shot of espresso into account. The actual prices of the coffees depend on your imagination however, they should be realistic. Some hints: • Focus on dividing your program into multiple functions. • You can also return double or integer types of values from your functions, so use them if you can. • Don't just code a function every possible type of, and try to make it generic as much as possible. • Be creative. Fill the gaps using your…arrow_forwardhow to answer the follow question in java In between is a well-known card game. Many variations exist- we define it as follows. One deck of card is used. A game consist of one or more hands. A player starts with a certain number of chips called the stake (say 100) and must risk one or more chips on each hand, before seeing any cards, as long as the player still has chips and there are three or more card left in the desk(enough to play one hand), the game continues. For each hand player must risk the player For each hand the player must risk between one and their total number of chips. Two cards are dealt face up. Then the third card is dealt. If the third card is in between the first two cards, based on ranks of the cards, the player’s chips are increase by the amount risked. Otherwise they decreased by the amount. A implement the game. The application user is the player (GUI not require) (only three cards is required to play). If the first two cards are the same rank, that hand is…arrow_forward
- Modify songVerse to play "The Name Game" (see OxfordDictionaries.com), by replacing "(Name)" with userName but without the first letter.Ex: If userName = "Katie" and songVerse = "Banana-fana fo-f(Name)!", the program prints:Banana-fana fo-fatie! Ex: If userName = "Katie" and songVerse = "Fee fi mo-m(Name)", the program prints:Fee fi mo-matie Note: You may assume songVerse will always contain the substring "(Name)" #include <iostream>#include <string>using namespace std; int main() {string userName;string songVerse; getline(cin, userName);userName = userName.substr(1, userName.size() - 1); // Remove first character getline(cin, songVerse); // Modify songVerse to replace (Name) with userName without first character /* Your solution goes here */ cout << songVerse << endl; return 0;} Please help me with this string operations problem using C++.arrow_forwardImplement the design of the Pizza class so that the following output is produced:# Write your codes here.# Do not change the following lines of code.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_forwardFirst, you need to design, code in Java, test and document a base class, Student. The Student class willhave the following information, and all of these should be defined as Private:A. Title of the student (eg Mr, Miss, Ms, Mrs etc)B. A first name (given name)C. A last name (family name/surname)D. Student number (ID) – an integer number (of type long)E. A date of birth (in day/month/year format – three ints) - (Do NOT use the Date class fromJAVA)The student class will have at least the following constructors and methods:(i) two constructors - one without any parameters (the default constructor), and one withparameters to give initial values to all the instance variables.(ii) only necessary set and get methods for a valid class design.(iii) method to write the output of all the instance variables in the class to the screen (which willbe overridden in the respective child classes, as you have more instance variables thatrequired to be output).(iv) an equals method which compares two…arrow_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
The Top Down Approach to Software Development; Author: Christopher Kalodikis;https://www.youtube.com/watch?v=v9M8LA2uM48;License: Standard YouTube License, CC-BY