Please do not give solution in image format thanku I'mwriting code for an assignment that I'll post below. I was hoping for some help with creating my driver for the new lockable Account Class. Assignment Question: Design a Java interface called Lockable that includes the following methods: setKey, lock, unlock, and locked. The setKey, lock, and unlock methods take an integer parameter that represent the key. The setKey method establishes the key. The lock and unlock methods lock and unlock the object, but only if the key passed in is correct. The locked method returns a boolean that indicates whether or not the object is locked. A Lockable object represents an object whose regular methods (Note: you need to modify these methods) will perform the tasks only if the object is unlocked. If the object is locked, then the methods will not perform the requested task (e.g., if the task is to "deposit" to an Account object, no deposit will be done. The method will simply return the current balance of the object); if the object is unlocked, the requested task can be performed. Now, redesign the Coin class (Listing 5.4, p. 186) and Account class (Listing 5.7, p. 192) from Chapter 5 in your course textbook so that they are Lockable. Create a driver class to demonstrate the behaviours of Lockable objects using Account and Coin classes (Note: you may have two separate demonstrations using 2 different driver classes, one for Account and another for Coin) Lockable Interface: public interface Lockable { public void setKey(int newkey); public void lock(int key); public void unlock(int key); public boolean locked(); } Account Class: import java.text.NumberFormat; public class Account implements Lockable { private final double RATE = 0.035; private String name; private long acctNumber; private double balance; private int key; private boolean isLocked; public Account(String owner, long account, double initial) { name = owner; acctNumber = account; balance = initial; isLocked = false; } public double deposit (double amount) { if (isLocked) { return balance; } if (amount > 0) { balance += amount; } return balance; } public double withdraw (double amount, double fee) { if (isLocked) { return balance; } if (amount + fee > 0 && amount + fee <= balance) { balance -= (amount + fee); } return balance; } public double addInterest() { if (isLocked) { return balance; } balance += (balance * RATE); return balance; } public double getBalance() { return balance; } public String toString() { NumberFormat fmt = NumberFormat.getCurrencyInstance(); return (acctNumber + "\t" + name + "\t" + fmt.format(balance)); } public void setKey (int key) { this.key = key; } public void lock (int key) { if (this.key == key) { isLocked = true; } } public void unlock (int key) { if (this.key == key) { isLocked = false; } } public boolean locked() { return isLocked; } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please do not give solution in image format thanku

I'mwriting code for an assignment that I'll post below. I was hoping for some help with creating my driver for the new lockable Account Class.

Assignment Question:

Design a Java interface called Lockable that includes the following methods: setKey, lock, unlock, and locked. The setKey, lock, and unlock methods take an integer parameter that represent the key. The setKey method establishes the key. The lock and unlock methods lock and unlock the object, but only if the key passed in is correct. The locked method returns a boolean that indicates whether or not the object is locked. A Lockable object represents an object whose regular methods (Note: you need to modify these methods) will perform the tasks only if the object is unlocked. If the object is locked, then the methods will not perform the requested task (e.g., if the task is to "deposit" to an Account object, no deposit will be done. The method will simply return the current balance of the object); if the object is unlocked, the requested task can be performed. Now, redesign the Coin class (Listing 5.4, p. 186) and Account class (Listing 5.7, p. 192) from Chapter 5 in your course textbook so that they are Lockable. Create a driver class to demonstrate the behaviours of Lockable objects using Account and Coin classes (Note: you may have two separate demonstrations using 2 different driver classes, one for Account and another for Coin)

Lockable Interface:

public interface Lockable
{
public void setKey(int newkey);
public void lock(int key);
public void unlock(int key);
public boolean locked();
}

Account Class:

import java.text.NumberFormat;

public class Account implements Lockable
{
private final double RATE = 0.035;
private String name;
private long acctNumber;
private double balance;
private int key;
private boolean isLocked;

public Account(String owner, long account, double initial)
{
name = owner;
acctNumber = account;
balance = initial;
isLocked = false;
}

public double deposit (double amount)
{
if (isLocked)
{
return balance;
}
if (amount > 0)
{
balance += amount;
}
return balance;
}

public double withdraw (double amount, double fee)
{
if (isLocked)
{
return balance;
}
if (amount + fee > 0 && amount + fee <= balance)
{
balance -= (amount + fee);
}
return balance;
}

public double addInterest()
{
if (isLocked)
{
return balance;
}
balance += (balance * RATE);
return balance;
}

public double getBalance()
{
return balance;
}

public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return (acctNumber + "\t" + name + "\t" + fmt.format(balance));
}

public void setKey (int key)
{
this.key = key;
}

public void lock (int key)
{
if (this.key == key)
{
isLocked = true;
}
}

public void unlock (int key)
{
if (this.key == key)
{
isLocked = false;
}
}

public boolean locked()
{
return isLocked;
}
}

Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Math class and its different methods
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
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education