online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
import java.util.Scanner; public class Main { public static void main(String [] args) { Scanner input = new Scanner(System.in); String petCare; System.out.println("Before we start the game"); //entering animalType; basics cat or dog System.out.println("What kind of pet are you going to take care of? "); System.out.println("Enter Dog to take care a pet dog" ); System.out.println("Enter Cat to take care a pet cat"); System.out.print("Choice: "); petCare = input.nextLine(); System.out.println(); System.out.println(); System.out.println(); //geting the name animalbreedtype and its age //dog case if(petCare.equalsIgnoreCase("dog")) { String name; String animalType; int age; System.out.print("Enter the name of the dog: "); name = input.nextLine(); System.out.print("Enter what type of dog is " + name+ ": "); animalType = input.nextLine(); Pet dog = new Pet(name, animalType); System.out.println(dog); //game loops starts System.out.println(); Petstats action = new Petstats(name); //class track && class for activties int lives=0; int choice; do { System.out.println("Welcome to Pets!"); System.out.println("!>Pet Care Game<!"); System.out.println("Day" +lives); System.out.println("Pick what do you wanna do to your pet?"); System.out.println("1. Check your Dog"); System.out.println("2. Activities with your Dog"); System.out.print("Choice >"); choice = input.nextInt(); switch(choice) { case 1: action.menu(); break; case 2: action.activity(); break; } lives++; action.consume(); System.out.println(); } while(lives < 4380 && action.lost()==false); //did a researched about average dog lifespan } // cat case else if(petCare.equalsIgnoreCase("cat")) { String name; String animalType; int age; System.out.print("Enter a name of your cat: "); name = input.nextLine(); System.out.print("Enter what cat type is " + name+ ": "); animalType = input.nextLine(); Pet cat = new Pet(name, animalType); System.out.println(cat); System.out.println(); System.out.println(); Petstats action = new Petstats(name); //class track && class for activties int lives=0; int choice; do { System.out.println("Welcome to Pets!"); System.out.println("!>Pet Care Game<!"); System.out.println("Day" +lives); System.out.println("Pick what do you wanna do to your pet?"); System.out.println("1. Check your Cat"); System.out.println("2. Activities with your Cat"); System.out.print("Choice >"); choice = input.nextInt(); switch(choice) { case 1: action.menu(); break; case 2: action.activity(); break; } lives++; action.consume(); System.out.println(); } while(lives < 4380 && action.lost()==false); //did a researched about average Cat lifespan } } }
/** * This class sets the: * name * age * type */ public class Pet { private String name; private String animalType; public Pet(String n, String at) { name = n; animalType = at; } public String getName() //specifics { return name; } public String getAnimalType() //specifics { return animalType; } public String toString() { String display; display = name + " is a "+ animalType; return display; } }
// import java.util.Scanner; public class Petstats { private String name; private Animal checkoract; private Game humanvsanimal; public Petstats(String a) { name = a; checkoract = new Animal(); humanvsanimal = new Game(); // 2 Game choices } public void menu() { Scanner input = new Scanner(System.in); int choice; System.out.println("What do you wanna check about your animal"); System.out.println("1. Tiredness"); System.out.println("2. Hunger"); System.out.println("3. Happiness"); System.out.println("4. Health"); System.out.println("5. Clealiness"); System.out.println("6. Poop?"); System.out.println("7. Money"); System.out.println("8. Inventory"); System.out.print("Choice >"); choice = input.nextInt(); System.out.println(); switch(choice) { case 1: System.out.println(name + "'s tiredness is %" + checkoract.getTired()); break; case 2: System.out.println(name + "'s Hunger is %" + checkoract.getHunger()); break; case 3: System.out.println(name + "'s Happiness is %" + checkoract.getHappy()); break; case 4: System.out.println(name + "'s Health is %" + checkoract.getHealth()); break; case 5: System.out.println(name + "'s Cleanliness is %" + checkoract.getClean()); break; case 6: System.out.println(name + "'s Poop level is %" + checkoract.getPoop()); break; // case 7: // System.out.println(name + "'s Money is $" + check.getMoney()); // break; //case 8: // System.out.println(check.getInv()); // break; } } public void activity() { Scanner input = new Scanner(System.in); int choice; System.out.println("What activities do you wanna do with you animal? "); System.out.println("1.Feed"); System.out.println("2.Sleep"); System.out.println("3.Take Medicine"); System.out.println("4.Play a game"); //minigame based System.out.println("5.Clean"); System.out.println("6.Poop"); System.out.println("7.Talk to"); System.out.println("8.Go to mall"); System.out.print("Choice >"); choice = input.nextInt(); switch(choice) { case 1: checkoract.tiredness(); System.out.println(); break; case 2: checkoract.hungry(); System.out.println(); break; case 3: checkoract.healthy(); System.out.println(); break; case 4: humanvsanimal.sendPlayerToTTT(); System.out.println(); break; case 5: checkoract.cleanliness(); System.out.println(); break; case 6: checkoract.happiness(); System.out.println(); break; case 7: checkoract.poop(); System.out.println(); break; case 8: checkoract.happiness(); System.out.println(); break; } } public void consume() { checkoract.getAllStats(); } public boolean lost() { // detects if the pet's health went to 0; if(checkoract.getHealth()<=0) { System.out.println("Your pet died!"); return true; } return false; } }
//gets the public class Animal { private int tired; private int hunger; private int happy; private int health; private int clean; private int poo; //private double money; //in order to get money you must win the minigame //private String inv; public Animal () { //all goes 100 tired = (int) (Math.random () * 21) + 40; hunger = (int) (Math.random () * 21) + 40; happy = (int) (Math.random () * 21) + 40; health = (int) (Math.random () * 21) + 40; clean = (int) (Math.random () * 21) + 40; poo = (int) (Math.random () * 21) + 40; //money = (int)(Math.random()*21)+40; //String inv= ""; } //setting value for each //if stats are >=50 they are OK if <= they need something public void tiredness () { if (tired >= 50) { tired += (Math.random () * 10) + 1; health += (Math.random () * 10) + 1; } else { tired += (Math.random () * 5) + 1; } if (tired < 10) { System.out.println ("Your pet is too exhaused! It needs some rest"); } System.out.println (); } public void hungry () { if (hunger >= 50) { hunger += (Math.random () * 10) + 1; health += (Math.random () * 10) + 1; } else { hunger += (Math.random () * 5) + 1; } if (hunger < 30) { System.out.println ("Your animals is hungry! You must feed it."); } System.out.println (); } public void happiness () { if (happy >= 50) { health += (Math.random () * 10) + 1; happy += (Math.random () * 5) + 1; } else { happy += (Math.random () * 5) + 1; } if (happy < 30) { System.out.println ("Your animal needs attention!"); } System.out.println (); } public void healthy () { if (health >= 50) { health += (Math.random () * 10) + 1; } else { health += (Math.random () * 5) + 1; } if (health < 30) { System.out.println ("Your animal needs medication!"); } System.out.println (); } public void cleanliness () { if (clean >= 50) { clean += (Math.random () * 10) + 1; health += (Math.random () * 10) + 1; } else { clean += (Math.random () * 5) + 1; } if (clean < 30) { System.out.println ("Your animal is smelly!"); } System.out.println (); } public void poop () { if (poo <= 50) { poo += (Math.random () * 10) + 1; } else { poo += (Math.random () * 5) + 1; } if (poo > 50) { System.out.println("Your animal is calling the nature! please get her out"); } System.out.println (); } public int getTired () { return tired; } public int getHunger () { return hunger; } public int getHappy () { return happy; } public int getHealth () { return health; } public int getClean () { return clean; } public int getPoop () { return poo; } public void getAllStats () { tired -= (Math.random () * 5) + 1; hunger -= (Math.random () * 5) + 1; happy -= (Math.random () * 5) + 1; health -= (Math.random () * 5) + 1; clean -= (Math.random () * 5) + 1; poo -= (Math.random () * 5) + 1; } }
import java.util.Scanner; //starts the game for TTT public class Game { private TTT tictactoe; public Game() { tictactoe = new TTT(); } public void sendPlayerToTTT() { Scanner input = new Scanner(System.in); System.out.println("Welcome to Tic Tac Toe"); tictactoe.initializeBoard(); do { System.out.println("Current board layout:"); tictactoe.printBoard(); int row; int col; do { System.out.println("Player " + tictactoe.getCurrentPlayerMark() + ", enter an empty row and column to place your piece!"); System.out.print("Enter your row: "); row = input.nextInt()-1; System.out.print("Enter the column to put your piece: "); col = input.nextInt()-1; } while(!tictactoe.placeMark(row,col)); tictactoe.changePlayer(); }while(!tictactoe.checkForWin() && !tictactoe.isBoardFull()); if(tictactoe.isBoardFull() && !tictactoe.checkForWin()) { System.out.println("The game was tied!"); } else { System.out.println("Current board layout:"); tictactoe.printBoard(); tictactoe.changePlayer(); System.out.println(tictactoe.getCurrentPlayerMark() + " Wins!"); } } }
import java.util.Scanner; public class TTT { private char[][] board; private char currentPlayerMark; public TTT() { board = new char[3][3]; currentPlayerMark = 'x'; initializeBoard(); } public void initializeBoard() { //This method will be sets the board to an empty board; //This loops throught rows for (int i = 0; i<3; i++) { //loop for columns for(int j = 0; j<3; j++) { board[i][j]='-'; } } } public void printBoard() { System.out.println("-------------"); for(int i = 0; i<3; i++) { System.out.print("| "); for(int j = 0; j<3; j++) { System.out.print(board[i][j] + " | "); } System.out.println(); System.out.println("-------------"); } } public boolean isBoardFull() { for(int i = 0; i<3; i++) { for(int j = 0; j<3; j++) { if(board[i][j]=='-') { return false; } } } return true; } public boolean checkForWin() { return (checkRowsForWin() || checkColumnsForWin() || checkDiagonalsForWin()); } private boolean checkRowsForWin() { for(int i = 0; i<3; i++) { if(checkRowCol(board[i][0], board[i][1], board[i][2])==true); { return true; } } return false; } private boolean checkColumnsForWin() { for(int i = 0; i<3; i++) { if(checkRowCol(board[0][i], board[1][i], board[2][i])==true); { return true; } } return false; } private boolean checkDiagonalsForWin() { for(int i = 0; i<3; i++) { if(checkRowCol(board[0][0], board[1][1], board[2][2])==true); { return true; } } return false; } private boolean checkRowCol(char c1, char c2, char c3) { return (c1 != '-' && c1 == c2 && c2==c3); } public void changePlayer() { if(currentPlayerMark == 'x') { currentPlayerMark = 'o'; } else { //default player piece currentPlayerMark = 'x'; } } public boolean placeMark(int row, int col) { if(row>=0 && row <3) { if(col>=0 && col<3) { if(board[row][col]=='-') { board[row][col]=currentPlayerMark; return true; } } } return false; } public char getCurrentPlayerMark() { return currentPlayerMark; } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue