Page 600 - ComputerScience_Class_11
P. 600

53           {

                54               Spiral_Matrix ob=new Spiral_Matrix();
                55               ob.spiralprint();
                56           }

                57       }

              The output of the preceding program is as follows:

                     BlueJ: Terminal Window - Java
                 Options

                Enter the number of elements :
                3
                The Spiral Matrix is:
                1 2 3
                8 9 4
                7 6 5



                Program 18     Define a  class Employee to input  the  details  of the  employee and  print  them. The data
                               members and member methods are defined as follows:
                               Data Members
                               int Id                 :  to store the employee ID
                               String Name            :  to store the employee name

                               long Salary            :  to store the employee salary
                               Member Methods
                               void getData()         :   to enter the details of the employee such as name, ID, age and
                                                         salary
                               void display()         :   to display the details of the employee
                               Specify the class Employee by giving details of the constructors and also write the main
                               function.

                 1       import java.util.*;
                 2           class Employee
                 3           {

                 4               int Id;
                 5               String Name;

                 6               int Age;
                 7               long Salary;
                 8

                 9       void getData() {
                10               Scanner sc = new Scanner(System.in);

                11               System.out.print("Enter Employee Id: ");




                  598  Touchpad Computer Science (Ver. 3.0)-XI
   595   596   597   598   599   600   601   602   603   604   605