وبلاگ شخصی مستر حاج رضا

وبلاگ شخصی مستر حاج رضا

در اینجا میخوام فقط بنویسم! درهم و نامربوط! همه چیز
وبلاگ شخصی مستر حاج رضا

وبلاگ شخصی مستر حاج رضا

در اینجا میخوام فقط بنویسم! درهم و نامربوط! همه چیز

برنامه جاوایی که این چند روز نوشتم

این آخرین تکلیف ام تو درس جاوا بود. درسته تا حالا نمره های خوبی گرفتم ولی باید اذعان کنم که این زبان واقعاً زبان حوصله بر و منفجر کننده مغزه! 

برای نوشتن این برنامه حدود سه روز به مدت 14 ساعت تا حالا کار کردم روش! ناگفته نماند که یه کم تقلب هم کردم! 

این برنامه ای که نوشتم در مورد نشان دادن حساب های بانکی، مقدار پولی که کاربر به حساب خود افزوده، مقدار پولی که کاربر از حساب خود برداشت کرده، تعیین میزان سود بانکی، محاسبه سود بانکی، محاسبه هزینه ها و سرویس های ماهانه بانکی و میزان موجودی در حساب بعد از تمام کسورات. 

این برنامه از سه تا کلاس تشکیل شده. کلاس اول که کلاس بانک اکانت هست یک کلاس انتزاعی هست که تمام فیلد ها و متودهای مربوط به محاسبات رو توش انجام میده. کلاس دوم کلاسی است که از کلاس اول به ارث گرفته شده و فعال بودن و غیرفعال بودن کلاس رو نشون میده و به علاوه نشون میده که اجازه فعالیت به بعضی از عملیات ها در صورتی که موجودی کمتر از 25  دلار باشه نده. سوپر کلاسها هم در همین کلاس دوم که به اسم سیوینگ اکانت هست قرار گرفته. کلاس سوم، کلاس درایور هست و عملاً همه کارها و متودهایی که در دو کلاس قبلی گفته شده بود را به نمایش میزاره. البته در این کلاس درایور من دو تا آبجکت هم درست کردم که نتیجه کار رو در دو حساب بانکی ببینم. 

This is my last Java assignment.  I post it here in my personal blog to keep these codes as a record for me.

I hope my professor gives me complete grade for this one because I spent plenty of time to finish it! 

I put this sentences in English that if she look up and searches my codes in internet and subsequently find this page, I can prove to  her that these codes are really mine! 

Here is a clue for her, I am DCCCD student! and my name is Reza

 برای دیدن کدها به ادامه مطلب بروید

 کد کلاس اول (بانک اکانت)

package bankaccount;


// creating an abstract class

public abstract class BankAccount 

{


/* creating fields for account balance, numberDeposit, NumberWithdrawals

  AnnualInterestRate, and MonthlyServiceCharges 

    They are all initialized with zero */  

private double balance = 0;

private int NumberDeposits=0;

private int NumberWithdrawals=0;

private double AnnualInterestRate = 0;

private double MonthlyServiceCharges=0;


//A constructor method that accepts as arguments the balance and the annual interest rate

public BankAccount()

{

  

}

public BankAccount(double bal,double annIntRate)

{

balance=bal;

AnnualInterestRate=annIntRate;   

}


//A method that accepts the monthly service charges as an argument and set the field value

// we set the Monthly Service Charges and Annual Interest Rate here

public void setMonthlyServiceCharges(double monservicecharges)

{

MonthlyServiceCharges=monservicecharges;

}

public void setAnnualInterestRate(double rate)

{

AnnualInterestRate=rate;

}


/* Creating methods that return the bank account balance,  number of deposits this month

number of withdrawals this month, annual interest rate, and  the monthly service charge*/


public double getBalance()


{

return balance;

}

public int getNumberDeposits()

{

return NumberDeposits;

}

public int getNumberWithdrawals()

{

return NumberWithdrawals;

}

public double getAnnualInterestRate()

{

return AnnualInterestRate;

}

public double getMonthlyServiceCharge()

{

return MonthlyServiceCharges;

}



/* Creating method that accepts the amount of the deposit as an argument, add the value of

that argument to the account balance, and increment the variable holding the number of

deposits. */

//dep as deposit, w as withdrawal

public void deposit(double dep) 

{

balance=balance+dep;

NumberDeposits++;

}

public void withdrawal(double w)

    {

balance=balance-w;

NumberWithdrawals++;

    }


//A method that updates the balance by calculating the monthly interest earned by the account

public void calculateInterest()

    {

double monthlyInterest;

monthlyInterest=balance*(AnnualInterestRate/12); //interest calculation formula

balance=balance+monthlyInterest;

    }


//A method that subtracts the monthly service charges from the balance

public void monthlyProcess()

    {

balance=balance-MonthlyServiceCharges;

calculateInterest();

NumberDeposits=0;

NumberWithdrawals=0;

MonthlyServiceCharges=0;

    }


}


کد کلاس دوم (سیوینگ اکانت)


package bankaccount;

    

//declare this class inheritated from BankAccount class

class SavingsAccount extends BankAccount{

    

//A private (Boolean) field that holds the account status

private boolean status=true;


/* constructor method that accepts as arguments the account balance, the annual interest rate, and 

the monthly service charge. The constructor should call the superclass constructor and, based on the

account balance, the constructor should set the account Status to true or false */

public SavingsAccount(double balance, double annualInterestRate,double servicecharge)

{

super.deposit(balance); // superclass version of the Deposit method to make a deposit

super.setAnnualInterestRate(annualInterestRate); 

super.setMonthlyServiceCharges(servicecharge);

if(balance>=25) // the balance of the account must greater or equal to $25

{

status=true;

}

else //else methode, if balance is less than 25$

{

status=false;

}

}


/* A method that accepts the deposit amount as an argument, calls the superclass version of the

Deposit method to make a deposit, and then updates the Status of the accounts if the balance goes

above $25. */

public void deposit(double amount)

{

if(status)

{

super.deposit(amount);

}

if(super.getBalance()>25)

{

status=true;

}

else

{

status=false;

}

}



/* A method that accepts the withdrawal amount as an argument, checks if the status of the

account is active, and, if that is true, calls the superclass version of the Withdrawal method,

to make a withdrawal from the account. The method should update the Status if the balance goes

under $25. */

public void withdrawal(double amount)

{

if(status)

{

super.withdrawal(amount);

}

if(super.getBalance()>25)

{

status=true;

}

else

{

status=false;

}

}


//A method that does the monthly process based on the number of withdrawals from the account

public void monthlyProcess()

{

    

/* If the number of withdrawals for the month is more than 4, then a service charge of $1 for

   each withdrawal above 4 */

if(super.getNumberWithdrawals()<=4)

{

super.monthlyProcess();

  

}

else

{

int temp=1;

for(int i=super.getNumberWithdrawals();i>0;i--)

{

super.setMonthlyServiceCharges(temp);

temp++;

}

}

super.monthlyProcess();

}



}

کد کلاس سوم (درایور کلاس) البته اسمش رو چیز دیگه گذاشتم که تو متن میبینید

package bankaccount;


//This is a driver class for the other two class

public class RezaAssignment9 {

 public static void main(String[] args)

{


//creating two bank account objects

SavingsAccount sobj=new SavingsAccount(10000,2.4,100);

SavingsAccount sobj1=new SavingsAccount(2200,2.8,120);


System.out.println("**** Here is Your Saving Accounts Information *****");

System.out.println("");//empty line to seperate


//print the first account information

System.out.println("**** First Account *****");

System.out.println("Balance = "+sobj.getBalance());

System.out.println("Number of Deposits = "+sobj.getNumberDeposits());

System.out.println("Number of withdrawals = "+sobj.getNumberWithdrawals());

System.out.println("Annual Interest Rate = "+sobj.getAnnualInterestRate()+"%");

System.out.println("Monthly Service Charge = "+sobj.getMonthlyServiceCharge());

// object parameters for account 1

sobj.deposit(100);

sobj.withdrawal(500);

sobj.calculateInterest();

sobj.monthlyProcess();

System.out.println("Updated Balance = "+sobj.getBalance());


System.out.println(""); //empty line to seperate


// print the Second Bank Account information

System.out.println("**** Second Account *****");

System.out.println("Balance = "+sobj1.getBalance());

System.out.println("Number of Deposits = "+sobj1.getNumberDeposits());

System.out.println("Number of withdrawals = "+sobj1.getNumberWithdrawals());

System.out.println("Annual Interest Rate = "+sobj1.getAnnualInterestRate()+"%");

System.out.println("Monthly Service Charge = "+sobj1.getMonthlyServiceCharge());

//object parameters for account 2

sobj1.deposit(100);

sobj1.withdrawal(10);

sobj1.calculateInterest();

sobj1.monthlyProcess();

System.out.println("Updated Balance = "+sobj1.getBalance());


}   

}


نظرات 8 + ارسال نظر
شن های ساحل سه‌شنبه 23 مرداد 1397 ساعت 11:11 http://seashell.blog.ir/

خیلی هم عالی لطف میکنین

شن های ساحل سه‌شنبه 23 مرداد 1397 ساعت 09:52

من یه چند وقتی شروع کردم به یادگیری زبان سی بعضی قسمت هاش واقعا مغزم منفجر شد اونوقت من فکر میکردم سی خیلی سخته پس جاوا از اونم سخت تره هی وای من.میشه لطف کنین اگه برای جاوا کتابی هست که خودتون از روی اون می خونین معرفی کنین؟

بله کتابی که ما داریم البته به انگلیسیه
اگه دوست داشته باشید براتون پی دی اف اش رو براتون بفرستم

سحر چهارشنبه 17 مرداد 1397 ساعت 00:25 http://roya-94.blogsky.com/

برا بار صدم گفتم بمنم یاد بده هر چی بلدی همین جوری منو نگا میکنه!

شما که فکر نکنم هنوز آمادگی اش رو داشته باشید!

روشن سه‌شنبه 16 مرداد 1397 ساعت 15:22 http://roshann.blogsky.com

من اصلاااااا نمیفهمم این همه سختی چرا تو این رشته جمع شده
خیلی خیلی داغووووون سخته ....
البته برای من
تو ک استادی

تا درس عبرتی بشه برای بقیه که سراغش نیان !

Baran دوشنبه 15 مرداد 1397 ساعت 18:23 http://haftaflakblue.blogsky.com/

کلاس اول؛
+خدا قوت

Maryam.k دوشنبه 15 مرداد 1397 ساعت 15:43 http://dreamlandd.blogsky.com

سلام
چه سختتتتتتتتتتتتتت

بهامین دوشنبه 15 مرداد 1397 ساعت 11:59

همیشه فکر میکردم خوندن اصول و مباحث حقوق مخصوصا جزا سخت ترین درس ممکنه
اما الان فکر میکنم برنامه نویسی خیلی سخت  
آفرین به مهارت شما :)

مرسی اما تا حدی اش رو جستجو کردم و به این برنامه اضافه کردم. هر رشته ای یه درس سخت حتما داره.ولی رشته ما بیشتر درسهاش سخته.

بهامین دوشنبه 15 مرداد 1397 ساعت 01:41

همیشه فکر میکردم خوندن اصول و مباحث جزا واسم سخته
الان فکر میکنم برنامه نویسی خیلی سخته...
آفرین به مهارت شما:)

مرسی اما تا حدی اش رو جستجو کردم و به این برنامه اضافه کردم. هر رشته ای یه درس سخت حتما داره.ولی رشته ما بیشتر درسهاش سخته.

برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد