使用抽象日期类型设计信用卡

时间:2016-02-29 18:32:47

标签: java

所以我应该设计并实现代表信用卡的ADT。它应包括客户名称,帐号,截止日期,奖励积分和帐户余额。应该有信用卡费用,现金预付款,付款,余额利息的增加以及银行账户统计数据的显示操作。但是,当我运行我的程序时, 我一直收到一个错误说#34; Class" creditCard"没有主要方法。"

 import java.util.Scanner;
 import javax.swing.*;
 import java.awt.*;
 import java.net.*;
 import java.awt.image.BufferedImage;
 import javax.imageio.ImageIO;
 import java.io.IOException;
 public class creditCard {

private int customerName;
private int accountNumber;
private int dueDate;
private int rewardPoints;
private int accountBalance;
static Scanner input = new Scanner(System.in);

double creditLimit = 500;
int user = 0;

public int getCustomerName() {
    return customerName;
}

public void setCustomerName(int customerName) {
    this.customerName = customerName;
}

public int getAccountNumber() {
    return accountNumber;
}

public void setAccountNumber(int accountNumber) {
    this.accountNumber = accountNumber;
}

public int getDueDate() {
    return dueDate;
}

public void setDueDate(int dueDate) {
    this.dueDate = dueDate;
}

public int getRewardPoints() {
    return rewardPoints;
}

public void setRewardPoints(int rewardPoints) {
    this.rewardPoints = rewardPoints;
}

public int getAccountBalance() {
    return accountBalance;
}

public void setAccountBalance(int accountBalance) {
    this.accountBalance = accountBalance;
}

public String charge(float amount) {
    if (amount > creditLimit) {
        System.out.println("You have exceeded your credit card limit and no charge can be made");
    }
    if (creditLimit - amount > 0) {
        System.out.println("You have exceeded your credit card limit and no charge can be made");
    }
    creditLimit = creditLimit - amount;
    System.out.println("A charge of" + amount + "has been made.");
    String charge = "A charge of" + amount + "has been made.";
    return charge;
}

public String advance(float amount) {
    if (amount > creditLimit) {
        System.out.println("You have exceeded your credit card limit and no charge can be made");
    }
    if (creditLimit - amount > 0) {
        System.out.println("You have exceeded your credit card limit and no charge can be made");
    }
    creditLimit = creditLimit - amount;
    System.out.println("You have withdrawn $ " + amount);
    String advance = "You have withdrawn $ " + amount;
    return advance;
}

public String payment(float amount) {
    creditLimit = creditLimit + amount;
    System.out.println("You have a credit limit of $ " + creditLimit);
    String payment = "You have a credit limit of $ " + creditLimit;
    return payment;
}

public String interest() {
    creditLimit = (creditLimit * 0.02) + creditLimit;
    String interest = "An interest of" + creditLimit * 0.02 + "has been added to your balance";
    return interest;
}

public void statistics(String charge, String advance, String payment, String interest) {

    System.out.println(charge);
    System.out.println(advance);
    System.out.println(payment);
    System.out.println(interest);

}

public void showMenu() {
    while (user!= 5) {
        System.out.println("Choose Charge(1) \nAdvance(2) \nPayment(3) \nInterest(4) \ncStatistics(5)");
    user = input.nextInt();
    switch (user) {
        case 1:
            float amount;
            System.out.println("Enter the amount: ");
            amount = input.nextFloat();
            String charge = charge(amount);
            break;
        case 2:
            float withdrawalAmount;
            System.out.println("Enter amount to withdraw: ");
            withdrawalAmount = input.nextFloat();
            String advance = advance(withdrawalAmount);
            break;
        case 3:
            float paymentAmount;
            System.out.println("Enter payment.");
            paymentAmount = input.nextFloat();
            String payment = payment(paymentAmount);
            break;
        case 4:
            String interest = interest();
            break;
        //case 5:
        //statistics(charge, advance, payment, interest);
        //break;
    }
    }
}


public void main(String[] args) {
    showMenu();
}

}

1 个答案:

答案 0 :(得分:0)

使main方法保持静态。

public static void main(String[] args) {
    showMenu();
}

或者更好地创建另一个入口点类并将主要文件放在那里。

public class Runner {
   public static void main(String[] args) {
      CreditCard creditCard= new CreditCard();
      creditCard.showMenu();
      // Do something else

   }