+ 1

error occurring solve it please.

can you correct this program and run it , i did much but always a error occurs .. only a single and tell what's the problem import java.util.Scanner; public class Program { public static void main(String[] args) { boolean yourTurn = true; System.out.println("As immediately as you wake up you are attacked by a rat! You get up and fight (1 to punch '1 stamina', 2 to kick '2 stamina', 3 to insult '0 stamina')"); Scanner sc =new Scanner (System.in); while(yourTurn == true) getInput(); } public class getInput(){ { String attack = "no attack"; public String input(){ int inp = sc.nextInt(); if(inp == 1){ attack = "punch"; } else if(inp == 2){ attack = "kick"; } else if(inp == 3){ attack = "insult"; } else{ System.out.println("Please enter a number between 1-3"); } } } public class Fight { public void punch(){ } } public class Rat { public int ratHealth(){ int health = 100; } } }

12th Sep 2016, 3:00 PM
Saransh Agarwal
Saransh Agarwal - avatar
3 Respuestas
+ 2
i think u shd inherit the rat and fight class
12th Sep 2016, 5:52 PM
Suhail Pappu
Suhail Pappu - avatar
0
instead of closing your main() at the beginning try closing it at the end. Because the program executes between open and closing braces{} of main. and instead of declaring your getinput() method as class type try it as void because your method doesn't has any return type so prefer void..
13th Sep 2016, 4:44 PM
Teja Naraharisetti
Teja Naraharisetti - avatar
0
actually there is no prblm with main(). I guess that error is due to return type
13th Sep 2016, 5:11 PM
Teja Naraharisetti
Teja Naraharisetti - avatar