⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ticketmachine.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
/** * TicketMachine models a naive ticket machine that issues * flat-fare tickets. * The price of a ticket is specified via the constructor. * It is a naive machine in the sense that it trusts its users * to insert enough money before trying to print a ticket. * It also assumes that users enter sensible amounts. * * @author David J. Barnes and Michael Kolling * @version 2006.03.30 */public class TicketMachine{    // The price of a ticket from this machine.    private int price;    // The amount of money entered by a customer so far.    private int balance;    // The total amount of money collected by this machine.    private int total;    /**     * Create a machine that issues tickets of the given price.     * Note that the price must be greater than zero, and there     * are no checks to ensure this.     */    public TicketMachine(int ticketCost)    {        price = ticketCost;        balance = 0;        total = 0;    }    /**     * Return the price of a ticket.     */    public int getPrice()    {        return price;    }    /**     * Return the amount of money already inserted for the     * next ticket.     */    public int getBalance()    {        return balance;    }    /**     * Receive an amount of money in cents from a customer.     */    public void insertMoney(int amount)    {        balance = balance + amount;    }    /**     * Print a ticket.     * Update the total collected and     * reduce the balance to zero.     */    public void printTicket()    {        // Simulate the printing of a ticket.        System.out.println("##################");        System.out.println("# The BlueJ Line");        System.out.println("# Ticket");        System.out.println("# " + price + " cents.");        System.out.println("##################");        System.out.println();        // Update the total collected with the balance.        total = total + balance;        // Clear the balance.        balance = 0;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -