Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why my code is not taking input user and throw compile time error?

+2 votes
asked Jul 7, 2021 by Satish Gupta (140 points)
class Employee {

   

    void employeeProfession(){

       Scanner sc = new Scanner(System.in);

         System.out.println("Profession is:");

         String str = sc.nextLine();

    }

}

class Salary extends Employee{

    void salaryPerMonth(){

        //Scanner sc = new Scanner(System.in);

        System.out.println("salary is:");

        //int s = sc.nextInt();

    }

    

}

class Behaviour extends Employee{

    void behaviourOfEmploye(){

       // Scanner sc = new Scanner(System.in);

       // int point = sc.nextInt();

       int point = 8;

        

        if(point <= 3)

        System.out.println("Bad");

        else if(point >3 && point <=6)

        System.out.println("Avg");

        else

        System.out.println("Good");

        

    }

}

public class Main

{

public static void main(String[] args) {

Behaviour b = new Behaviour();

b.behaviourOfEmploye();

b.employeeProfession();

}

}

1 Answer

0 votes
answered Oct 31, 2021 by Peter Minarik (86,180 points)

You need to import the Scanner class:

import java.util.Scanner;
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...