Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 10E

Suppose that you are going to create an object used to count the number of people in a room. We know that the number of people in the room can never be negative. Create a RoomCounter class having three public methods:

  • addPerson—adds one person to the room
  • removePerson—removes one person from the room
  • getCount—returns the number of people in the room

If removePerson would make the number of people less than zero, throw a NegativeCounterException.

Blurred answer
Students have asked these similar questions
Write a compareTo method that compares two Song objects based on the artist, and title within artist. For example, given the following Songobjects:   "Glass Animals"​​"Heat Waves" "Elton John, Dua Lipa"​"Cold Heart" "Adele"​​​"Easy on Me" "Doja Cat"​​"Kiss Me More" "Adele"​​​"My Little Love"   They will be put in the following order: "Adele"​​​"Easy on Me" "Adele"​​​"My Little Love" "Doja Cat"​​"Kiss Me More" "Elton John, Dua Lipa"​"Cold Heart" "Glass Animals"​​"Heat Waves"  In which class does the compareTo method belong?
I am creating a digital clock and I am trying to make sure that it does not allow an hour less than zero. All of my others paramters are being met (the clock is being created at hour zero and is creating at hour 23) however, I can't figure out why it is allowing hours that are less than zero. This is my code: public class DigitalClock {    private int currentHour;    private int currentMinutes;    public int getHour()     {        return currentHour;    }    public void setHour(int currentHour)     {        this.currentHour = currentHour;    }    public int getMinutes()     {        return currentMinutes;    }    public void setMinutes(int currentMinutes)     {        this.currentMinutes = currentMinutes;    }    public DigitalClock (int hour, int minutes)     {         if (hour <= 0 && hour <= 23)         currentHour = hour;      else         currentHour = 0;      if (0 <= minutes && minutes <=59)         currentMinutes = minutes;      else…
Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces. For example: 100.5 30.4 pizza 56.8 1000.3 8.2 Also suppose that you have a particular item that you know the price of. Let’s use the following example: Kindle: 99.99 Write a static method: public static double priceIsRight(Scanner s, double price) that takes a Scanner and an item price as parameters and returns the bid that is closest to the item price but not greater than the item price. If all bids are greater than the price, return 0.0. If there are no bids (Scanner is empty) return 0.0. You can assume the Scanner is not null.   In the above example. 56.8 should be returned, since it is the number that is closest to 99.99 but not over 99.99.   Notice that there may be some invalid tokens in the Scanner's input. The above example has pizza as one of its tokens, which is clearly not a valid bid. Your method should throw these tokens away and not consider them as bids.   It is probably…

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY