Starting Out with Java: Early Objects (6th Edition)
Starting Out with Java: Early Objects (6th Edition)
6th Edition
ISBN: 9780134457963
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 9PC

BankAccount and SavingsAccount Classes

Design an abstract class named BankAccount to hold the following data for a bank account:

  • Balance
  • Number of deposits this month
  • Number of withdrawals
  • Annual interest rate
  • Monthly service charges

The class should have the following methods:

Constructor: The constructor should accept arguments for the balance and annual interest rate.
deposit: A method that accepts an argument for the amount of the deposit. The method should add the argument to the account balance. It should also increment the variable holding the number of deposits.
withdraw: A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also increment the variable holding the number of withdrawals.
calcinterest:

A method that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas:

M o n t h l y   I n t e r e s t   R a t e = ( A n n u a l   I n t e r e s t   R a t e / 12 ) M o n t h l y   I n t e r e s t = B a l a n c e * M o n t h l y I n t e r e s t   R a t e B a l a n c e = B a l a n c e + M o n t h l y   I n t e r e s t

monthlyProcess: A method that subtracts the monthly service charges from the balance, calls the calclnterest method, and then sets the variables that hold the number of withdrawals, number of deposits, and monthly service charges to zero.

Next, design a SavingsAccount class that extends the BankAccount class. The SavingsAccount class should have a status field to represent an active or inactive account. If the balance of a savings account falls below $25, it becomes inactive. (The status field could be a boolean variable.) No more withdrawals may be made until the balance is raised above $25, at which time the account becomes active again. The savings account class should have the following methods:

withdraw: A method that determines whether the account is inactive before a withdrawal is made. (No withdrawal will be allowed if the account is not active.) A withdrawal is then made by calling the superclass version of the method.
deposit: A method that determines whether the account is inactive before a deposit is made. If the account is inactive and the deposit brings the balance above $25, the account becomes active again. A deposit is then made by calling the superclass version of the method.
monthlyProcess: Before the superclass method is called, this method checks the number of withdrawals. If the number of withdrawals for the month is more than 4, a service charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly service charges. (Don’t forget to check the account balance after the service charge is taken. If the balance falls below $25, the account becomes inactive.)
Blurred answer
Students have asked these similar questions
(Java) The Sculpture Subclass Write class as follows: The class is named Sculpture, and it inherits from the Painting class. It has a private boolean member variable named humanForm It has a default constructor that assigns the values "No name" to name, "No artist" to artist, -1 to the year, "No medium" to the medium, and false to the humanForm variable. This default constructor calls the five argument constructor. It has a five-argument constructor to assign values to the name, artist, year, medium, and humanForm variables. It has a getter and setter for the humanForm variable. It has a toString() method. This class contains no other methods Make sure to include your name, the name of this class, our course number, and the Activity number in a Javadoc comment at the top. Make sure to write a Javadoc comment for each of these methods.
Create a class called ship that incorporates a ship’s serial number and location. Create another class angle which has two variables latitude and longitude. A member function of the ship class should get a position from the user and store it. Create object that should report the serial number and position. Write a main () program that creates three ships, asks the user to input the position of each, and then displays each ship’s serial number and position.Identify all the classes implement inheritance between them.   (language cpp)
A class may have several constructors and it is called __________.

Chapter 9 Solutions

Starting Out with Java: Early Objects (6th Edition)

Ch. 9.4 - When a class member is declared as protected, what...Ch. 9.4 - What is the difference between private members and...Ch. 9.4 - Why should you avoid making class members...Ch. 9.4 - Prob. 9.14CPCh. 9.4 - Why is it easy to give package access to a class...Ch. 9.6 - Look at the following class definition: public...Ch. 9.6 - When you create a class, it automatically has a...Ch. 9.7 - Recall the Rectangle and Cube classes discussed...Ch. 9.8 - Prob. 9.19CPCh. 9.8 - If a subclass extends a superclass with an...Ch. 9.8 - What is the purpose of an abstract class?Ch. 9.8 - If a class is defined as abstract, what can you...Ch. 9.9 - Prob. 9.23CPCh. 9.9 - Prob. 9.24CPCh. 9.9 - Prob. 9.25CPCh. 9.9 - Prob. 9.26CPCh. 9.9 - Prob. 9.27CPCh. 9.9 - Prob. 9.28CPCh. 9 - In an inheritance relationship, this is the...Ch. 9 - In an inheritance relationship, this is the...Ch. 9 - This key word indicates that a class inherits from...Ch. 9 - A subclass does not have access to these...Ch. 9 - This key word refers to an objects superclass. a....Ch. 9 - In a subclass constructor, a call to the...Ch. 9 - The following is an explicit call to the...Ch. 9 - A method in a subclass that has the same signature...Ch. 9 - A method in a subclass having the same name as a...Ch. 9 - These superclass members are accessible to...Ch. 9 - Prob. 11MCCh. 9 - With this type of binding, the Java Virtual...Ch. 9 - Prob. 13MCCh. 9 - Prob. 14MCCh. 9 - Prob. 15MCCh. 9 - Abstract classes cannot ___________. a. be used as...Ch. 9 - You use the __________ operator to define an...Ch. 9 - Prob. 18MCCh. 9 - Prob. 19MCCh. 9 - You can use a lambda expression to instantiate an...Ch. 9 - True or False: Constructors are not inherited.Ch. 9 - True or False: in a subclass, a call to the...Ch. 9 - True or False: If a subclass constructor does not...Ch. 9 - True or False: An object of a superclass can...Ch. 9 - True or False: The superclass constructor always...Ch. 9 - True or False: When a method is declared with the...Ch. 9 - True or False: A superclass has a member with...Ch. 9 - True or False: A superclass reference variable can...Ch. 9 - True or False: A subclass reference variable can...Ch. 9 - True or False: When a class contains an abstract...Ch. 9 - True or False: A class may only implement one...Ch. 9 - True or False: By default all members of an...Ch. 9 - // Superclass public class Vehicle { (Member...Ch. 9 - // Superclass public class Vehicle { private...Ch. 9 - // Superclass public class Vehicle { private...Ch. 9 - // Superclass public class Vehicle { public...Ch. 9 - Write the first line of the definition for a...Ch. 9 - Look at the following code, which is the first...Ch. 9 - Write the declaration for class B. The classs...Ch. 9 - Write the statement that calls a superclass...Ch. 9 - A superclass has the following method: public void...Ch. 9 - A superclass has the following abstract method:...Ch. 9 - Prob. 7AWCh. 9 - Prob. 8AWCh. 9 - Look at the following interface: public interface...Ch. 9 - Prob. 1SACh. 9 - A program uses two classes: Animal and Dog. Which...Ch. 9 - What is the superclass and what is the subclass in...Ch. 9 - What is the difference between a protected class...Ch. 9 - Can a subclass ever directly access the private...Ch. 9 - Which constructor is called first, that of the...Ch. 9 - What is the difference between overriding a...Ch. 9 - Prob. 8SACh. 9 - Prob. 9SACh. 9 - Prob. 10SACh. 9 - What is an. abstract class?Ch. 9 - Prob. 12SACh. 9 - When you instantiate an anonymous inner class, the...Ch. 9 - Prob. 14SACh. 9 - Prob. 15SACh. 9 - Employee and ProductionWorker Classes Design a...Ch. 9 - ShiftSupervisor Class In a particular factory, a...Ch. 9 - TeamLeader Class In a particular factory, a team...Ch. 9 - Essay Class Design an Essay class that extends the...Ch. 9 - Course Grades In a course, a teacher gives the...Ch. 9 - Analyzable Interface Modify the CourseGrades class...Ch. 9 - Person and Customer Classes Design a class named...Ch. 9 - PreferredCustomer Class A retail store has a...Ch. 9 - BankAccount and SavingsAccount Classes Design an...Ch. 9 - Ship, CruiseShip, and CargoShip Classes Design a...

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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY