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 5, Problem 6E
Consider a class that keeps track of the sales of an item. An object of this class will have the attributes
- Number sold
- Total sales
- Total discounts
- Cost per item
- Bulk quantity
- Bulk discount percentage
and the following methods:
- registerSale (n) records the sale of n items. If n is larger than the bulk quantity, the cost per item will be reduced by the bulk discount.
- displaySales displays the number sold, the total sales, and total discount.
- a. Implement the class in Java.
- b. Write some Java statements that test the class.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Write in Java
Java program
FOR JAVA
Create a class named Product that has ID, price and stock as fields. This class must have two constructors; one constructor must take all its fields as parameters, second constructor must take ID and price as parameters and set stock to 0. Also implement the following methods:
• String toString(): Returns a brief summary about the object.
• void sell(int): Takes a parameter that represents the amount to sell. Checks if stocks are sufficient. If so, it updates the stock and prints the total price. Else it prints a warning to user.
Create 3 instances of Product class and test your methods.
Chapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 5.1 - Consider the program in Listing 5.4 . Suppose you...Ch. 5.1 - Prob. 2STQCh. 5.1 - Prob. 3STQCh. 5.1 - Suppose every species in the world has a peculiar...Ch. 5.1 - Revise the definition of the method writeOutput in...Ch. 5.1 - Revise the definition of the method readInput in...Ch. 5.1 - Revise the definition of the method...Ch. 5.1 - What is the meaning of (int) that appears in the...Ch. 5.1 - Prob. 9STQCh. 5.1 - Define a method called getDensity that could be...
Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.2 - In Listing 5.12, we set the data for the object...Ch. 5.2 - Give preconditions and postconditions for the...Ch. 5.2 - What is an accessor method? What is a mutator...Ch. 5.2 - Give the complete definition of a class called...Ch. 5.2 - Prob. 17STQCh. 5.2 - In the definition of the method in Listing 5.15,...Ch. 5.2 - What is a well-encapsulated class definition?Ch. 5.2 - When should an instance variable in a class...Ch. 5.2 - Prob. 21STQCh. 5.2 - In a class definition, is anything private ever...Ch. 5.2 - In a class definition, is the body of any method...Ch. 5.3 - What is a reference type? Are class types...Ch. 5.3 - When comparing two quantities of a class type to...Ch. 5.3 - Prob. 26STQCh. 5.3 - Write a method definition for a method called...Ch. 5.3 - Given the class Species as defined in Listing...Ch. 5.3 - After correcting the program in the previous...Ch. 5.3 - What is the biggest difference between a parameter...Ch. 5.3 - Prob. 31STQCh. 5.3 - Write an equals method for the class Person...Ch. 5.4 - Rewrite the method drawFaceSansMouth in Listing...Ch. 5 - Design a class to represent a credit card. Think...Ch. 5 - Repeat Exercise 1 for a credit card account...Ch. 5 - Repeat Exercise 1 for a coin instead of a credit...Ch. 5 - Repeat Exercise 1 for a collection of coins...Ch. 5 - Consider a Java class that you could use to get an...Ch. 5 - Consider a class that keeps track of the sales of...Ch. 5 - Consider a class MotorBoat that represents...Ch. 5 - Prob. 8ECh. 5 - Prob. 9ECh. 5 - Prob. 10ECh. 5 - Write a program to answer questions like the...Ch. 5 - Define a class called Counter. An object of this...Ch. 5 - Prob. 3PCh. 5 - Define a Trivia class that contains information...Ch. 5 - Define a Beer class that contains the following...Ch. 5 - Write a grading program for an instructor whose...Ch. 5 - Add methods to the Person class from Self-Test...Ch. 5 - Create a class that represents a grade...Ch. 5 - Write a program that uses the Purchase class in...Ch. 5 - Write a program to answer questions like the...Ch. 5 - Consider a class that could be used to play a game...Ch. 5 - Consider a class BasketballGame that represents...Ch. 5 - Consider a class ConcertPromoter that records the...Ch. 5 - Prob. 9PPCh. 5 - Consider a class Movie that contains information...Ch. 5 - Repeat Programming Project 18 from Chapter 4, but...Ch. 5 - Prob. 12PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write statements that will display a random number from each of the following sets: 1. 2, 4, 6, 8, 10. 2. 3, 5,...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
How does the typing system of PHP and JavaScript differ from that of Java?
Concepts Of Programming Languages
(Bubble-sort animation) Write a program that animates the bubble-sort algorithm. Create an array that consists ...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
public class MyClassT { public static void displayValue(T value) { System.out.println(value); } }
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
ofstream file; file.open (info.dat, ios::tin); if (file) { cout Could not open file.\n; }
Starting Out with C++ from Control Structures to Objects (9th 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
- Java Methods Write a program that accepts three strings: first name, last name, age, and nationality. Create an object of the class Person and assign the inputs to their respective attributes. In the class, create a method greeting() that prints the attributes. Inputs 1. Input Cody Chum 20 Filipino Sample Output Enter first name: Cody Enter last name: Chum Enter age: 20 Enter nationality: Filipino Hello, I am Cody Chum, 20 years old and a Filipino!arrow_forwardJava Programming problem Create a checking account class with three attributes: account number, owner’s name, and balance. Create constructor, getters and setters. If one is to set the initial balance of an account as a negative value in a setter or a constructor, remind the user about the error and set it as 0. Create a CheckingAccountDemo class, and create a main method in which Ask for the name, account number, and initial balance for one account from the keyboard input. With these input values as arguments in a call to the constructor, create a CheckingAccount object. Print the summary of this account that includes information on the name, account number, and balance by calling the getters.arrow_forwardJAVA PROGRAM Chapter 7. PC #1. Rainfall Class Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should have methods that return the following: • the total rainfall for the year • the average monthly rainfall • the month with the most rain • the month with the least rain Demonstrate the class in a complete program. Main class name: RainFall (no package name) NOTE, THE MAIN CLASS NAME needs to be Rainfall as mentioned above AND IT HAS TO PASS ALL THE TEST CASES WHEN I UPLOAD IT TO HYPERGRADE. THANK YOU Enter the rainfall amount for month 1:\n1.2ENTEREnter the rainfall amount for month 2:\n2.3ENTEREnter the rainfall amount for month 3:\n3.4ENTEREnter the rainfall amount for month 4:\n5.1ENTEREnter the rainfall amount for month 5:\n1.7ENTEREnter the rainfall amount for month 6:\n6.5ENTEREnter the rainfall amount for month 7:\n2.5ENTEREnter the rainfall amount for month 8:\n3.3ENTEREnter the…arrow_forward
- Java: A place to buy candy is from a candy machine. A new candy machine is bought for the gym, but it is not working properly. The candy machine has four dispensers to hold and release items sold by the candy machine and a cash register. The machine sells four products — candies, chips, gum, and cookies—each of which is stored in a separate dispenser. You have been asked to write a program for this candy machine so that it can be put into operation. The program should do the following: Show the customer the different products sold by the candy machine Let the customer make the selection Show the customer the cost of the item selected Accept money from the customer Return change Release the item, that is, make the sale Here is my provided code: import java.util.*; public class CandyMachine{// Each candy machine is made of 1 CashRegister and 4 DispensersCashRegister cashRegister;Dispenser candy;Dispenser chips;Dispenser gum;Dispenser cookies;//Default constructor to set the…arrow_forwardUse java and classesarrow_forwardjava programming Robot Class : a robot has a name , located at a point with integer coordinates , faces north , east , south , or west and keeps a record of all its movements positions . The class has the following methods : A default constructor that initializes robot's name to " Unknown ” , location to ( 0,0 ) , direction to North , and travelled distance to 0 , and simulated movements to null . A constructor that given robot's name , starting location , and facing direction , Accessor methods to access all the instance variables and the simulated movements of the robot Mutator methods that change the instance variables to given values and they made the change for only suitable values . tumLeft and turn Right methods that change the direction of the robot but not the location move method that moves the robot by one unit in the direction it is facing . get Travelled Distance method that retums how many units has the robot moved .arrow_forward
- Java - Access Specifiers Create a class named Circle that has attributes radius, area, and circumference and make the attributes private. Make a public method that sets the radius and a method that prints all attributes. Ask the user input for radius. Note: Use the PI from the math functions Inputs A line containing an integer 10 Sample Output Radius: 20 Area: 1256.64 Circumference: 125.66arrow_forwardJAVA. THIS IS A PROGRAMMING ASSIGNMENT NOT A WRITING ASSIGNMENT IF YOU ANSWERED BEFORE DO NOT ANSWER AGAIN PLEASE DO NOT PASTE A PAPER Design a class to store the following information about computer scientists⦁ Name⦁ Research area(s)⦁ Major contribution A scientist may have more than one area of research.⦁ Implement the usual setters and getters methods ⦁ Implement a method that takes a research area as an input and return thenames of scientists associated with that area ⦁ Implement a method that takes a word as an input and return the names ofscientists whose contribution mention that word Next, perform desktop research to find at least five prominent black computerscientists, with their research area(s) and major contribution, and store this data intoobjects of the class you designed. You can just hardcode this data. No user input needed.Define JUnit tests to check your research area and contribution search methods.arrow_forwardJAVA Write a class that calculates add, subtraction, and multiplication. The class should include the following methods: Constructor : initialize all values to 0 getAsk() : Ask users to input two integer numbers. This method calls Distribute() method. Distribute() : Ask users to choose which calculation he/she wants. This method calls a method that can add, subtract, or multiply based on the user's option. CalAdd() : add two numbers CalSub() : subtract two numbers CalProduct() : multiply two numbers toString() : toString method that display result of operation. The program should be designed to test the class developed. Your program might look like the following: public class CalculateNumTesting{ public static void main(String[] args){ CalculateNum calculation = new CalculateNum(); calculation.getAsk(); System.out.println(calculation); } }arrow_forward
- please quickly thanks ! use javaarrow_forwardJava Programming: Write a static method named urgentAndIncomplete. Write the method as if it is in Main.java (not part of the ToDoItem class). The method should: Accept three ToDoItem references as parameters, and Return an int. Count how many of the ToDoItems meet two criteria: A priority greater than 3 Not completed The method should return how many of the parameters meet these criteria. That will be either 0, 1, 2, or 3.arrow_forwardJAVACreate a class called Quadratic for representing a one-variable quadratic expression of the form: ax2 + bx + c a,b and c here are the coefficients. The class should contain the following methods: * A constructor that accepts values for a, b, and c. * public double getA() * public double getB() * public double getC() * public double evaluate (int x) * will return the value of the expression at point x * public double discriminant() - that will return (b2 - 4ac) * public boolean isImaginaryRoots() - roots are imaginary if (b2 - 4ac) < 0 * public boolean isRealRoots() - roots are real if (b2 - 4ac) >= 0 // these methods can only be invoked if the roots are not imaginary * public float firstRoot() * public float secondRoot() * public boolean isPerfectSquare(); // If the first and second roots are equal * Try to override the toString methods * Write a sample main program that will work as shown below. Example output: coefficient a: 4 coefficient b: 4 coefficient c: 1…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
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License