| | |
Newbie
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
Hi, I'm new to the whole programing world, so I'm a bit lost.
The problem is:
Enhanace the "BankAccount" class by,
1.) Rejecting negative amounts in the deposit and withdrawl methods.
and
2.) Rejects withdrawals that would result in a negative balance.
(Simply return from the method without modifying the balance when the amount is negative or a withdrawl exceeds the balance.)
**What I've gotten so far is:
if (amount <= balance)
the class "BankAccount" is below:
public class BankAccount
{
public BankAccount()
public void deposit(double amount)
public double getBalance()
}
The problem is:
Enhanace the "BankAccount" class by,
1.) Rejecting negative amounts in the deposit and withdrawl methods.
and
2.) Rejects withdrawals that would result in a negative balance.
(Simply return from the method without modifying the balance when the amount is negative or a withdrawl exceeds the balance.)
**What I've gotten so far is:
if (amount <= balance)
balance = balance - amount;else
system.out.println("Not enough memory in account")
the class "BankAccount" is below:
public class BankAccount
{
public BankAccount()
{public BankAccount(double initialBalance)
balance = 0;
}
{
balance = initialBalance;
}
public void deposit(double amount)
{public void withdraw(double amount)
// ...
double newBalance = balance + amount;
balance = newBalance;
}
{
// ...
double newBalance = balance - amount;
balance = newBalance;
}
public double getBalance()
{private double balance;
return balance;
}
}
•
•
Join Date: Dec 2008
Posts: 104
Reputation:
Solved Threads: 18
Try this:
By the way System.out.println is for java ( atleast to my knowledge).
C# Syntax (Toggle Plain Text)
//Rejecting negative amounts in deposits public void deposit(double amount) { if(amount < 0) { Console.WriteLine("Sorry, You cannot deposit negative amounts to your account"); return; } double newBalance = balance + amount; balance = newBalance; } ////Rejecting negative amounts in withdrawls. public void withdraw(double amount) { if(amount < 0) { Console.WriteLine("Sorry, You cannot withdraw negative amounts to your account"); return; } double newBalance = balance - amount; if(newBalance < 0) { Console.WriteLine("Sorry, You account doesnot have enough balance to complete this transaction"); return; } balance = newBalance; }
By the way System.out.println is for java ( atleast to my knowledge).
Mona, your problem is easy whatever C# or Java is, you should first try on draft, trace that, and then writing code. If you face problem then post a question don't be used to have a full answer to your questions with code, that's a very big problem to whom starting programming.
Wish for you the best.
Wish for you the best.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- As a newbie, where i should start from in linux? (Getting Started and Choosing a Distro)
- Questions about building a system (was: newbie) (Troubleshooting Dead Machines)
- Best free C/C++ compiler for a newbie? (C++)
- help newbie alert needs help with login page (ASP.NET)
- newbie needs help, basic mfc stuff (C++)
- Hello, newbie here... (Geeks' Lounge)
- Book For Newbie (C++)
- Newbie - how do I start C++ programming? (C++)
- PHP newbie, project feasibility (PHP)
- How to network two Win98 machines (Networking Hardware Configuration)
Other Threads in the C# Forum
- Previous Thread: How to run an external script from a C# script?
- Next Thread: Uninstall custom actions
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation visualstudio webbrowser windows winforms wpf xml






