Define a class MyNumber having one private int data member. Write a default constructor to initialize it to 0 and another constructor to initialize it to a value (Use this). Write methods isNegative, isPositive, isZero, isOdd, isEven. Create an object in main. Use command line arguments to pass a value to the object (Hint : convert string argument to integer) and perform the above tests. Provide javadoc comments for all constructors and methods and generate the html help file.

 Define a class MyNumber having one private int data member. Write a default constructor to initialize it to 0 and another constructor to initialize it to a value (Use this). Write methods isNegative, isPositive, isZero, isOdd, isEven. Create an object in main. Use command line arguments to pass a value to the object (Hint : convert string argument to integer) and perform the above tests. Provide javadoc comments for all constructors and methods and generate the html help file.


import java.io.*;

import java.util.*;

class number

{

int n;

number() //Default Constuctor

{

n=0;

 }

number(int n) //parametrised constuctor

{

this.n=n;

}

public void isPositive()

{if(n>0)

 System.out.println("Number is positive");

}

public void isNegative()

 {

 if(n<0)

 System.out.println("Number is Negative");

 }

public void isEven()

 {

 if(n%2==0)

 System.out.println("Number is even");

 }

public void isOdd()

 {

 if(n%2==1)

 System.out.println("Number is Odd");

 }

}

class mynumber

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int n;

System.out.println("Enter the number");

n=sc.nextInt();

number n2=new number();

number n1=new number(n);

n1.isPositive();

n1.isNegative();

n1.isEven();

n1.isOdd();

}

}

Post a Comment

0 Comments