Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 29th, 2004, 11:20 AM
shak187 shak187 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 shak187 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 47 sec
Reputation Power: 0
python to java

i have been trying to convert it but i cannot can do it can anyone help me thanks
import javax.swing.JOptionPane;
public class define{
private int CURRENT = 1;
private int DEPOSIT = 2;
private int POUND = £; // ==== GLOBAL VARIABLES ========
// [ ] means list has no (0) elements on it initially.
static String [ ] customers; static Boolean [ ] hasCurrent;
static Boolean [ ]hasDeposit;
static int [ ]currentAccountBalances;static int [ ]depositAccountBalances;

public static void main(String [] args)
{
choice = displayMenu();
while (choice != 0)
{ // NB choice == 0 is "quit"
if (choice == 1)
addCustomer( );
else if (choice == 2)
viewBalance();
else if (choice == 3)
withdrawCash();
else if (choice == 4)
depositFunds();
}//while
choice = displayMenu();
System.out.println ("Bye thanks for using the bank...");
}//main()
public static void displayMenu()
{ ( ... )
valid = False;
while (valid = true)
{
System.out.println ("\n\n******* MAIN MENU ****************\n");
System.out.println ("Please select one of the following options:");
System.out.println ("\t 1: create new account");
System.out.println ("\t 2: view a Customers Balance");
System.out.println ("\t 3: withdraw cash from a customers account");
System.out.println ("\t 4: deposit funds into a customers account");
System.out.println ("\t 0: quit....");
choice = input(" \t>>> " );
valid = check(choice);
}
return choice;
}//display menu ()
public void addCustomer()
{
name = raw_input("what is the customers name? >>> ");
System.out.println ("what kind of account do you want to create:");
System.out.println ("\t 1: CURRENT");
System.out.println ("\t 2: DEPOSIT");
System.out.println (" \t>>>");
type = input( );
while ((type != CURRENT) and (type != DEPOSIT))
{
System.out.println (" Sorry, input not recognised. Plese select 1 or 2:");
System.out.println ("\t 1: current");
System.out.println ("\t 2: deposit");
type = input(" \t>>> " );
}//while
updateCustomer(name, type);
}//add customer()
public void viewBalance()
{
//remember len(...) is a function which returns the length of a list
// its Java equivalent is <arrayName>.length
if (customers.length>0) //# ie we have customers
{
displayCustomers();
Boolean active = False;
String account = "";
custId = getCustId();
name = customers[custId];
accountType = getAccount( );
if (accountType () == CURRENT)
{
balance = currentAccountBalances[custId];
account = "current";
active = hasCurrent[custId];
}//if
else
{
balance = depositAccountBalances[custId];
account = "deposit";
active = hasDeposit[custId];
}
if (active)
{
System.out.println("Balance on"+ name+ "'s"+ account +"account is:" +balance);
}
else
System.out.println ("sorry that account has not been set up");
}
else
System.out.println ("No Customers available");
}//view balance()
public static void withdrawCash()
{
if (customers.length> 0);
{
displayCustomers();
custId = getCustId();
name = customers[custId];
accountType = getAccount( );
if ((accountType == CURRENT)and(hasCurrent[custId]))
withdraw(currentAccountBalances + custId + accountType);
else if ((accountType == DEPOSIT) and (hasDeposit[custId]))
withdraw(depositAccountBalances, custId, accountType);
else if
(System.out.println ("sorry! that account has not been set up"));
else
System.out.println ("No Customers available...");
}
}//withdraw cash()
public static void depositFunds()
{
{
if (customers.length> 0)
displayCustomers();
custId = getCustId();
name = customers[custId];
accountType = getAccount( );
if ((accountType) == (CURRENT) and (hasCurrent[custId]))
deposit(currentAccountBalances, custId, accountType);
else if ((accountType == DEPOSIT) and (hasDeposit[custId]))
desposit(depositAccountBalances, custId, accountType);
else System.out.println ("sorry! that account has not been set up");
else System.out.println ("No Customers available...");
}
}//deposit funds()
public static void check(){ // might not need this function in Java if showOptionDialog is used
bValue = False;
if (choice in range(0, 5))
bValue = True;
return bValue;
}//check()
public static void updateCustomer(custName,accountType){
// This condition might take a bit of thought to deal with in Java. Hint: what does isMember( ) do?? :
if (custName in customers)
custId = customers.index(custName);
currValue = hasCurrent[custId];
depValue = hasDeposit[custId];
create = True;
if (currValue)
{
System.out.println custName, ("already has a current account.");
}//currValue()
if (accountType) == CURRENT
System.out.println ("Sorry, you can't create another current account with us");
create = False;
if (depValue)
{
System.out.println custName, ("already has a deposit account with us");
}//depvalue()
if (accountType) == DEPOSIT
System.out.println ("Sorry, you can't create another deposit account with us");
create = False;
if (create)
{
createAnotherAccount(custId, accountType);
}//create ()
else()
createNewAccount(custName, accountType);
}// update customer()
public static void displayCustomers(){ length = len(customers);
System.out.println ("CUST ID\tCUST NAME");
System.out.println ("=======\t=========");
for count in range(0, length);
System.out.println (" " + str(count) + "\t ", customers[count]);
}//display customer()
public static void getCustId(){
tempId = input("Please enter custId >>> ");
length = len(customers);
while (tempId < 0 or tempId > length)
tempId = input(" invalid data: Please enter custId in range 0 to " + str(length));
return tempId
}//get custID()
public static void getAccount( ){
tempAcc = input("Please select \n1. CURRENT or \n2. DEPOSIT \n>>>");
while (tempAcc != CURRENT) and (tempAcc != DEPOSIT)
tempAcc = input("Invalid selection. Please select \n1. CURRENT or \n2. DEPOSIT \n>>>");
return tempAcc;
}// get account
public static void deposit(accountBalanceArray, id, type){
deposit = input("How much money does the customer want to deposit (0 to quit)? >>> " + POUND);
while (deposit < 0)
System.out.println ("use the withdraw function to take money from an account...");
deposit = input("How much money does the customer want to deposit (0 to quit)? >>> "+ POUND);
if (deposit >= 0)
accountBalanceArray[id] += deposit;
account = "";
name = customers[id];
if (type == CURRENT)
account = "current";
else ()
account = "deposit";
System.out.println ("New balance on" name+"'s", account,"account is: "+ POUND + str(accountBalanceArray[id]));
}//deposit
public static void withdraw(accountBalanceArray, id, type){
withdrawal = input("How much money does the customer want to take out (0 to quit)? >>> "+ POUND);
{
while (accountBalanceArray[id] - withdrawal) < 0 or withdrawal < 0
if (withdrawal < 0)
System.out.println ("use the deposit function to add money to an account...");
else
System.out.println ("Sorry. That amount would put the customer into the red.");
System.out.println ("The max amount the customer can withdraw is " + POUND + str(accountBalanceArray[id]));
withdrawal = input("How much money do they want to take out (0 to quit)? >>> " + POUND );
if (withdrawal >= 0)
accountBalanceArray[id] -= withdrawal;
account = "";
name = customers[id];
if (type == CURRENT)
account = "current";
else()
account = "deposit";
System.out.println ("New balance on", name+"'s", account,"account is: " + POUND + str(accountBalanceArray[id]));
}
public static void createNewAccount(custName, accountType){
account = "";
// hmm.. append is a built in Python program. We'll have to use our own append function in Java:
customers.append(custName)
{
if (accountType == CURRENT)
hasCurrent.append(True);
hasDeposit.append(False);
account = "current";
}
{
else if (accountType == DEPOSIT)
hasCurrent.append(False);
hasDeposit.append(True);
account = "deposit";
currentAccountBalances.append(0);
depositAccountBalances.append(0);
print custName + "'s", account, "account set up...";
}
}//create new account()
public static void createAnotherAccount(custId, accountType)
{
account = "";
{
if (accountType == CURRENT)
hasCurrent[custId] = True;
account = "current";
}
{
else if (accountType == DEPOSIT)
hasDeposit[custId] = True;
account = "deposit";
System.out.println (customers[custId] + "'s", account, "account set up...");
}
}

}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > python to java


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT