You are on page 1of 7

NAME: MONALISA.

. ROY
CLASS: XI
SECTION: C
ROLL NUMBER:
SUBJECT: COMPUTER
. PROJECT
TOPIC:
JAVA
PROGRAMS
PROGRAM I:
A MYSTIC NUMBER IS A NUMBER IN WHICH THE
EVENTUAL SUM OF THE DIGITS IS EQUAL TO
THREE.
Example : 984 is a mystic number because
. 9 + 8+4 =21=2+1=3
DESIGN A CLASS TO INPUT A NUMBER AND FIND
WHETHER IT IS A MYSTIC NUMBER OR NOT.
INCLUDE THE FOLLOWING MEMBERS:
INSTANCE VARIABLES:
 int n
INSTANCE METHODS:
 public Mystic()-Default constructor to initialize n
to 0
 public void fillNum(int num) – to assign value to n
 public int sumOfDigits() – to find the sum of the
digits of the number
 public boolean isMystic() – to check whether the
number is mystic or not and display appropriate
message.
Write a main method the create an object and call the
above methods accordingly.

VARIABLE LISTING:
SCOPE : public class Mystic
VARIABLE VARIABLE PURPOSE
NAME TYPE
n int To store the inputted number

SCOPE: public void fillNum( )


VARIABLE VARIABLE PURPOSE
NAME TYPE
num int Formal parameter; to store the
value to be assigned to n

SCOPE: public int sumOfDigits( )


VARIABLE VARIABLE PURPOSE
NAME TYPE
copy int To store a copy of n on which
the operations would be carried
out
sum int To store the sum of the digits
SCOPE: public boolean isMystic( )
VARIABLE VARIABLE PURPOSE
NAME TYPE
flag boolean To store the result after
condition checking

SCOPE: public static void main (String [] args)


VARIABLE VARIABLE PURPOSE
NAME TYPE
obj Mystic Refers to class object; used to
call instance methods
scan Scanner Refers to Scanner object used
to take keyboard input
num int To store the number inputted
by the user

SOURCE CODE:
OUTPUT:

You might also like