Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 3, Problem 4R
The TicTacToe class of Code Fragments 3.9 and 3.10 has a flaw, in that it allows a player to place a mark even after the game has already been won by someone. Modify the class so that the putMark method throws an IllegalStateException in that case.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In this java assignment, we will be creating a paystub for an employee using classes, files, getters, and setters. Each file should only have one class and the class should share the same name as the file. We are going to implement the following classes:
Employee - This class represent the employee. It needs the following fields exposed via getters and setters:
Employee ID (hard code it to 1)
First name, last name, middle initial
Address, city, zip
Phone, email
Hourly rate
PayPeriod - This class represents an employee's payment information. An employee will eventually have more than one pay period. It needs the following fields exposed via getters and setters:
Pay period Id (hard code to 123456)
Employee Id
Start date, end date
Number of hours
PayrollManager - This class provides the functionality we need to compute and display the payroll. It should implement the following methods:
double CalculateGrossPay (Employee, PayPeriod) - this should return the total gross for the…
Write a class ArrayMethods, where the main method asks the user to enter thenumber of inputs and stores them in an array called myList. Create a methodprintArray that prints the array myList. Create another method copyArray that copiesthe array using System.arraycopy, and multiplies each element in the copied array by2, then finally returns the array to the main method. Invoke the printArray again toprint the array returned by copyArray. In summary, see below. (!5 points)• main method does: asks user for inputs and stores in array. Invoke printArray. Invoke copyArray.Invoke printArray again.• printArray: void method, parameters passed is an array, prints an array• copyArray: array-returning method, parameters passed is an array, copies array, multiplies 2 to eachelement in the copied array, returns the copied arraySample RunEnter the number of items: 4Enter the numbers: 2 3 4 6Your printed array: 2 3 4 6Your copied printed array: 4 6 8 122. Write a class ArrayClass, where the main…
Java - Encapsulation
Create a class Point with attributes x and y which are both integers. Create getters and setters for these attributes and implement the following methods:
1. calculateDistance() - calculates the distance from the origin to the point. Returns a double, formula is sqrt(x^2 + y^2)
2. printCoordinates() - prints "(x,y)"
Ask for user inputs for x and y. Use the methods printCoordinates() and calculateDistance() respectively.
Inputs
1. X
2. Y
Sample Output
Enter x: 20
Enter y: 15
(20,15)
25.00
Chapter 3 Solutions
Data Structures and Algorithms in Java
Ch. 3 - Prob. 1RCh. 3 - Write a Java method that repeatedly selects and...Ch. 3 - Prob. 3RCh. 3 - The TicTacToe class of Code Fragments 3.9 and 3.10...Ch. 3 - Prob. 5RCh. 3 - Prob. 6RCh. 3 - Prob. 7RCh. 3 - Prob. 8RCh. 3 - Prob. 9RCh. 3 - Prob. 10R
Ch. 3 - Prob. 11RCh. 3 - Prob. 12RCh. 3 - Prob. 13RCh. 3 - Prob. 14RCh. 3 - Prob. 15RCh. 3 - Prob. 16RCh. 3 - Prob. 17CCh. 3 - Prob. 18CCh. 3 - Prob. 19CCh. 3 - Give examples of values for a and b in the...Ch. 3 - Suppose you are given an array, A, containing 100...Ch. 3 - Write a method, shuffle(A), that rearranges the...Ch. 3 - Suppose you are designing a multiplayer game that...Ch. 3 - Write a Java method that takes two...Ch. 3 - Prob. 25CCh. 3 - Prob. 26CCh. 3 - Prob. 27CCh. 3 - Prob. 28CCh. 3 - Prob. 29CCh. 3 - Prob. 30CCh. 3 - Prob. 31CCh. 3 - Prob. 32CCh. 3 - Prob. 33CCh. 3 - Prob. 34CCh. 3 - Prob. 35CCh. 3 - Write a Java program for a matrix class that can...Ch. 3 - Write a class that maintains the top ten scores...Ch. 3 - Prob. 38PCh. 3 - Write a program that can perform the Caesar cipher...Ch. 3 - Prob. 40PCh. 3 - Prob. 41PCh. 3 - Prob. 42PCh. 3 - Prob. 43P
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (8th Edition)
Is the following valid if ShapeBaSe is defined as in Listing 8.19? ShapeInterface shapeVariable = new ShapeBase...
Java: An Introduction to Problem Solving and Programming (7th Edition)
When a local variable has the same name as a field, the local variables name does this to the fields name. a. s...
Starting Out with Java: Early Objects (6th Edition)
Explain the use of the SQL transaction control language (TCL) statements BEGIN TRANSACTION, COMMIT TRANSACTION,...
Database Concepts (7th Edition)
Porter’s competitive forces model: The model is used to provide a general view about the firms, the competitors...
Management Information Systems: Managing The Digital Firm (16th Edition)
T F: If the CInt function cannot convert its argument, it causes a runtime error.
Starting Out With Visual Basic (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
- Please do it in java codearrow_forwardJava eclipsearrow_forwardWrite a class ArrayMethods, where the main method asks the user to enter the number of inputs and stores them in an array called myList. Create a method printArray that prints the array myList. Create another method copyArray that copies the array using System.arraycopy, and multiplies each element in the copied array by 2, then finally returns the array to the main method. Invoke the printArray again to print the array returned by copyArray.arrow_forward
- In java, Write a method void popMult(int k) for the ArrayBoundedStack class which will pop k items from this. Throw a StackUnderflowException and don't pop anything if there are fewer than k items on this. This is a method of the ArrayBoundedStack class. DO NOT USE ANY OTHER METHODS OF THE ARRAYBOUNDEDSTACK CLASS.arrow_forwardAdd a removeLot method to the Auction class, having the -following header: /** * Remove the lot with the given lot number. * @param number The number of the lot to be removed. * @return The Lot with the given number, or null if * there is no such lot. */ public Lot removeLot(int number) This method should not assume that alot with a given number is stored at any particular location within the collection.arrow_forwardThis is for pygame. Block class The Block class inherits from Drawable and it will draw a square with a black outline at its current location. You must implement at the very least the required methods of the base class (draw and get_rect), as well as a constructor. You may need to implement other methods as part of the public interface. Put all this code in a file name Block.py This is the Drawable class.arrow_forward
- Can you implement the Student class using the concepts of encapsulation? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. You are given a Student class in the editor. Your task is to add two fields: ● String name ● String rollNumber and provide getter/setters for these fields: ● getName ● setName ● getRollNumber ● setRollNumber Implement this class according to the rules of encapsulation. Input # Checking all fields and getters/setters Output # Expecting perfectly defined fields and getter/setters. There is no need to add constructors in this class.arrow_forwardAdd a method called multiplesOfFive to the Exercise class. The method must have a void return type and take a single int parameter called limit. In the body of the method, write a while loop that prints out all multiples of 5 between 10 and limit (inclusive) on a single line. For instance, if the value of limit were 15 then the method will print: 10 15 You can use the printEvenNumbers method that is already in the Exercise class as an example to help you work out how to complete this method. In the main method of the Main class, add a call on the Exercise object to your multiplesOfFive method that prints the multiples of 5 between 10 and 25. Add a method called sum to the Exercise class. The method must have a void return type and take no parameters. In the body of the method, write a while loop to sum the values 1 to 10 and print the sum once the loop has finished. In the main method of the Main class, add a call on the Exercise object to your sum method. Check that it prints: 55 Add…arrow_forwardWrite a class CountObject which has a method namenumberfoObjects() which returns the number of objects been created ofthat class. Also write a class that will create few objects of CountObjectclass and show the count. (Hint: you have to use static variable inCountObject class).arrow_forward
- Design an interface named Colorable with a voidmethod named howToColor(). Every class of a colorable object must implementthe Colorable interface. Design a class named Square that extendsGeometricObject and implements Colorable. Implement howToColor todisplay the message Color all four sides. The Square class contains adata field side with getter and setter methods, and a constructor for constructinga Square with a specified side. The Square class has a private double datafield named side with its getter and setter methods. It has a no-arg constructorto create a Square with side 0, and another constructor that creates a Squarewith the specified side.Draw a UML diagram that involves Colorable, Square, and GeometricObject.Write a test program that creates an array of five GeometricObjects. For eachobject in the array, display its area and invoke its howToColor method if it iscolorable.arrow_forwardcreate a class rectangle with attributes length and width both encapsulated, each of which defaults to 1. provide methods that calculate the rectangle’s perimeter and area. write set and get methods for both length and width tp allow their access through behaviors. the set methods should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. write a program to test class rectanglearrow_forwardin Javaarrow_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
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License