473,320 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can someone please help with this modifying Account problem!?!?!

22
Can someone please help with this modifying Account problem!?!?!

Modify the Account class so that it also permits an account to be opened with just a name and an account number, assuming an initial balance of zero. Modify the main method of the Transactions class to demonstrate this new capability.


//************************************************** ******************
// Account.java Author: Lewis/Loftus
//
// Represents a bank account with basic services such as deposit
// and withdraw.
//************************************************** ******************

import java.text.NumberFormat;

public class Account
{
private final double RATE = 0.035; // interest rate of 3.5%

private long acctNumber;
private double balance;
private String name;

//-----------------------------------------------------------------
// Sets up the account by defining its owner, account number,
// and initial balance.
//-----------------------------------------------------------------
public Account (String owner, long account, double initial)
{
name = owner;
acctNumber = account;
balance = initial;
}

//-----------------------------------------------------------------
// Deposits the specified amount into the account. Returns the
// new balance.
//-----------------------------------------------------------------
public double deposit (double amount)
{
balance = balance + amount;

return balance;
}

//-----------------------------------------------------------------
// Withdraws the specified amount from the account and applies
// the fee. Returns the new balance.
//-----------------------------------------------------------------
public double withdraw (double amount, double fee)
{
balance = balance - amount - fee;

return balance;
}

//-----------------------------------------------------------------
// Adds interest to the account and returns the new balance.
//-----------------------------------------------------------------
public double addInterest ()
{
balance += (balance * RATE);
return balance;
}

//-----------------------------------------------------------------
// Returns the current balance of the account.
//-----------------------------------------------------------------
public double getBalance ()
{
return balance;
}

//-----------------------------------------------------------------
// Returns a one-line description of the account as a string.
//-----------------------------------------------------------------
public String toString ()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();

return (acctNumber + "\t" + name + "\t" + fmt.format(balance));
}
}
Nov 17 '06 #1
1 2247
r035198x
13,262 8TB
Can someone please help with this modifying Account problem!?!?!

Modify the Account class so that it also permits an account to be opened with just a name and an account number, assuming an initial balance of zero. Modify the main method of the Transactions class to demonstrate this new capability.


//************************************************** ******************
// Account.java Author: Lewis/Loftus
//
// Represents a bank account with basic services such as deposit
// and withdraw.
//************************************************** ******************

import java.text.NumberFormat;

public class Account
{
private final double RATE = 0.035; // interest rate of 3.5%

private long acctNumber;
private double balance;
private String name;

//-----------------------------------------------------------------
// Sets up the account by defining its owner, account number,
// and initial balance.
//-----------------------------------------------------------------
public Account (String owner, long account, double initial)
{
name = owner;
acctNumber = account;
balance = initial;
}

//-----------------------------------------------------------------
// Deposits the specified amount into the account. Returns the
// new balance.
//-----------------------------------------------------------------
public double deposit (double amount)
{
balance = balance + amount;

return balance;
}

//-----------------------------------------------------------------
// Withdraws the specified amount from the account and applies
// the fee. Returns the new balance.
//-----------------------------------------------------------------
public double withdraw (double amount, double fee)
{
balance = balance - amount - fee;

return balance;
}

//-----------------------------------------------------------------
// Adds interest to the account and returns the new balance.
//-----------------------------------------------------------------
public double addInterest ()
{
balance += (balance * RATE);
return balance;
}

//-----------------------------------------------------------------
// Returns the current balance of the account.
//-----------------------------------------------------------------
public double getBalance ()
{
return balance;
}

//-----------------------------------------------------------------
// Returns a one-line description of the account as a string.
//-----------------------------------------------------------------
public String toString ()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();

return (acctNumber + "\t" + name + "\t" + fmt.format(balance));
}
}
Post what you suggest remembering that you need to overload the constructor with one that satisfies the required functionality.
Nov 17 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Franklin Bowen | last post by:
Are there any limitations or gotchas to updating the same table which fired a trigger from within the trigger? Some example code below. Hmmm.... This example seems to be working fine so it...
9
by: SB | last post by:
Ok, very simple problem. I'm trying to update a value by calling a function using pass by reference, but it does not update the value. In short, the value I'm trying to update is balance, which is...
10
by: Andreas Sheriff | last post by:
Please evaluate the following snippet: int a=5; int b; b = a++ + a; Edit1->Text = b; a = 5; b = a++ + ++a; Edit2->Text = b;
21
by: MLH | last post by:
A97 procedure to open http://www.arch.com/message/ enter an 800 number, press "Continue", enter a text msg string from a memo field and press "Send" This is a calendaring and appointment A97...
4
by: Frank Rizzo | last post by:
Hello, I want to use a variable as a signal to the thread that it should stop what it's doing (code below). As a rule, should I lock an object only when I am writing to it or do I have to lock...
4
by: TN Bella | last post by:
Hello, I don't know why I keep getting this error. I have 15 of each txtacctnum (txtacctnum - txtacctnum14), txtcostcntr, txtrefnum, and txtacctamt. Some of the inputs are null, so I don't want to...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
3
by: sparks | last post by:
I have 2 fields that I have to make sure don't get screwed up. (could be one it doesn't matter) but what they want is no duplicates, warn the user changing existing numbers is a no no. (of course...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.