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
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
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…
First, 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…
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
In the following exercises, write a program to carry out the task. The program should use variables for each of...
Introduction To Programming Using Visual Basic (11th Edition)
T F One limitation of the for loop is that only one variable may be initialized in the initialization expressio...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Use the following tables for your answers to questions 3.7 through 3.51 : PET_OWNER (OwnerID, OwnerLasst Name, ...
Database Concepts (8th Edition)
Assume the following variable declaration exists in a program: double number = 123.456; Write a statement that ...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
State whether each of the following is true or false. If false, explain why. The following are all invalid vari...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
What is an object?
Starting Out With Visual Basic (8th 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
- One 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_forwardHello! 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_forwardPlease help me with this C++ code. Please show work and code output. Write a class definition that stores information for a book. I want to store the following information about this book.arrow_forward
- Use Java.arrow_forwardI hope you are fine, I want the code for this class .. Even if it is a small part of it, please, I want it for necessity, thanksarrow_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_forwardWhat would the implementation regarding the input section look like in Java?arrow_forward
- First, 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_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_forwardHelp, I making a elevator simulator, I need help in writing code in the Elevator class and it's polymorphism class. I am not sure what to do next. Any help is appreciated. There are 4 types of passengers in the system:Standard: This is the most common type of passenger and has a request percentage of 70%. Standard passengers have no special requirements.VIP: This type of passenger has a request percentage of 10%. VIP passengers are given priority and are more likely to be picked up by express elevators.Freight: This type of passenger has a request percentage of 15%. Freight passengers have large items that need to be transported and are more likely to be picked up by freight elevators.Glass: This type of passenger has a request percentage of 5%. Glass passengers have fragile items that need to be transported and are more likely to be picked up by glass elevators. There are 4 types of elevators in the system:StandardElevator: This is the most common type of elevator and has a request…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