Chp10 10.7

《Java语言程序设计》P296

本章是关于对象的思考,主要是在研究面向对象的程序设计时类的设计,作业写得比较杂乱,构造方法时没有严格遵守类的流行设计风格,由于是作业,再加上比较简单,没有添加任何注释。

整套程序分为两个类,一个Account类,用于定义Account()及其方法;一个AccountTest类,用于调用Account类中的方法以实现题目要求的功能。

public class Account {
    private static int ACOUNT_NUMBER = 5;
    private int moneyAtAcount = 5000;
    private boolean isLogin = false;
    public void Acount(){

    }

    public int getMoneyAtAcount(){
        return moneyAtAcount;
    }

    public void withdraw(int m){
        moneyAtAcount -= m;
        System.out.println("Withdraw "+m+" succeed, now balance have " + moneyAtAcount);
    }

    public void deposite(int n){
        moneyAtAcount += n;
        System.out.println("Deposite "+n+" succeed, now balance have " + moneyAtAcount);
    }

    public void login(int p){
        if(p == ACOUNT_NUMBER){
            isLogin = true;

        }else
            System.out.println("Wrroy Account");
    }

    public boolean getLogin(){
        return isLogin;
    }

    public void logout(){
        isLogin = false;
    }

}
import java.util.Scanner;

public class AcountTest {
    public static void main(String[] args) {
        Account account = new Account();
        Scanner input = new Scanner(System.in);

        for (int i=1;i>0;i++) {     //人为无限循环,题目要求如此,实现的比较简陋
            System.out.println("Enter an id:");
            account.login(input.nextInt());
            for (;account.getLogin();) {         //对于printf的编辑格式不是很熟悉,为了图方便,选用一打println来输出选单
                System.out.println("Main menu");
                System.out.println("1:check balance");
                System.out.println("2:withdraw");
                System.out.println("3:deposit");
                System.out.println("4:exit");
                System.out.println("Enter a choice: ");

                int choice = input.nextInt();
                switch(choice){
                case 1:
                    System.out.println(account.getMoneyAtAcount());
                    break;
                case 2:
                    System.out.println("Enter an amount to withdraw: ");
                    account.withdraw(input.nextInt());
                    break;
                case 3:
                    System.out.println("Enter an amount to deposit: ");
                    account.deposite(input.nextInt());
                    break;
                case 4:
                    account.logout();
                    break;
                }

            }

        }
    }
}

2016-03-24

时间: 2024-08-07 04:32:53

Chp10 10.7的相关文章

百度粉红色风科技上来看积分

http://www.ebay.com/cln/508gua_gvqjq/-/167266747010/2015.02.10 http://www.ebay.com/cln/jhu2290/-/167423283013/2015.02.10 http://www.ebay.com/cln/cha.m22/-/167166250017/2015.02.10 http://www.ebay.com/cln/fenyu56/-/167382503016/2015.02.10 http://www.eb

百度附件是分开就爱死了开发了

http://www.ebay.com/cln/m_m3154/-/167249028014/2015.02.10 http://www.ebay.com/cln/zhsu412/-/167238372018/2015.02.10 http://www.ebay.com/cln/mi.han5/-/167545028015/2015.02.10 http://www.ebay.com/cln/lij5252/-/167389481016/2015.02.10 http://www.ebay.co

使用 Chrome 浏览器插件 Web Scraper 10分钟轻松实现网页数据的爬取

本文标签: WebScraper Chrome浏览器插件 网页数据的爬取 使用Chrome 浏览器插件 Web Scraper 可以轻松实现网页数据的爬取,不写代码,鼠标操作,点哪爬哪,还不用考虑爬虫中的登陆.验证码.异步加载等复杂问题. Web Scraper插件 Web Scraper 官网中的简介: Web Scraper Extension (Free!)Using our extension you can create a plan (sitemap) how a web site

Install Hyper-V on Windows 10

? Enable Hyper-V to create virtual machines on Windows 10.Hyper-V can be enabled in many ways including using the Windows 10 control panel, PowerShell (my favorite) or using the Deployment Imaging Servicing and Management tool (DISM). This documents

10.4 补充范围内丢失的值

select y.yr.coalesce(x.cnt,0) as cntfrom (select min_year-mod(cast(min_year as int),10)+rn as yrfrom (select (select min(extract(year from hreadate))from emp) as min_year,id-1 as rnfrom t10) a) yleft join(select extract(year from hredate) as yr,count

10.6 监控io性能 - 10.7 free命令 - 10.8 ps命令 - 10.9 查看网络状态 - 10.10 linux下抓包

- 10.6 监控io性能 - 10.7 free命令 - 10.8 ps命令 - 10.9 查看网络状态 - 10.10 linux下抓包 - 扩展tcp三次握手四次挥手 http://www.doc88.com/p-9913773324388.html  - tshark几个用法:http://www.aminglinux.com/bbs/thread-995-1-1.html  # 10.6 监控io性能 ![mark](http://oqxf7c508.bkt.clouddn.com/b

Windows 10 UWP程序标题栏设置

原文:Windows 10 UWP程序标题栏设置 在Windows 10程序中,以前只能用于全屏方式的Metro程序现在可以运行在窗口模式下了,并且改了个新名字,叫Windows 通用程序(Universal Windows app),简称UWP程序.新的UWP程序虽然大体上还是和以前的Metro程序差不多的,但还是引入了一点新东西的,本文这里就介绍一下它的标题栏设置的几个特性. 隐藏标题栏: 将应用界面扩展至 Titlebar 区域 CoreApplication.GetCurrentView

How to enable C development in a Windows 10 development environment VM

To enable C development in a Windows 10 development environment VM, follow these steps: Start VS in the Windows 10 development environment VM. Choose "File" -> "New" -> "Project", choose "Open Visual Studio Install

设置UWP程序自启动(Automate launching Windows 10 UWP apps)

原文:设置UWP程序自启动(Automate launching Windows 10 UWP apps) 在开发UWP程序的过程中,有时候需要设置程序的自启.本人实现的步骤如下: 1.在VS中激活Protocol (Package.appxmanifest --> Declarations --> Add Protocol),图示如下: 2.编译并发布项目(Build and Deploy) 发布之后Protocol被激活,在(控制面板 --> 程序 --> 默认程序 -->