Java class and object, Java object

Source: Internet
Author: User

Java class and object, Java object

Write Java applications. First, define an Account class that describes the bank Account, including member changes.

Account and deposit balance. The member methods include deposit, withdrawal, and balance query ". Second,

Write a primary class and test the Account class function in the primary class.

Class:

 

1 String bankAccountNumber; 2 String name; 3 double cunKuanYu_e; 4 5 void cunkuan (double cunkuan) {6 cunKuanYu_e = cunKuanYu_e + cunkuan; 7 System. out. println (name + "your account is:" + bankAccountNumber + "in the account to save" + cunkuan + "Yuan, existing balance" + cunKuanYu_e ); 8} 9 10 void qukuan (double qukuan) {11 if (cunKuanYu_e >= qukuan) {12 cunKuanYu_e = cunKuanYu_e-qukuan; 13 System. out. println (name + "your account is:" + bankAccount "+ Qukuan +" Yuan, existing balance "+ cunKuanYu_e); 14} else {15 System. out. println (name + "your account is:" + bankAccountNumber + ", with insufficient balance! "); 16} 17} 18 19 double getYu_E () {20 return cunKuanYu_e; 21}

 

 

 

Call:

1 Account ren1 = new Account (); 2 ren1.bankAccountNumber = "622848123456789"; 3 ren1.name = "zhangsan"; 4 ren1.cunKuanYu _ e = 587.54; 5 6 7 ren1.qukuan (600.0 ); 8 System. out. println (ren1.name + "balance =" + ren1.getYu _ E (); 9 ren1.cunkuan (1000); 10 11 Account ren2 = new Account (); 12 ren2.bankAccountNumber = "622848987654321 "; 13 ren2.name = ""; 14 ren2.cunKuanYu _ e = 87.54; 15 16 17 double ren1ye = ren1.getYu _ E (); 18 System. out. println (ren1.name + "account balance:" + ren1ye); 19 double ren2ye = ren2.getYu _ E (); 20 System. out. println (ren2.name + "account balance:" + ren2ye );

 

 

Result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.