Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Gaspar Santiago
Gaspar Santiago
3,377 Points

Java Web Development Project 1, program is running as the specs desire but I keep failing.

I am a Tech Degree student in the Java track and I'm working on project 1. I've completed the project. It runs as desired, and I've included everything the specs call for. Nevertheless, my results keep coming back as "Needs work".

The error I keep getting is a java.lang.AssertionError. I've looked this is up on Stack social and other resources but I can't find anything on how to overcome it.

Here are my errors in detail: 1 - java.lang.AssertionError: Did you increment the Random value you got by 1 Expected: a string containing "What type of item" but: was "ADMINISTRATOR SETUP ================= Name of items in jar: Maximum number of highlander in the jar: Your goal is to guess how many highlander are in the jar. Your guess should be between 1 and 1. Ready? (press ENTER to start guessing) Guess: "

2 - java.lang.AssertionError: Ensure your prompts match what was defined in the instructions Expected: a string containing "What type of item" but: was "ADMINISTRATOR SETUP ================= Name of items in jar: Maximum number of marbles in the jar: Your goal is to guess how many marbles are in the jar. Your guess should be between 1 and 100. Ready? (press ENTER to start guessing) Guess: Your guess is too low, try again! Your guess is too high, try again! "

These are the only two errors. I can't access Slack because I need to be invited by the team leader, whoever that is, to get help. I've already contacted customer support but have to wait to receive a response. I've exhausted most channels to this point and I'm just hoping someone from the community can help me.

You can find my project at: https://github.com/gsantiago1618/TreehouseProject1/tree/master/src/main/java

It's public and this is the only way to show what I did since it's not your typical Treehouse project that you can usually share on here.

Thank you to anyone who can help me with this.

1 Answer

Hello

The reason you project is failing build to a jar is because the test cases won't pass. I generally use Maven to Gradel to deal with dependencies. When I downloaded your project from Github, it was difficult to work with as the test cases dependencies were missing and there is no pom to add dependencies. I guess what I am trying to say, use Maven or Gradle to make you life easy and the project more manageable.

Also, your Prompter class needs a bit of work. It took me few minutes to understand what is it you trying to do ... but here is my shot at it.

import java.util.Scanner;

/**
 * Created by Gaspar Santiago on 1/17/2017.
 */

public class Prompter {
    Scanner input = new Scanner(System.in);
    String mTextInput;
    int mIntInput;

    public Prompter(String textInput, int intInput) {
        setTextInput(textInput);
        setIntInput(intInput);
    }

    public void setTextInput(String textInput) {
        // select item to put in jar
        System.out.println("ADMINISTRATOR SETUP\n =================");
        System.out.println("Name of items in jar: "); // Player enters name
        textInput = input.nextLine();
        mTextInput = textInput;
    }

    public void setIntInput(int intInput) {
        System.out.println("Maximum number of " + mTextInput + " in the jar: ");
        intInput = input.nextInt();// intInput gets assigned Admins entry
        mIntInput = intInput;
    }

    public String getTextInput() {
        return mTextInput;
    }

    public int getIntInput() {
        return mIntInput;
    }

    public int getPlayerInput() {
        // player begins guessing game
        System.out.println("Your goal is to guess how many " + Game.itemName + " are in the jar." +
                " Your guess should be between 1 and " + Game.maxNumberOfItems + ".");
        System.out.println("Ready? (press ENTER to start guessing)");
        System.out.println("Guess: ");
        int anInt = input.nextInt();
        int attempts = 1;

        while (anInt != Game.randomNumber) {
            if (anInt < 1) {
                System.out.println("You entered an invalid number, please try again.");
                anInt = input.nextInt();
                attempts++;
            } else if (anInt > Game.maxNumberOfItems) {
                System.out.println("Your guess must be less than " + Game.maxNumberOfItems);
                anInt = input.nextInt();
            } else if (anInt < Game.randomNumber) {
                System.out.println("Your guess is too low, try again!");
                anInt = input.nextInt();
                attempts++;
            } else if (anInt > Game.randomNumber) {
                System.out.println("Your guess is too high, try again!");
                anInt = input.nextInt();

            }
        }
        System.out.println("Congratulations - You guessed that there are " + Game.randomNumber + " "
                + Game.itemName + " in the jar! It took you " + attempts + " guess(es) to get it right");
        return anInt;
    }


}

the change to Prompter seems to work ok if you just run main... best as I can tell. But again, your project will fail to build to a jar, because the test cases are off.