Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我必须做一个“回答”;猜猜下一张牌会更高;游戏但是可以';我没有发现问题_Java_Class_If Statement_Arraylist_Game Physics - Fatal编程技术网

Java 我必须做一个“回答”;猜猜下一张牌会更高;游戏但是可以';我没有发现问题

Java 我必须做一个“回答”;猜猜下一张牌会更高;游戏但是可以';我没有发现问题,java,class,if-statement,arraylist,game-physics,Java,Class,If Statement,Arraylist,Game Physics,3节课。牌,游戏和甲板。 我不知道为什么它会给我一个错误。 希望有人能帮助我,我想知道是什么问题 标题说的是,我必须猜测下一张牌是高还是低 打包卡片游戏; 导入java.util.Scanner; 导入java.util.*; 公开课游戏{ 私人静态智力得分; //当前卡片:卡片 专用静态卡; //下一张牌 私人卡nextCard; //扫描器 私人静态甲板; 专用静态扫描仪sc=新扫描仪(System.in); //主要 公共静态void main(字符串[]args){ 甲板=新甲板();

3节课。牌,游戏和甲板。 我不知道为什么它会给我一个错误。 希望有人能帮助我,我想知道是什么问题

标题说的是,我必须猜测下一张牌是高还是低


打包卡片游戏;
导入java.util.Scanner;
导入java.util.*;
公开课游戏{
私人静态智力得分;
//当前卡片:卡片
专用静态卡;
//下一张牌
私人卡nextCard;
//扫描器
私人静态甲板;
专用静态扫描仪sc=新扫描仪(System.in);
//主要
公共静态void main(字符串[]args){
甲板=新甲板();
currentCard=deck.getNextCard();
Game.gameTurn();
}
//转法
公共静态void gameTurn(){
//System.out.println(Deck.getCards().size());
System.out.print(“您的下一张卡是高于还是低于下一张卡?”);
系统输出打印(sc);
字符串应答=sc.nextLine();
Card nextCard=deck.getNextCard();
if(回答等于(“更高”)&&nextCard.ISHIGHEREQUALE(当前卡)){
正确的();
}else if(answer.equals(“lower”)和&!nextCard.isHigherOrEqual(currentCard)){
正确的();
//answer.equals(“lower”)和&!nextCard.IshighErrorequal(currentCard)
}否则{
gameOver();
}
}
//正确的方法
公共静态无效更正(){
Game.gameTurn();
得分=0;
分数++;
}
//博弈论方法
公共静态void gameOver(){
System.out.println(“总分为“+score+”!”);
}
}
打包纸牌游戏;
导入java.util.ArrayList;
导入java.util.Collections;
公务舱甲板{
//cards=Card=newarraylist()
私有静态ArrayList卡=新ArrayList();
//甲板法
公共空甲板(){
对于(int i=1;i<4;i++){
线装;
开关(一){
案例1:
“心”;
打破
案例2:
套装=“钻石”;
打破
案例3:
套装=“黑桃”;
打破
案例4:
西服=“俱乐部”;
打破
违约:
诉讼=”;
打破
}
对于(int j=1;j=c.getValue()){
返回true;
}否则{
返回false;
}
}
}

公共空甲板()

当您创建一个对象时,您调用的是构造函数(即使您没有编写构造函数),而不是方法。

谢谢!它正在运行。很遗憾,我找不到无法打印currentCard的原因(做了一些小改动)在您的卡片类字符串getName(){return name;}中添加一个getter,并在打印方法System.out.println(currentCard.getName())中调用它;
package CardGame;

import java.util.Scanner;
import java.util.*;

public class Game {


    private static int score;

    // currentCard : Card
    private static Card currentCard;
    // Next Card
    private Card nextCard;
    // Scanner
    private static Deck deck;

    private static Scanner sc = new Scanner(System.in);

    // Main

    public static void main(String[] args) {

        deck = new Deck();

        currentCard = deck.getNextCard();

        Game.gameTurn();
    }

    // get turn method
    public static void gameTurn() {
        // System.out.println(Deck.getCards().size());
        System.out.print("is your next card higher or lower than the next card?");
        System.out.print(sc);
        String answer = sc.nextLine();

        Card nextCard = deck.getNextCard();


        if (answer.equals("higher") && nextCard.isHigherOrEqual(currentCard)) {

            correct();
        } else if (answer.equals("lower") && !nextCard.isHigherOrEqual(currentCard)) {
            correct();
            // answer.equals("lower")&& !nextCard.isHigherOrEqual(currentCard)
        } else {
            gameOver();
        }
    }

    // correct method

    public static void correct() {
        Game.gameTurn();
        score = 0;
        score++;
    }

    // Game over Method

    public static void gameOver() {
        System.out.println("total score is " + score + "!");
    }
}

package CardGame;

import java.util.ArrayList;
import java.util.Collections;

public class Deck {

    // cards = Card = new ArrayList<>()
    private static ArrayList<Card> cards = new ArrayList<>();

    // Deck Method
    public void Deck() {

        for (int i = 1; i < 4; i++) {
            String suits;

            switch (i) {

            case 1:
                suits = "Hearts";
                break;

            case 2:
                suits = "Diamonds";
                break;

            case 3:
                suits = "Spades";
                break;

            case 4:
                suits = "Clubs";
                break;
            default:
                suits = "";
                break;
            }
            for (int j = 1; j <= 10; j++) {
                int value = j;
                String name = j + " of " + suits;
                Card c = new Card(suits, name, value);

                cards.add(c);

            }
            // add 1.3 tot 1.11

            Card jack = new Card(suits, "jack of " + suits, 11);

            cards.add(jack); // JACK

            Card queen = new Card(suits, "queen of " + suits, 12);

            cards.add(queen); // QUEEN

            Card king = new Card(suits, "king of " + suits, 13);

            cards.add(king); // KING

            Card ace = new Card(suits, "ace of " + suits, 14);

        }
        // 1.11 shuffle cards
        Collections.shuffle(cards);
    }

    // getNextCard() : Card

    public Card getNextCard() {

        Card nextCard = cards.remove(0);

        return nextCard;

    }

    // getCards() : ArrayList <card>
    public static ArrayList<Card> getCards() {

        return cards;
    }

}

package CardGame;

public class Card {

    // Suit String
    private String suit;

    // Name String
    private String name;
    // Value int
    private int value;

    // Card constructor
    public Card(String suit, String name, int value) {
        this.value = value;
        this.name = name;
        this.suit = suit;

    }

    public int getValue() {
        return value;
    }

    // toString Method
    public String toString() {
        if (value == 15);
        return "";
    }
    // isHigherorEqual Method

    public boolean isHigherOrEqual(Card c) {
        if (this.value >= c.getValue()) {
            return true;
        } else {
            return false;
        }
    }
}