-2

My code keeps getting 6 errors called "Cannot find symbol", I've gone over my code and cannot understand where this issue is coming from in the given locations

symbol:   method prtIntro()
  location: variable session of type Session
/tmp/H9bVKeD6Jn/Session.java:68: error: cannot find symbol
            session.setTurns();
                   ^
  symbol:   method setTurns()
  location: variable session of type Session
/tmp/H9bVKeD6Jn/Session.java:71: error: cannot find symbol
            for (int i = 0; i < session.getTurns(); i++) {
                                       ^
symbol:   method getTurns()
  location: variable session of type Session
/tmp/H9bVKeD6Jn/Session.java:75: error: cannot find symbol
                game.setPairBonus();
                    ^
  symbol:   method setPairBonus()
  location: variable game of type Game
/tmp/H9bVKeD6Jn/Session.java:76: error: cannot find symbol
                game.setSeven11Bonus();
                    ^
  symbol:   method setSeven11Bonus()
location: variable game of type Game
/tmp/H9bVKeD6Jn/Session.java:77: error: cannot find symbol
                game.setTotal();
                    ^
symbol:   method setTotal()
  location: variable game of type Game

I've attached my code below so if someone could explain how I can resolve these issues I would greatly appreciate it


import java.util.Random;
import java.util.Scanner;

// The Game class handles the game logic and calculations
class Game {
    private Random random = new Random();
    private int die1;
    private int die2;
    private int sum;
    private int pairBonus;
    private int seven11Bonus;
    private int total;

    public void setDice() {
        die1 = random.nextInt(6) + 1;
        die2 = random.nextInt(6) + 1;
        sum = die1 + die2;
    }

    public void sortDice() {
        if (die1 > die2) {
            int tempDie = die1;
            die1 = die2;
            die2 = tempDie;
        }
    }

    // Other getter and setter methods for various calculations
    // ...

    // More methods for setting and getting bonuses and totals
    // ...
}

// The Session class manages player information and interaction
class Session {
    private Scanner scan = new Scanner(System.in);
    private String name;
    private int turns;

    public void setName() {
        System.out.print("Enter your name: ");
        name = scan.nextLine();
    }

    // Other methods for getting player information and printing messages
    // ...

    public void prtOutro() {
        System.out.println("Thanks for playing, " + name + "! See you next time.");
    }
}

// The main Driver class runs the game
public class Driver {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Game game = new Game();
        Session session = new Session();
        String playAgain;

        // Get player name and display welcome message
        session.setName();
        session.prtIntro();

        do {
            // Get the number of turns from the player
            session.setTurns();

            // Loop through the specified number of turns
            for (int i = 0; i < session.getTurns(); i++) {
                // Set up the game for this turn
                game.setDice();
                game.sortDice();
                game.setPairBonus();
                game.setSeven11Bonus();
                game.setTotal();

                // Display the results of this turn
                System.out.println("\nRoll " + (i + 1) + ":");
                // Display other information using the game's getter methods
                // ...

            }

            // Ask if the player wants to play again
            System.out.print("\nDo you want to play again? (Y/N): ");
            playAgain = input.next();
        } while (playAgain.equalsIgnoreCase("Y"));

        // Display a goodbye message
        session.prtOutro();
    }
}

I attempted to change the formatting of the code and experimented with deleting certain elements yet each came with a progressively different issue

user207421
  • 305,947
  • 44
  • 307
  • 483
Star
  • 1
  • 2
    it is complaining that it can not find `session.setTurns();` and `session.getTurns();` and others. The `Session` class code that you posted above does not contain these methods. – Scary Wombat Aug 08 '23 at 23:59
  • 2
    Not really to your question, but setters *should* take a value to be set. Yours don't. – Elliott Frisch Aug 09 '23 at 00:01
  • I'm not clear on what you don't understand as you're calling methods that simply don't exist. You can't just make up stuff that *seems* OK and hope it works as programming is much too exacting a task to allow for that. Your question suggests that you're just now learning the most basic concepts of Java programming. Since this site is not geared to work in place of an introduction to programming website, and since it is best to get this information from tutorials, you will probably want to start there. – Hovercraft Full Of Eels Aug 09 '23 at 00:41
  • You can find links to great Java tutorials and other language resources in the [java info](https://stackoverflow.com/tags/java/info) section of the [tag:java] tag. Start here: [The Java™ Tutorials](https://docs.oracle.com/javase/tutorial/tutorialLearningPaths.html) – Hovercraft Full Of Eels Aug 09 '23 at 00:41

0 Answers0