NAME-Megha Saxena Registration Number - 20BIT0366 Java Programming Lab - 33+34 Assignment 3
NAME-Megha Saxena Registration Number - 20BIT0366 Java Programming Lab - 33+34 Assignment 3
a. MathProcess
ii. Design a method isProductPerfectNumber which returns Boolean. It verifies the member is a
product perfect number or not. A number is a product perfect number if the product of all its
divisors, other than the number itself, is equal to the number. For example, 10 and 21 are product
perfect numbers since 1*2*5 = 10 and 1*3*7 = 21. Finally returns the result.
iii. Design another method to find the factorial of the member and returns the factorial value.
b. StatProcess
i. Contains an array of integers and its size n as members. Create a constructor to initiate the size
of array. Design a method getInput which gets ‘n’ integer numbers. Design another method
findMean which finds mean value of the array and return it.
Design the test class which imports this package and demonstrate these classes and their
methods through few objects.
CODE:
package CSE1007;
public class MathProcess {
int member1;
public void member(){
member1=10;
}
static boolean isPerfect(int n)
{
// To store sum of divisors
int sum = 1;
return false;
}
// Driver program
{
System.out.println("Below are all perfect" +
"numbers till 10000");
for (int n = 2; n < 10000; n++)
if (isPerfect(n))
System.out.println( n +
" is a perfect number");
}
static int factorial(int n)
{
if (n == 0)
return 1;
// Driver method
public static void main(String[] args)
{
int num = 5;
System.out.println("Factorial of " + num
+ " is " + factorial(5));
}
}
package CSE1007;
import java.util.Scanner;
public class JStatProcess {
2. Write a program in Java to raise exception for data validation and typo error.
a. Read the Register Number and Mobile Number of a student. If the Register Number does not
contain exactly 9 characters or if the Mobile Number does not contain exactly 10 characters,
throw an IllegalArgumentException.
b. If the Mobile Number contains any character other than a digit, raise a
NumberFormatException. c. If the Register Number contains any character other than digits and
alphabets, throw a NoSuchEl Get the input and print it if no error in the input. Otherwise raise the
corresponding error
CODE:
import java.io.*;
public class error{
public static void main(String args[]){
try{
int registrationnumber[]=new int[9];
int mobilenumber[]= new int[10] ;
if(registrationnumber.length<9 )
{
System.out.println("no error");
}
if(mobilenumber.length<10)
{
System.out.println("no error");
}
}catch(IllegalArgumentException e)
{
System.out.println("Error throw:" +e);
}
try{
if(registrationnumber != [a-z,A-Z])
{
System.out.println("no error");
}catch(NoSuchElementException e1)
{
System.out.println("Error throw:" +e1);
}
}
}
}
OUTPUT: