Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 1, Problem 25C
Modify the CreditCard class to add a toString() method that returns a String representation of the card (rather than printing it to the console, as done by printSummary). Modify the main method from Code Fragment 1.6 accordingly to use the standard println command.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Create the compareTo method for a class that represents an individual whose first and last names are stored as two Strings. In an alphabetical list of people with last names first and then first names, one individual is "less than" another if they come before the other.(as is typical).
Add a toString() method to Fraction class that returns the fraction as aString in the form "x / y", where x and y are numerator and denominatorrespectively. As the method does not do any display itself, the output can be done by a client program that calls the method in an output statement. Use client program to test this functionality; i.e. provide an output statement to display a fraction as its String representation.
class Fraction2{private int n, d;public Fraction(){this.n = this.d = 0; //Initialize the values}public Fraction(int n, int d){this.n = n; //Initialize the variablesthis.d = d;}//Define the getter function getNum() that returns the numeratorpublic int getNum(){//Returns numeratorreturn n;}
//Define the getter function getDen() that returns the denominatorpublic int getDen(){//Returns denominatorreturn d;}//Define the boolean function isZero() that returns 0 if numerator is 0 and denominator is not equals to zeropublic boolean isZero(){return(getNum() == 0 &&…
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.
Chapter 1 Solutions
Data Structures and Algorithms in Java
Ch. 1 - Prob. 1RCh. 1 - Suppose that we create an array A of GameEntry...Ch. 1 - Write a short Java method, isMultiple, that takes...Ch. 1 - Write a short Java method, isEven, that takes an...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that takes an integer n...Ch. 1 - Write a short Java method that counts the number...Ch. 1 - Prob. 9RCh. 1 - Prob. 10R
Ch. 1 - Modify the CreditCard class from Code Fragment 1.5...Ch. 1 - Prob. 12RCh. 1 - Modify the declaration of the first for loop in...Ch. 1 - Prob. 14CCh. 1 - Write a pseudocode description of a method for...Ch. 1 - Write a short program that takes as input three...Ch. 1 - Write a short Java method that takes an array of...Ch. 1 - Prob. 18CCh. 1 - Write a Java program that can take a positive...Ch. 1 - Write a Java method that takes an array of float...Ch. 1 - Write a Java method that takes an array containing...Ch. 1 - Prob. 22CCh. 1 - Write a short Java program that takes two arrays a...Ch. 1 - Modify the CreditCard class from Code Fragment 1.5...Ch. 1 - Modify the CreditCard class to add a toString()...Ch. 1 - Write a short Java program that takes all the...Ch. 1 - Write a Java program that can simulate a simple...Ch. 1 - A common punishment for school children is to...Ch. 1 - The birthday paradox says that the probability...Ch. 1 - (For those who know Java graphical user interface...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
(Multiples of 2 with an Infinite Loop) Write an application that keeps displaying in the command window the mul...
Java How To Program (Early Objects)
True or False: A static member method may refer to non-static member variables of the same class, but only afte...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Explain the important differences between application security engineering and infrastructure security engineer...
Software Engineering (10th Edition)
E-Mail Address Book Create an application with a class named PersonEntry. The PersonEntry class should have pro...
Starting out with Visual C# (4th Edition)
A common memory matching game played by young children is to start with a deck of cards that contains identical...
Problem Solving with C++ (9th Edition)
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 (10th 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 class called Pokemon that has a name (e.g. “Pikachu”) and a number (e.g. 25). Implement a constructor that takes both values as parameters. Implement accessors for both values. Implement a toString() that returns a string in the format “Name(number)”, e.g. “Pikachu(25)”. Implement an equals(Object) method (two Pokémon are considered equal if they have the same number). Implement a hashCode() method that returns the number.(remember the equals and hashCode contract).arrow_forwardWrite the code for the timeTick method in ClockDisplay that displays hours, minutes, and seconds, or even implement the whole class if you wish.arrow_forwardCreate a class MapTester (either in your current project or in a new project). In it, use a HashMap to implement a contacts list similar to the one in the example above. (Remember that you must import java.util.HashMap.) In this class, implement two methods: public void enterNumber(String name, String number) and public String lookupNumber(String name) The methods should use the put and get methods of the HashMap class to implement their functionality.arrow_forward
- Please assist with non graded problem. Create a Calculator class that implements sum, subtraction, multiplication, and division operations, and throws an appropriate exception whenever the user attempts to perform a division by zero. Then develop a graphical interface (with JavaFx) for your calculator using TextField, Button, and Label objects, or any other graphical objects you like. Graphically display division by zero errors.arrow_forwardInstructions Below is a simple Book class. Every Book object has a title (a String) and a rating (an int). Make the Book class implement the Comparable interface. Book objects should be ordered by rating, and then (if the ratings are equal) they should be ordered alphabetically by title. Additional Notes: Regarding your code's standard output, CodeLab will ignore case errors and will ignore whitespace (tabs, spaces, newlines) altogether. Submit Book.java TestBook.java 1 import java.util.Objects; 2 3- public class Book { Reset w12345 16 17 SN: 360234-00159 cus: Unattempted dline: 08/12/22 11:59pm EDT title, int rating) { ⇒zes On: 08/12/22 11:59pm EDT jects.requireNonNull(title, "title cannot be null"); 10 - 11 16 } maiscada China ile; } if (rating 5) { throw new Illegal ArgumentException("rating must be between 0 and 5"); } this.rating = rating; ✓ History: (No Submissions)arrow_forwardImplement a toString method for the following class that returns a string containing the class name and the names and values of all instance variables.arrow_forward
- . Download the program from the instructor’s GitHub account (Ch3HW) then update it tocreate a class Student that includes four properties: an id (type Integer), a name (type String), a Major (type String) and a Grade (type Double). Use class Student to create objects (using buttonAdd) that will be read from the TextFields then save it intoan ArrayList. Perform the following queries on the ArrayList of Student objects and show the results on the listViewStudents (Hint: add buttons as needed):a) Use lambdas and streams to sort the Student objects by name, then show the results.b) Use lambdas and streams to map each Student to its name and grade, sort the results by grade (descending), then display the results.c) Use lambdas and streams to map each Student to its name and grade, to select the Students who have grade values in the range 80 to 90. Sort the results by grade value(descending), then show the results.d) Use lambdas and streams to calculate the total average of all Students…arrow_forwardalso need help Write a second constructor that takes a String array of pages as input and sets the String array instance variable equal to the input. Continue to default the page number to zero. Part 2: Write a getter and a setter method for the current page number variable. The setter should check to make sure that the input is a valid page number and only update the variable if the new value is valid. Part 3: Write a getCurrentPage method that returns the String of the current page indexed by current_page. public class Ebook{ private String[] pages; private int current_page; //constructor public Ebook() { this.pages = {"See Spot.", "See Spot run.", "Run, Spot, run."}; this.current_page = 0; }}arrow_forwardwrite a code for costumercheckout.java and test file. give explanation "implement the observers for the payment method and the scanning of the items"arrow_forward
- Write a class called listOddNumbers that prints the below picture. (Note: there is a single space between each number). Please show your code and copy and paste your console with the finished result.arrow_forward1. Write a java class called Pokemon that has a name (e.g. “Pikachu”) and a number (e.g. 25). Implement a constructor that takes both values as parameters. Implement accessors for both values. Implement a toString() that returns a string in the format “Name(number)”, e.g. “Pikachu(25)”. Implement an equals(Object) method (two Pokémon are considered equal if they have the same number). Implement a hashCode() method that returns the number. (remember the equals and hashCode contract). 2. Create a java class, PokemonComparator, that implements Comparator and compares two Pokémon in reverse order by number. For example, if Pokemon A's number is 25 and B's number is 50, compare(A, B) would return a number > 0 because B should come first. Hint: what if you subtracted the numbers? 3. Write a new class, PokemonMain, with a main method that: a. Creates a binary tree with your favorite Pokémon at the root and a new PokemonComparator. b. Insert at least 10-15 more Pokémon in any order. c.…arrow_forwardRedefine the equals method of the class Date (Display 4.13) so that it hasa parameter of type Object and follows the other guidelines we gave for anequals method. (Remember, you should use getClass(), not instanceof.)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
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY