Page 242 - Cs_withBlue_J_C11_Flipbook
P. 242
43 Scanner sc= new Scanner(System.in);
44 String n;
45 double bsal;
46 System.out.println("Enter name and basic salary ");
47 n=sc.nextLine();
48 bsal=sc.nextDouble();
49 Employee ob= new Employee(n,bsal);
50 ob.calculate();
51 ob.display();
52 }
53 }
The output of the preceding program is as follows:
Enter name and basic salary
Amar Dey
40000
Name : Amar Dey
Basic salary : 40000.0
HRA : 4000.0
DA : 22000.0
PF : 3332.0
Gross : 66000.0
Net salary : 62668.0
Program 2 Define a class Armstrong with the following specifications:
Data Members
int n : number to be checked
Member Methods
Armstrong() : Constructor to initialise values
void input() : Inputs a number
boolean check_armstronmg() : Checks and returns true if n is an Armstrong number
void display() : Calls check_armstrong() and prints Armstrong number or not
1 import java.util.*;
2 class armstrong
3 {
4 int n;
5 armstrong()
6 {
7 n=0;
240240 Touchpad Computer Science-XI

