2008년 8월 3일 일요일

ex8



public class ex8 {
//배열 inex가 하나더 필요하고요.
static int index = 0,indexName=0;
static int startAccountNumbers = 123;
// static int [] accountNumbers = new int [5];
// static double [] accountBalances = new double [5];
// static String [] firstNames = new String [5];
// static String [] lastNames = new String [5];
// static boolean [] creditCards = new boolean [5];
//원래는 클래스로 묶고 벡터를 사용해야 하는데

//여기하고
//"indexName"
static int [] accountNumbers = new int [50];
static double [] accountBalances = new double [50];
static String [] states = new String [50];


//여기는 다르게 생각하고요.
//"index"
static String [] firstNames = new String [50];
static String [] lastNames = new String [50];
static boolean [] creditCards = new boolean [50];
static double [] accountBalancesSum = new double [50];


public static void main (String [] args) {//메인에 있는것은 무조건 들어가야하는거입니다.

createNewCustomer ();

createNewCustomer ();

createNewCustomer ();


makeDeposit (1539.28, 123);

makeDeposit (-483,123);

makeWithdrawal (399.99, 123);


makeDeposit (333.50, 369);

makeDeposit (400, 369);

makeDeposit (512.99, 369);

makeWithdrawal (250, 369);


makeWithdrawal (200, 1107);

makeDeposit (200, 1107);

makeWithdrawal (-800000,1107);

makeWithdrawal (200, 1107);


makeWithdrawal (1000, 3443);

makeDeposit (14.92, 93939);

printAllAccounts ();

}

public static void createNewCustomer () {

firstNames [indexName] = JOptionPane.showInputDialog ("Enter new customer's first name:");

lastNames [indexName] = JOptionPane.showInputDialog ("Enter new customer's last name:");

accountNumbers [indexName]= startAccountNumbers;

startAccountNumbers = startAccountNumbers * 3;

accountBalances [indexName] = 0;

creditCards [indexName] = false;

indexName = startAccountNumbers /(3*123);

}

public static void printAccount (int index) {
int tempInedx;
for (int i = 0; i < index; i++) {

tempInedx = accountNumbers[i]/(3*123);
if(tempInedx>=0 && tempInedx<=50 && firstNames [tempInedx]!=null){

accountBalancesSum[tempInedx]=accountBalancesSum[tempInedx]+accountBalances[i];
if (accountBalancesSum[tempInedx] < 1000) {

creditCards [tempInedx] = false;

} else {

creditCards [tempInedx] = true;

}

if (accountBalancesSum[tempInedx] > -1) {

System.out.println ("$" + accountBalancesSum[tempInedx] + states[i] + " to account number: " + accountNumbers[i]);

System.out.println ("Account number: "+ accountNumbers [i]);

System.out.println ("Name: " + lastNames [tempInedx] + ", " + firstNames [tempInedx]);

System.out.println ("Account balance: $" + accountBalancesSum[tempInedx]);

if (creditCards [i] == true) {

System.out.println ("Credit card: Yes\n" );

} else {

System.out.println ("Credit card: No\n" );

}

} else {

//System.out.println ("Deposits must be greater than zero!\n");

}

}else{System.out.println("Account number "+ accountNumbers[i]+" not found!");}

}//for
}

public static void printAllAccounts () {

printAccount (index);

System.out.println ("*** Summary of Accounts ***");

}

public static void makeDeposit (double amount, int accountNumber) {

accountBalances [index] = amount;
accountNumbers [index] = accountNumber;
states[index] = " deposited";
index++;


}

public static void makeWithdrawal(double amount, int accountNumber) {

accountBalances [index] = amount;
accountNumbers [index] = accountNumber;
states [index] = " withdrawn";
index++;



}

}//main





문]
시험이 다음주라 선생님 추천의 문제 풀고있는데 잘 안풀려서요.


댓글 없음:

댓글 쓰기

-


Sidewinder


World


FishMusic


LaughingBaby