
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
![Opening and Closing Accounts
File Account,java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw,
deposit, get the balance and account number, and return a String representation. Note that the constructor for this class
creates a random account number. Save this class to your directory and study it to see how it works. Then write the following
additional code:
1. Suppose the bank wants to keep track of how many accounts exist.
Declare a private static integer variable numAccounts to hold this value. Like all instance and static variables, it will
be initialized (to 0, since it’s an int) automatically.
а.
b. Add code to the constructor to increment this variable every time an account is created.
Add a static method getNumAccounts that returns the total number of accounts. Think about why this method should
be static - its information is not related to any particular account.
c.
d. File TestAccountsl1.java contains a simple program that creates the specified number of bank accounts then uses the
getNumAccounts method to find how many accounts were created. Save it to your directory, then use it to test your
modified Account class.
2. Add a method void close() to your Account class. This method should close the current account by appending
"CLOSED" to the account name and setting the balance to 0. (The account number should remain unchanged.) Also
decrement the total number of accounts.
3. Add a static method Account consolidate(Account acctl, Account acct2) to your Account class that creates a new
account whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should
be returned. Two important rules of consolidation:
• Only accounts with the same name can be consolidated. The new account gets the name on the old accounts but a new
account number.
Two accounts with the same number cannot be consolidated. Otherwise this would be an easy way to double your
money!
Check these conditions before creating the new account. If either condition fails, do not create the new account or close
the old ones; print a useful message and return null.
4. Write a test program that prompts for and reads in three names and creates an account with an initial balance of $ 100 for
each. Print the three accounts, then close the first account and try to consolidate the second and third into a new account.
Now print the accounts again, including the consolidated one if it was created.
//**********
// TestAccounts1
// A simple program to test the numAccts method of the
// Account class.
****
************
//******************
**** ********
******:
************
import java.util.Scanner;
public class TestAccounts1
public static void main(String[] args)
{
Account testAcct;
Scanner scan = new Scanner (System.in);
Chapter 7: Object-Oriented Design
113
System.out.println("How many accounts would you like to create?"); int num =
scan.nextInt();
for (int i=1; i<=num; i++)
{
testAcct = new Account (100, "Name"
System.out.println("\nCreated account
System.out.println("Now there are
+ i);
+ testAcct);
+ Account.numAccounts () +
accounts");
%3D
}
}
}](https://content.bartleby.com/qna-images/question/6a453cf0-4fa7-465e-ab7f-471dd1e543ba/7378adb4-9c7c-4838-a12d-d86739fb7211/gapa1d_thumbnail.jpeg)
Transcribed Image Text:Opening and Closing Accounts
File Account,java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw,
deposit, get the balance and account number, and return a String representation. Note that the constructor for this class
creates a random account number. Save this class to your directory and study it to see how it works. Then write the following
additional code:
1. Suppose the bank wants to keep track of how many accounts exist.
Declare a private static integer variable numAccounts to hold this value. Like all instance and static variables, it will
be initialized (to 0, since it’s an int) automatically.
а.
b. Add code to the constructor to increment this variable every time an account is created.
Add a static method getNumAccounts that returns the total number of accounts. Think about why this method should
be static - its information is not related to any particular account.
c.
d. File TestAccountsl1.java contains a simple program that creates the specified number of bank accounts then uses the
getNumAccounts method to find how many accounts were created. Save it to your directory, then use it to test your
modified Account class.
2. Add a method void close() to your Account class. This method should close the current account by appending
"CLOSED" to the account name and setting the balance to 0. (The account number should remain unchanged.) Also
decrement the total number of accounts.
3. Add a static method Account consolidate(Account acctl, Account acct2) to your Account class that creates a new
account whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should
be returned. Two important rules of consolidation:
• Only accounts with the same name can be consolidated. The new account gets the name on the old accounts but a new
account number.
Two accounts with the same number cannot be consolidated. Otherwise this would be an easy way to double your
money!
Check these conditions before creating the new account. If either condition fails, do not create the new account or close
the old ones; print a useful message and return null.
4. Write a test program that prompts for and reads in three names and creates an account with an initial balance of $ 100 for
each. Print the three accounts, then close the first account and try to consolidate the second and third into a new account.
Now print the accounts again, including the consolidated one if it was created.
//**********
// TestAccounts1
// A simple program to test the numAccts method of the
// Account class.
****
************
//******************
**** ********
******:
************
import java.util.Scanner;
public class TestAccounts1
public static void main(String[] args)
{
Account testAcct;
Scanner scan = new Scanner (System.in);
Chapter 7: Object-Oriented Design
113
System.out.println("How many accounts would you like to create?"); int num =
scan.nextInt();
for (int i=1; i<=num; i++)
{
testAcct = new Account (100, "Name"
System.out.println("\nCreated account
System.out.println("Now there are
+ i);
+ testAcct);
+ Account.numAccounts () +
accounts");
%3D
}
}
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 1 images

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
- BMI is a measure of body condition and it is related to a person's weight and height. In the metric system, for weight given in Kilograms (Kg) and height given in centimeters (cm), the BMI value is given by: $BMI=10000*weight/(height^2)$. The person's condition is given by the table below:\n", "\n", "| BMI | Condition|\n", "|-----|----------|\n", "| <18.5| Underweight|\n", "|>=18.5 and <25| Normal |\n", "|>=25 and <30| Overweight |\n", "|>= 30 | Obese|\n", "\n", Write a program that asks for a person's height in cm and weight in Kg and print's the person's condition.arrow_forwardAnnotate following code. def QualityPointCalculator(qualPnts, crdts): if crdts > 0: return qualPnts/crdts return 0def convertGrade(grade): if grade == "A": return 4.00 elif grade == "A-": return 3.70 elif grade == "B+": return 3.30 elif grade == "B": return 3.00 elif grade == "B-": return 2.70 elif grade == "C+": return 2.30 elif grade == "C": return 2.00 elif grade == "C-": return 1.70 elif grade == "D+": return 1.30 elif grade == "D": return 1.00 else: return 0.00 def calcQualPnts(pnts, crdts): return pnts*crdts if __name__ == '__main__': quality_points = [] course_names = [] grades = [] credits = [] final_gpa = 0.0 semester_gpa = 0.0 final_total = 0.0 howMany = 0 print('GRADE & QUALITY NUMERICAL POINTS') choice = input('Would you like to calculate your GPA for a term? Enter Y/N: ') while choice.upper()[0] == 'Y':…arrow_forwardBy using Loop in c++, you are responsible to develop a Credit Limit Calculator, which will determine if their customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:- a) Account number b) Balance at the beginning of the month c) Total of all items charged by this customer this month d) Total of all credits applied to this customer's account this month e) Type of Membership: SVIP(S), VIP(V) and Basic(B) Your program should input each for these facts, calculate the new balance (= beginning balance + charges - credit), and determine if the new balance exceeds the customer's credit limit. The customer's credit limit is based on their membership type as below:- Type of Membership SVIP (S) VIP (V) Basic (B) Credit Limit (HK$) 20,000 10,000 5,000 For those customers whose credit limit is exceed, the program should display the customer's account number, type of membership, credit limit, new balance and the message "Credit Limit"…arrow_forward
- Last Name Dev Hours Review Date Rating Salary Bonus Brody 6 1/5/2018 2 $ 19,840 Alex 8 4/1/2018 5 $ 26,700 Ashley 1 7/1/2018 4 $ 33,200 1. Use the logical if function to pay a bonus. You determine the rules for the bonus. List the rules and your steps. For example, you may use the employee rating to align with a specific bonus percentage such as 2% for a 2 rating, 5% for a 5 rating, etc.arrow_forwardAnswer this question attachedarrow_forward13. Factorial Implementation What is incorrect with the following implementation of factorial: def factorial(n): return n* factorial(n-1) Pick ONE option Nothing is wrong The return value should be n+ factorial(n-1) The return value should be factorial(n-1) * factorial(n-2) ) A base case is missing Clear Selection loxituarrow_forward
- OCaml Questions: Please make sure to answer each question correctly and indicate which question you are answering. There must be no mistake in any of the answers.arrow_forwardCredit Rating (feature1) Liabiltiy or not (Target) Yes No Total Excellent 3 1 4 Good 4 2 6 Poor 0 4 4 Total 7 7 14 Balance (feature2) Liabiltiy or not (Target) Yes No Total >50K 2 6 8 < 50 K 5 1 6 Total 7 7 14 Liability Tables Refer to the ‘Liability’ tables above, the target variable is Liability which can take on two values “Yes” and “No” and we 2 features: Credit Rating (which can take on values “Excellent”, “Good” and “Poor”), and Balance (which can take on values “> 50K”, “< 50K”). There are 14 observations in total. See the above liability table for different figures of ‘excellent’, ‘good’, ‘poor’ credit ratings and ‘Yes’, ‘No’ liability class. Use decision tree algorithm to work out which feature provides more information or reduces more uncertainty about our target variable out of the two using the concepts of entropy and information Gain.Please answer ASAP,…arrow_forwardCreate a function named fnTuition that calculates the tuition for a student. This function accepts one parameter, the student ID, and it calls the fnStudentUnits function that you created in task 2. The tuition value for the student calculated according to the following pseudocode: if (student does not exist) or (student units = 0) tuition = 0 else if (student units >= 9) tuition = (full time cost) + (student units) * (per unit cost) else tuition = (part time cost) + (student units) * (per unit cost) Retrieve values of FullTimeCost, PartTimeCost, and PerUnitCost from table Tuition. If there is no student with the ID passed to the function, the function should return -1. Code two tests: 1) a student who has < 9 student units, and 2) for a student who has >= 9 student units. For each test, display StudentID and the result returned by the function. Also, run supportive SELECT query or queries that prove the results to be correct.arrow_forward
- Question 14 papa .Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardFill in the blank in the following statement.A store sells an item for 50% more than it's sale price. This means the original price of the item is ______ times larger than the sale price.arrow_forwardJavaarrow_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