Java: Introduction to Problem Solving and Programming
7th Edition
ISBN: 9780133834604
Author: SAVITCH
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 7, Problem 6E
Create a class Ledger that will record the sales for a store. It will have the attributes
- sale—an array of double values that are the amounts of all sales
- salesMade —the number of sales so far
- maxSales—the maximum number of sales that can be recorded and the following methods:
- Ledger (max) —a constructor that sets the maximum number of sales to max
- addSale (d) —adds a sale whose value is d
- getNumberOfsales —returns the number of sales made
- getTotalSales—returns the total value of the sales
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
When you add a contact to your phone, it automatically sorts those names alphabetically. In this exercise, we are going to create a phonebook that automatically sorts everytime a new number is added to the phonebook.
A PhoneNumber class has been created already that has the instance variables name and number. Your job is to create the PhoneBook class that will store an ArrayList of PhoneNumbers.
The PhoneBook class does not have a constructor - it only contains an ArrayList that can store the individual phone numbers that are added to it.
There should be three methods in the PhoneBook class:
addNumber- This method takes a PhoneNumber and adds it to the directory. Once the number has been added, the sort method is called on the directory to sort that new address into the phone book.
sort- This method sorts the directory in alphabetical order A-Z.a. Remember that in order to compare Strings, we can use the compareTo() method. This returns an integer that indicates whether a String’s…
Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a date (use int's to store the date). Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches.
Additionally, you will need to implement a class called Calendar. This will contain an ArrayList of Appointment objects (The list is an instance variable of the Calendar class). You will need to provide the following methods for your Calendar class.
A no argument constructor
public Calendar(){...}
This constructor will initialize your ArrayList instance variable to an empty list.
/**
* A method to add an appointment to the calendar
* @param apt – the appointment object to add to the calendar.
*/
public void add(Appointment apt) {…}
/**
* A method to remove an appointment from the…
Complete the Course class by implementing the findStudentHighestGpa() method, which returns the Student object with the highest GPA in the course. Assume that no two students have the same highest GPA.
Given classes:
Class Course represents a course, which contains an ArrayList of Student objects as a course roster. (Type your code in here.)
Class Student represents a classroom student, which has three private fields: first name, last name, and GPA. (Hint: GetGPA() returns a student's GPA.)
Ex: If the following students and their GPA values are added to a course:
Henry Nguyen with 3.5 GPABrenda Stern with 2.0 GPALynda Robison with 3.2 GPASonya King with 3.9 GPA
then the findHighestStudent() method returns a student and the program output is:
Top student: Sonya King (GPA: 3.9)Code:Course.java:
import java.util.ArrayList;
//create class Student
//create class Courseclass Courses{ private ArrayList<Student> roster; // collection of Student object // class constructor…
Chapter 7 Solutions
Java: Introduction to Problem Solving and Programming
Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - What output will be produced by the following...Ch. 7.1 - Consider the following array: int [] a = new...Ch. 7.1 - What is wrong with the following code to...Ch. 7.1 - Write a complete Java program that reads 20 values...Ch. 7.2 - Write some Java code that will declare an array...Ch. 7.2 - Rewrite the method displayResults of the program...Ch. 7.2 - What output will be produced by the following...Ch. 7.2 - Give the definition of a static method called...
Ch. 7.2 - Give the definition of a static method called...Ch. 7.2 - Prob. 12STQCh. 7.2 - The following method compiles and executes but...Ch. 7.2 - Suppose that we add the following method to the...Ch. 7.3 - Prob. 15STQCh. 7.3 - Replace the last loop in Listing 7.8 with a loop...Ch. 7.3 - Suppose a is an array of values of type double....Ch. 7.3 - Suppose a is an array of values of type double...Ch. 7.3 - Prob. 19STQCh. 7.3 - Consider the partially filled array a from...Ch. 7.3 - Repeat the previous question, but this time assume...Ch. 7.3 - Write an accessor method getEntryArray for the...Ch. 7.4 - Prob. 23STQCh. 7.4 - Write the invocation of the method selectionSort...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - How would you need to change the method...Ch. 7.4 - Consider an array b of int values in which a value...Ch. 7.5 - What output is produced by the following code?...Ch. 7.5 - Revise the method showTable in Listing 7.13 so...Ch. 7.5 - Write code that will fill the following array a...Ch. 7.5 - Write a void method called display such that the...Ch. 7.6 - Prob. 33STQCh. 7 - Write a program in a class NumberAboveAverage that...Ch. 7 - Write a program in a class CountFamiles that...Ch. 7 - Write a program in a class CountPoor that counts...Ch. 7 - Write a program in a class FlowerCounter that...Ch. 7 - Write a program in a class characterFrequency that...Ch. 7 - Create a class Ledger that will record the sales...Ch. 7 - Define the following methods for the class Ledger,...Ch. 7 - Write a static method isStrictlyIncreasing (double...Ch. 7 - Write a static method removeDuplicates(Character[]...Ch. 7 - Write a static method remove {int v, int [] in}...Ch. 7 - Suppose that we are selling boxes of candy for a...Ch. 7 - Create a class polynomial that is used to evaluate...Ch. 7 - Write a method beyond LastEntry (position) for the...Ch. 7 - Revise the class OneWayNoRepeatsList, as given in...Ch. 7 - Write a static method for selection sort that will...Ch. 7 - Overload the method selectionSort in Listing 7.10...Ch. 7 - Revise the method selectionSort that appears in...Ch. 7 - Prob. 18ECh. 7 - Write a sequential search of an array of integers,...Ch. 7 - Write a static method findFigure (picture,...Ch. 7 - Write a static method blur (double [] [] picture)...Ch. 7 - Write a program that reads integers, one per line,...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - Write the method rotateRight that takes an array...Ch. 7 - The following code creates a ragged 2D array. The...Ch. 7 - Write a program that will read a line of text that...Ch. 7 - Prob. 2PPCh. 7 - Add a method bubbleSort to the class ArraySorter,...Ch. 7 - Add a method insertionSort to the class...Ch. 7 - The class TimeBook in Listing 7.14 is not really...Ch. 7 - Define a class called TicTacToe. An object of type...Ch. 7 - Repeat Programming Project 10 from Chapter 5 but...Ch. 7 - Prob. 8PPCh. 7 - Write a GUI application that displays a picture of...Ch. 7 - ELIZA was a program written in 1966 that parodied...Ch. 7 - Prob. 11PPCh. 7 - Create a GUI application that draws the following...Ch. 7 - Practice Program 2 used two arrays to implement a...Ch. 7 - Practice Program 5.4 asked you to define Trivia...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What are some features of specific programming languages you know whose rationales are a mystery to you?
Concepts Of Programming Languages
How do you identify the potential classes in a problem domain description?
Starting Out with Python (4th Edition)
What is the most important difference between a while statement and a do-while statement?
Absolute Java (6th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Write a program to print the value of EOF.
C Programming Language
What is wrong with the following version of the constructor of TIcketMachine?
Try out this version in the be...
Objects First with Java: A Practical Introduction Using BlueJ (6th 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 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…arrow_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_forward1) Create a "Car" class that keeps car ids and prices. And create a "Galleries" class that holds the car list for a particular gallery. In this class there should be methods for get / set and print for car name, car number and car list. Adding / Removing Cars to the List in This Class should have methods. And create another method to find and print the IDs of Cars with Car Segment equal to X. (print (X)). Car Prices are as follows according to the segments. 0-19999 -> Z20000-29999 -> Y30000-44999 -> T45000-100000 -> P Apply the Car list using "Single Linked List"(Node, newNode, head). The program should be written in JAVA.arrow_forward
- 1: create a class Pentagon, which implements the RegularPolygon interface. It should have a double field called length, as well as a constructor that initializes this length field to a given value. 2: In the main() method of Pentagon class, add the following code: RegularPolygon sq = new Square(10); RegularPolygon penta = new Pentagon(20); Write code to get the perimeter for sq and penta. 3: In the main() method defined in Q2, add this line of code: sq.getArea(); Will this code pass through compiler? What is the reason? The Java feature in Q1 which create a new version of predefined method getPerimeter() is called Polymorphism Override Overload Inheritancearrow_forwardWrite a class that represents a player in a game. The player should have a name, password,experience points, an inventory array of four strings, and a location x,y. Your class shouldhave mutator and accessor methods for all variables. For example: setName(), getName(). Itshould have a suitable display method. Mutators and accessors should be public but allvariables should be private. To implement get inventory, use string * getInv(); Use the scoperesolution operator to implement larger methods such as display(). Use in class methods forshorter methods such as setName(), getName(). (in C++)Example:void setName(string name){this->name = name;}string *getInv();...string* player::getInv(){return inventory;}Note that in the above method setName “this->” is required for disambiguation. If writtenvoid setName(string n){name = n;}“this->” is not required.Write a test program that creates three players and displays them.Example Output:This program generates three player objects and…arrow_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 copy Array 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. Sample RunEnter the number of items: 4Enter the numbers: 2 3 4 6Your printed array: 2 3 4 6Your copied printed array: 4 6 8 12arrow_forward
- Using java Hamburger ClassWrite a Hamburger class with the following six attributes:• bun - the type of bun the burger will be on• patties - the number of patties on the burger• cheese - whether or not the burger will have cheese• price - the price of the burger• toppings - an array of five toppings; it will need to start empty Write getters/setters for all attributesexcept the toppings array.Your constructor should create a single on white with no cheese and no toppings with a price of $2.99.Your class should include the following methods in this order, please: addCheese - this method has noparameters that adds cheese to the burger and increases the price by 75 centssuperSizeIt - this method has no parameters and adds a patty to the burger and increases the price by 1.50addToppings - this method would present the user with at least five toppings (your choice) stored in an array of Stringobjects. If the user indicates the wants the item, store the String in the toppings array. There…arrow_forwardImplement a class named Parade using an ArrayList, which will manage instances of class Clown. Each Clown only needs to be identified by a String for their name. Always join a new Clown to the end of the Parade. Only the Clown at the head of the Parade (i.e., the first one) can leave the Parade. In addition, also write a method called isFront that takes a Clown as parameter and returns true if the passed clown is at the front of the parade otherwise returns false. Create a test application to demonstrate building a parade of three or four clowns and include your own name. Then, remove one or two, and add another one or two. Also, test the isFront method by passing different clowns to the method.arrow_forward) Modify the BookStore and BookSearchEngine classes explained in the class to include the following additional methods and test them:a) A method returning the book with the lowest price in the library.b) A method searching the library for Books of a given author and returning an ArrayList of such Books. c) A method returning an ArrayList of Books whose price is less than a given number.arrow_forward
- Create the class Suitcase. Suitcase has things and a maximum weight limit, which defines the greatest total allowed weight of the things contained within the Suitcase object. Add the following methods to your class: A constructor, which is given a maximum weight limit public void addThing(Thing thing), which adds the thing in the parameter to your suitcase. The method does not return any value. public String toString(), which returns a string in the form "x things (y kg)" The things are saved into an ArrayList object: ArrayList<Thing> things = new ArrayList<Thing>(); The class Suitcase has to make sure the thing's weight does not cause the total weight to exceed the maximum weight limit. The method addThing should not add a new thing if the total weight happens to exceed the maximum weight limit. Below, you find an example of how the class can be used: public class Main { public static void main(String[] args) { Thing book = new Thing("Happiness…arrow_forwardIn this problem, we are going to use ArrayLists and classes to design a road trip. You have three classes: GeoLocation.java which represents a geo location. A RoadTrip.java class, which represents a road trip (or an ordered list of places), and a RoadTripTester.java class which brings them all together. In GeoLocation.java: Add a private instance variable called name which is a String. This represents the name of the location. Modify the Geolocation class constructor so that it is now of the format public GeoLocation(String name, double theLatitude, double theLongitude) Add a getter method for name called getName(). Update the toString so that it returns a String of the format San Francisco (37.7833, -122.4167) Now, you’ll also need to create a RoadTrip class. RoadTrip stores an ordered list of locations, so you’ll need to have an ArrayList as an instance variable. The RoadTrip class constructor should initialize an ArrayList that stores a list of GeoLocations. You’ll also need to…arrow_forwardJava this piece of my code is not working .....I am trying to add Warship with a type or warship , but I keep getting an error ? //add another WarShip instance to the ArrayList. //use a foreach loop to process the ArrayList and print the data for each ship. //count the number of ships that are not afloat. Return this count to main for printing. //In the shipShow method: the number of ships that are still a Float public static int shipShow(ArrayList<Ship> fleetList) { //from the ArrayList, remove the CargoShip that was declared as type Ship. fleetList.remove(2); //Removing ElFaro form the list // review Type casting instanceof | up casting Ship < Warship , subclass is a object of its parents //add warship USS John Warner - add cast by (Ship) new WarShip Ship warship2 = (Ship) new WarShip("USS John Warner", 2015, true, "attack submarine", "United States"); fleetList.add(warship2); int count= 0; //use a foreach loop to process the ArrayList and print the data for each ship.…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