all groups > vj# > may 2004 >
You're in the

vj#

group:

Please Help


Please Help mary
5/28/2004 7:51:02 PM
vj#:
Re: Please Help Mary
5/29/2004 5:01:02 PM
Hi Lars Thanks for responding. I have very limited programming knowledge. I know qbasic but that's about it. This should be an easy program. I just need to know how it adds to the balance each time you add a deposit. I don't see how that's possible without using a database to store the info
Re: Please Help Lars-Inge Tønnessen
5/29/2004 11:17:30 PM
Hi Mary,

We would love to help, but a few questions:

1. How advanced should this be? (introduction to programming 1, or advanced
distributed transactional components)

2. Should this run on one computer, or multiple computers? (Server -
Clients)

3. GUI (buttons, menus, windows etc) or command prompt (keyboard typing and
text)

4. What is your background in programming? (So we know how to help)


Regards,
Lars-Inge Tønnessen

Re: Please Help Mary
5/30/2004 11:56:02 AM
How exactly do I do this. Do I copy the code into one .jsl file for J#? or do I add classes. I need more detailed help thank
Re: Please thiHelp Help
5/30/2004 12:21:01 PM
Is this done in J# or J++ or SunJava with the javac. I tried in J# and I tried putting all the code in notepad and making a .java file. I get these errors in the javac bank.java:129: unclosed string literal :"+ThrumpCorp.withdrawl(3, 400) ); I get about 17 errors. Then when I move the quotaation marks to before the : instead of after it I get this error Class1.java:1: 'class' or interface expected
I am putting all the code into one notepad. Am I suppose to separate the codes into different files. one for bank , one for class one for deposit one for withdrawl. Is that right

When I do this in J# I add different classes but still get errors
Thanks for any help
Re: Please Help Lars-Inge Tønnessen
5/30/2004 5:08:59 PM

Here you will find a small simple J# example. It does not use a SQL database
or transactions. It's a one user bank. This is probably what they are asking
for in an introduction text/course.



/*
* This is our banking "database".
* We can do:
* - deposit
* - withdrawl
* - balance
*
* Our small bank can hold up to 100 accounts. These accounts
* are stored in an static array called "account[]". The next version
* sould use a dynamic array, but I will use a static array, because
* this is what an introduction book/text will use.
*
*/
public class bank
{
// This is the maximum number of accounts in the bank.
int NoOfAccounts = 0;

// The static array that holds the 100 accounts.
int account[];

// A startup constructor that will initialize the 100 accounts.
public bank( int MaxAccounts )
{
NoOfAccounts = MaxAccounts;

// Make a static array.
account = new int[NoOfAccounts];

// Loop through the 100 accounts and set the balance to 0.
for (int counter = 0; counter < NoOfAccounts; counter++)
this.account[counter] = 0;
}

// The deposit method. "accountNo" is the account number, "inMoney" is
the amount.
// The method throws an exception if the user tries to access an account
that is outside
// the account array. An exception is an error.
public int deposit( int accountNo, int inMoney ) throws System.Exception
{
int new_value = 0;

if (( accountNo < NoOfAccounts ) || (accountNo < 0))
{
// Get the old value in the account
int old_value = account[ accountNo ];

// Add the new amount to the balance.
new_value = old_value + inMoney;

// Store the new value back in the array.
account[ accountNo ]= new_value;
}
else // This will give the user an error if they try to access the
array out of range.
throw new System.Exception("Deposit : Out of account range!");

// return the new balance.
return new_value;
}

// The withdrawl method. "accountNo" is the account number, "inMoney" is
the amount.
// The method throws an exception if the user tries to access an account
that is outside
// the account array. An exception is an error.
public int withdrawl( int accountNo, int outMoney ) throws
System.Exception
{
int new_value = 0;
if ( (accountNo < NoOfAccounts) || (accountNo < 0) )
{
// Get the old value in the account
int old_value = account[ accountNo ];

// Calculate the new account value
new_value = old_value - outMoney;

// Store the new value in the account
account[ accountNo ] = new_value;
}
else // Error, out of array range!
throw new System.Exception("Withdrawl : Out of account range!");

// Return the new balance.
return new_value;
}

// This method returns the balance of a specified account.
public int balance( int accountNo ) throws System.Exception
{
int value = 0;

// Check to see if the account number is within the account range.
if ( (accountNo < NoOfAccounts) || (accountNo < 0) )
{
// Get the amount in the account
value = account[ accountNo ];
}
else // Error, out of account array range. Eg. 1001 or -34
throw new System.Exception("Balance : Out of account range!");

// Return the value.
return value;
}
}

// The entry point of the application.
public class Class1
{
public Class1()
{
// Use try - catch, because we throw exceptions in the bank object.
try
{
// Make a bank with 100 accounts. The bank is called
"ThrumpCorp".
bank ThrumpCorp = new bank( 100 );

// Deposit $100000 on the account 1
ThrumpCorp.deposit( 1, 100000 );

// Get the balance of the account 1
System.Console.WriteLine("Balance account No 1
:"+ThrumpCorp.balance(1) );

// Withdrawl $200 on the account 1
ThrumpCorp.withdrawl( 1, 200 );

// Get the balance of the account 1
System.Console.WriteLine("Balance account No 1
:"+ThrumpCorp.balance(1) );

// Deposit $200 on the account 2
System.Console.WriteLine("Balance account No 2
:"+ThrumpCorp.deposit(2, 200) );

// Withdrawl $400 on the account 3
System.Console.WriteLine("Balance account No 3
:"+ThrumpCorp.withdrawl(3, 400) );

// !!!This will bring an exception. We are trying to acces
account 300!!!
System.Console.WriteLine("Balance account No 4
:"+ThrumpCorp.balance( 300 ) );
}
catch ( System.Exception error )
{
System.Console.WriteLine(" Error: "+error.get_Message() );
}
}

/** @attribute System.STAThread() */
public static void main(String[] args)
{
new Class1();
}
}



Regards,
Lars-Inge Tønnessen
www.larsinge.com

AddThis Social Bookmark Button