Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java programming question (Object oriented programming) Answer FULL question properly for thumbs up: Question 1 A programmer creates the Java class shown in Figure 1
Java programming question (Object oriented programming)
Answer FULL question properly for thumbs up:
Question 1 A programmer creates the Java class shown in Figure 1 on page 3, to represent a bank account in which balance must always be greater than zero The questions that follow concern this class. You may include small fragments of code in your answers where appropriate, but keep in mind that full marks can be obtained with purely descriptive answers, if they are sufficiently accurate and detailed. Note also that you will not be penalised for minor errors of syntax in code fragments (a) This class will not behave as required, due to a bug in one of the methods. Explain the nature of this bug. Explain carefully how the code should be changed to fix it (b) A programmer tries to create a BankAccount object in his program like this BankAccount acc new BankAccount ("John Smith"); What would he see when he tries to compile this code? Why would he see this? (c) A software developer reviewing the implementation of this class makes the observation that "the constructor, the deposit method and the withdraw method are OK, but they should really be given exception specifications." What does the developer mean by this observation? Is this a sensible criticism to make of the code? Explain your reasoning (d) A program using the class contains the following piece of code: myAccount.deposit (cash); System.out.println("Cash deposited") (i) Under what circumstances would the program user not see the "Cash deposited" message? Explain your reasoning (ii) Describe what would need to be added to this code in order for the user to see the message "Sorry, that amount of cash is not valid" printed when the circumstances (e) Explain why it might be useful to alter line 3 of the class definition so that balance is (f) A programmer wishes to produce a variant of BankAccount in which the minimum in (i) apply declared as protected rather than private value allowed for a deposit is 100. Explain in detail how she could achieve this in an efficient mannerStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started