我在某些方法上出错

时间:2018-12-06 02:28:45

标签: java arrays bluej tui

我正在编写这个Java类,它是Class loyaltyCard的TUI,但是,使用以下方法遇到一些错误。谢谢您的帮助。

  1. 公共无效addLoyalty卡

  2. 公共无效的ShowAllLoyaltyCards(它应打印所有会员卡的详细信息,并且每张之间都有一个空格)

  3. 公共无效的showLoyaltyCard(如果“消息”不成功,请打印带有选择卡号的loyaltycard

这是我的代码:

import java.util.ArrayList;
import java.util.Scanner;

public class LoyaltyCardTUI
{

    private LoyaltyCardList loyaltyCardList;
    private Scanner myScanner;

    public LoyaltyCardTUI()
    {
        myScanner = new Scanner(System.in);
        LoyaltyCardList loyaltyCardList = new LoyaltyCardList();
    }

    public void menu()
    {
        int command = -1;
        while (command != 0)
        {   
            displayMenu();
            command = getCommand();
            execute (command);
        }
    }

    **public void addLoyaltyCard(**)
    {
        loyaltyCardList.addLoyaltyCard(new LoyaltyCard());
    }

    private void displayMenu()
    {
        System.out.println( "Options are" );
        System.out.println( "Enter 1" );
        System.out.println( "Enter 2" );
        System.out.println( "Enter 3" );
        System.out.println( "Enter 4" );

    }

    private void execute( int command)
    {
        if ( command == 1)
            addLoyaltyCard();
        else
        if ( command == 2 )
            getNumberOfLoyaltyCards();
        else
        if ( command == 3)
            quitCommand();
        else
        if ( command == 4)
            quitCommand();
        else
        if ( command == 5)
            quitCommand();
        else
            System.out.println("Unknown Command");
    }

    private int getCommand()
    {
        System.out.print ("Enter command: ");
        int command = myScanner.nextInt();
        myScanner.nextLine(); 
        return command;
    }

    public void getNumberOfLoyaltyCards()
    {
        int command = myScanner.nextInt();
        System.out.println("We have" + loyaltyCardList.getNumberOfLoyaltyCards() + "loyaltyCards");
    }

    public void quitCommand()
    {
        int command = myScanner.nextInt();
        System.out.println("Application Closing");
        System.exit(0);
    }

    private void removeLoyaltyCard()
    {     
        System.out.print("Enter card number : ");
        String cardNumber = myScanner.nextLine();
        if (loyaltyCardList.removeLoyaltyCard(cardNumber))
            System.out.println("LoyaltyCard with card number  " + cardNumber + " removed from class list");
        else
            System.out.println("LoyaltyCard with card number " + cardNumber + " not  found");
    }

    **public void showAllLoyaltyCards()**
    {
        for(LoyaltyCard loyaltyCard : loyaltyCards)
        {
            loyaltyCard.printCustomerDetails();
            System.out.println();
        }
    }

    **public void showLoyaltyCard()**
    {
        for (LoyaltyCard loyaltyCard : loyaltyCards)
        {
            if (cardNumber.equals(loyaltyCard.getCardNumber()))
            {
                return System.out.println(loyaltyCard);
            }
            else
            {
                return System.out.println("Could not find loyalty card for card number"+cardNumber);
            }
        }
    }

    private void unknownCommand(int command)
    {
        System.out.println("Invalid Command : "+ command);
    }
}

0 个答案:

没有答案