【问题标题】:Express Account program快捷账户计划
【发布时间】:2015-11-20 20:47:54
【问题描述】:

我需要编写一个包含以下内容的代码 在这个项目中,您将编写一个允许用户重复创建和管理快递卡帐户的程序。

每张快递卡就像一张借记卡,只是它只能用于购买餐食。新的 Express 卡账户余额为 0 美元。用户可以

  1. 存钱到快递卡,增加余额(存更多钱),
  2. 以固定价格购买餐食,从而减少余额,并且
  3. 用餐(每刷一次卡,剩余用餐次数减一)。

快递卡账户有两种:

  • 学生快递帐户或
  • 一个教职员工快递账户。

所有快递账户都有字段,accountBalance,numberOfMeals,pricePerMeal 和 baseAmtForBonus。

到目前为止,我不知道从这里去哪里

import java.util.Scanner;
public class ExpAcct{
public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    System.out.println("MAIN MENU /n 1.) Create a new account /n 2.) Log into an existing account /n3.) Exit the banking system /nPlease enter your selection.");
    int main = scan.nextInt();
    System.out.println("CHOOSE THE TYPE FOR THE NEW ACCOUNT /n1.) Student express account /n2.)Faculty express account /nPlease enter your selection");
    int accType = scan.nextInt();

}


public class ExpressAccount extends ExpAcct{
public ExpressAccount(int accNumber){

}
public int getAccountNumber(){
    return accNumber;
}
public double getAccountBalance(){
    return accBalance;
}
public double getBaseAmtForBonus(){
    return baseAmt;
}
public double getPricePerMeal(){
    return pricePerMeal;
}
public int getNumOfMeals(){
    return numMeals;
}
public String toString(){

}

【问题讨论】:

  • 您好,由于没有准确的问题,您可能不会得到一个好的答案。
  • “从这里到哪里去”是什么意思?您遇到的具体问题或具体点是什么?
  • 尝试使用 if 语句来得到你想要的。尝试进一步澄清您的帖子。在下面检查我的答案!

标签: java arrays object


【解决方案1】:

您要做的是检查用户输入的内容:

    if(main==1){
        if(accType==1){
            String accTypeWord = "Student";
        if(accType==2){
            String accTypeWord = "Faculty";

}
    if(main==2){
    System.out.println("Please enter your password: ");
    //check if password equals their account password
}
    if(main==3){
    System.out.println("Have a good day! Thanks for visiting the bank.");
}

当你想向他们收钱买餐时,你可以试试这个:

    Scanner scanner = new Scanner(System.in);
    System.out.println("How much do you have in your ATM account? ");
    double accountBalance = scanner.nextInt();
    System.out.println("Please enter cost of meal: ");
    double mealCost = scanner.nextInt();
    int accountBalance -= mealCost

这将使您在银行中的金额减少用餐费用。您可能不希望他们的帐户中有多少,但我必须在此处向您展示如何操作。

以下是您在程序中需要的步骤:

  1. 使用 if 语句检查他们做出了哪些选择。(创建新帐户、登录预先存在的帐户等)
  2. 我已经向您展示了如何向他们收取购买餐费的费用。
  3. 要求存款,将其存储到一个 double 中,然后通过执行以下操作将其添加到帐户中: accountBalance += depositAmount;

祝你好运,编码愉快!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-07
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 2016-12-08
    • 2011-12-03
    相关资源
    最近更新 更多