You are on page 1of 15

I.C.

SE 2009 QUESTION PAPER

Q1)An electronics shop has announced the following seasonal discount on the purc
hase of certain items.
Purchase Amount in Rs Discount on Laptop
Discount on Desktop PC
0-25000 o.o%
5.0%
25001-57000 5.0%
7.5%
57001-100000 7.5%
10.0%
More than 100000 10.0%
15.0%
WAP based on the above criteria to input name,address amount of purchase and the
type of purchase(L for laptop and D for desktop) by a customer. Computand print
the net amount to be paid by a customer along with his name and address.

import java.io.*; //impoting and exporting

class electronic
{
public static void display(String args[]) throws IOException
{
double p,d,net;
System.out.println(" **********BILL PROGRAM**********");
System.out.println(" Enter Name of the Customer");
//inputing
//displaying
System.out.println("Enter Value of Purchase =");
p = Double.parseDouble(x);
//converting p to double type
System.out.println("Name of the Customer::"+name);
System.out.println("L.Enter L for Laptop");
//displaying
System.out.println("D.Enter D for Desktop");
//displaying
System.out.println();
char choice;
//inputing string choice
System.out.println("Name of the Customer::"+name);
switch(choice)
{
case 'L':
if(p<=25000) //giving the condition
{
d=0;
net = p-d;
System.out.println("Amount to be paid="+net); // i
f the condition is true it will display this
}
else
if(p>25000&&p<=57000)
{
d=(5.0/100)*p;
net=p-d;
System.out.println("Amount to be paid="+net);
}
else
if(p>57000&&p<=100000)
{
d=(7.5/100)*p;
net=p-d;
System.out.println("Amount to be paid="+net);
}
else
if(p>100000)
{
d=(10.0/100)*p; //method
net=p-d;
System.out.println("Amount to be paid="+net);
}
break; //if the above condion is
true then the break statement will not let the rest of the program to execute
case'D':
if(p<=25000)
{
d=(5.0/100)*p;
net=p-d;
System.out.println("Amount to be paid="+net);
}
else
if(p>25000&&p<=57000)
{
d=(7.5/100)*p;
net=p-d;
System.out.println("Amount to be paid="+net);
}
else
if(p>57000&&p<=100000)
{
d=(10.0/100)*p;
net=p-d;
System.out.println("Amount to be paid="+net);
}
else
if(p>100000)
{
d=(15.0/100)*p;
net=p-d;
System.out.println("Amount to be paid="+net);
}
break;
}
}
}

Q2)WAP to generate a triangle or an inverted triangle till n terms based upon th

e user's choice of triangle to be displayed

import java.io.*;
class triangle
{
public static void display(String args[]) throws IOException
{
int n; //initializing n
System.out.println("Enter Value of n =");
//inputing String s
n = Integer.parseInt(v);
//converting v to integer type
System.out.println(" M E N U ");
//displaying
System.out.println("1 for Triangle");
System.out.println("2 for Inverted Triangle");
System.out.println();
//inputing string x
int ch = Integer.parseInt(x);/
/converting x into integer type
switch(ch) //running switch case
{
case 1:
int i,j;
//initializing i and j
for(i=1;i<=n;i++)
//running the for loop n number of times
{
for(j=1;j<=i;j++)
System.out.print(i);
//displaying i
System.out.println(" ");
}
break;
case 2:
for(i=n;i>=1;i--)
//running the for loop n number of times
{
for(j=i;j>=1;j--);
System.out.print(+i);
System.out.println(" ");
}
break;
default: //if the user does not give the above
condition then it will pass to default option and will print invalid option
System.out.println("INVALID OPTION");
}
}
}

Q3)WAP to input a sentence and print the number of characters found in the longe
st word of the given sentence.

class LongestWord
{
public void WordSize(String str) //accepting string str
{
char ch; //initializing char ch
str =str+" ";
int len = 0;
int x=str.length(); //calculating the length of th
e sentence
System.out.println("Enter the sentence::" +str);
System.out.println("\n");
for(int i=0;i<x;i++)
{
ch=str.charAt(i); //counting the number of ch
aracter
if(ch != ' ')
{
System.out.println(ch); //displaying ch
len=len+1;
}
if(ch==' ')
{
System.out.println(" : The Size is" +len + " characters")
;
len=0;
System.out.println("\n");
}
}
}
}

Q7) Design a class to overload a function num_calc () as follows

import java.io.*;
{
{
System.out.println(" M E N U ");
System.out.println("s. Square of Integer");
System.out.println("p. Product of integers");
System.out.println("e. Equality of Strings");
System.out.println();
}
public void num_calc(int num,char ch) // declaring the
function
{
System.out.println("Choice=" +ch);
System.out.println("Number+" +num); //displaying
int square = num*num; //finding the squar
e
int cube = num*num*num; // finding the cube
if(ch=='s')
System.out.println("Square of the Number is =" +square);
else
System.out.println("Cube of the Number is =" +cube);
}
public void num_calc (int a , int b , char ch) //calling anot
her function
{
System.out.println("Choice=" +ch);
System.out.println("Number1=" +a);
System.out.println("Number2=" +b);
int product = a*b; //
finding the product
int sum = a+b; //
finding the sum
if(ch=='p')
System.out.println("Product of the Number is =" +product);
//displaying the result
System.out.println("Sum of the Number is =" +sum);
}
public void num_calc(String s1,String s2)
{
System.out.println("First String:" +s1);
System.out.println("Second String:" +s2);
if(s1.equals(s2))
//cheking whether the two strings are equal or not
System.out.println("Strings are equal");
else
System.out.println("Strings are not equal");
}
}

Q4a) WAP a menu to check whether it is a buzz number .

import java.io.*;
class BUZZ
{
public static void main(String args[])throws IOException
{
System.out.println(" M E N U ");
System.out.println(" ");
int n, number; //initializing n and number
//inputing
System.out.print("Enter Vlue of number =");
//inputing string x
n = Integer.parseInt(x);
//converting x into integer type
if(n%7 ==0)
//method
System.out.println("The number is BUZZ number");
//displaying
else
if (n/10==7)
System.out.println("The number is BUZZ number");
else
System.out.println("The number is NOT A BUZZ number");
}
}
Q4b)WAP to accept 2 number and print the GCD of them

import java.io.*;
class GCD
{
public static void main(String atrs[]) throws IOException
{
System.out.println(" M E N U ");
System.out.println(" ");
int a,b;
// initializ
ing a and b
System.out.println("NOTE::a nad b are two numbers. a is greater
than b");
System.out.print("Enter Value of a =");
// Inputing string x
a = Integer.parseInt(x);
//converting x into
integer type
System.out.print("Enter Value of b =");
// Inputing string y
b = Integer.parseInt(y);
//converting y into inte
ger type
System.out.println("First Number=" +a);
System.out.println("Second Number=" +b);
int dd, div;
// initializing dd and div
if(a>b)
{
dd=a; //method
div=b;
}
else
{
dd=b;
div=a;
}
int temp=1; //initializing tem
p
while(temp !=0);
temp =dd%div;
if(temp==0)
{
System.out.println("GCD is=" +div); //display
ing
}
else
{
dd=div;
div = temp;
}
}
}

Q5) The annual examination results of 50 students in a class is tabulated as f

ollows:
Roll no. Subject A Subject B
Subject C
WAP to read the data, calculte and display the following:
a)Average mark obtained by each student.
b) Print the roll number and average marks of the students whose average mark is
above 80.
c)Print the roll number and average marks of the students whose average mark is
below 40

import java.io.*;
class Result
{
public static void main (String args[]) throws IOException
{
int roll[] = new int [50;
//int roll can store 50 values
int sub1[] = new int [50];
//int sub 1 can store 50value
int sub2[] = new int[50];
//int sub 2 can store 50value
int sub3[] = new int[50];
//int sub 3can store 50value
int total[] = new int [50];
//int total can store 50value
double average[]=new double[50];
for(int i=0;i<=4;i++)
{
System.out.println("Enter Roll No. of the student");
//inputing rn
roll[i]=Integer.parseInt(rn);
//converting rn to integer type
System.out.println("Enter Marks in Subject A");
//inputing a
sub1[i]=Integer.parseInt(a);
//converting a to integer type
System.out.println("Enter Marks in Subject B");
//inputing b
sub2[i]=Integer.parseInt(b);
//converting b to integer type
System.out.println("Enter Marks in Subject C");
//inputing c
sub3[i]=Integer.parseInt(c); //
converting c to integer type
total[i]= sub1[i]+ sub2[i]+sub3[i];
average[i]=(double)total[i]/3;
// finding the average
}
System.out.println(" R E S U L T ");
System.out.println("Roll No. Subject A Subject B Subject C A
verage");
System.out.println("----- --------- ------- --------- -
------");
for(int k=0;k<=4;k++)
{
int n;
n=k+1;
System.out.println(n +" "+sub1[k]+" "+sub2[k]+" "+su
b3[k]+" "+average[k]);
}
int max=total[0];
int high1=sub1[0];
int high2=sub2[0];
int high3=sub3[0];
int r=0;
int roll1=0,roll2=0,roll3=0;
for(int i=1;i<=4;i++)
{
if(total[i]>max)
{
max=total[i]; // method
r=roll[i];
}
if(sub1[i]>high1)
{
high1=sub1[i];
roll1=roll[i];
}
if(sub2[i]>high1)
{
high2=sub2[i];
roll2=roll[i];
}
if(sub3[i]>high1)
{
high3=sub3[i];
roll3=roll[i];
}
}
System.out.println("Total Highest Marks are="+max+ "obtained by
roll number"+r);
System.out.println("Highest Marks in Subject A are="+high1+"obt
ained by roll number"+roll1); // displaying the result
System.out.println("Highest Marks in Subject B are="+high2+"obt
ained by roll number"+roll2);
System.out.println("Highest Marks in Subject C are="+high1+"obt
ained by roll number"+roll3);
}
}

BOOK QUESTION
QI) Define a class called NumberProblems, which has the following functions
Int sumOfFactors(int n)-which returns sum of all the factors of the numb
er n except itself.
boolean isPerfect(int n)- which returns true if n is perfect and false oth
erwise.
void perfect Nos Below(int lim)-which first prints out all perfect numbers les
s than lim.Each perfect number should be printed on a single line along with its
factors. So for example the output from perfect Nos Below(10): 6=(1,2,3)

class NumberProblems
{
int sumOfFactors(int n) //calling function
{
int s=0,i; //intializing the variables
for(i=1; i<=n/2 ; i++) //running the for loop
{
if(n%1==0) //cheking wether it gives 0 as remainder
{
s=s+i;
}
}
return s; //returning the value
}
boolean isPerfect(int n) //declaring another function under the s
ame class
{
int f;
f=sumOfFactors(n); //calling the previous function
if(f==n) //cheking weth
er f is equal to n
{
return true; // if f=n it will return t
rue
}
else
{
return false; //if f is not equal to
n then it will return false
}
}
void perfectNosBelow (int lim) //declaring another function unde
r the same class
{
for(int i=1;i<=lim;i++)
{
if( isPerfect(i)) //calling the previ
ous function
{
System.out.print(i); //displaying i
}
}
}
void display(int n)
{
System.out.print( n+"=(" );
for(int i=1;i<=n/2;i++)
{
if(n%i==0)
System.out.print(i +",");
}
System.out.print(")");
}
}

Q2 Define a class RecurringPatterns and define methods in it,which will print t

hefollowing patterns.
a)
class RecurringPatterns
{
public void display(int n)
{
int i,j; //initializing i and j
for(i=1;i<=n;i++) //running the for loo
p n times
{
for(j=1;j<=n-i;j++)
{
System.out.print(" "); //for blank space
}
for(j=1;j<=i;j++)
{
System.out.print("a" +" "); //displayi
ng
}
System.out.println(" "); //for blank space
}
for(i=1;i<=n-1;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(" ");
}
for(j=1;j<=n-i;j++)
{
System.out.print("a" +" ");
}
System.out.println(" ");
}
}
}

b)
class RecurringPatterns {
public void display(int n){
int i,j;
for(i=1;i<=n;i++) { //RUNNING THE FOR LOOP
for(j=1;j<=n-i;j++) {
System.out.print(" "); //DISPLAYING SPACE
}
for(j=1;j<=i;j++) {
System.out.print(j); //NESDTED LOOPING
}
for(j=i-1;j>=1;j--) {
System.out.print(j);
}
System.out.println();
}
for(i=n-1;i>=1;i--) {
for(j=1;j<=n-i;j++){
System.out.print(" "); }//DISPLAYING THE SPACE
for(j=1;j<=i;j++) {
System.out.print(j); }
for(j=i-1;j>=1;j--){
System.out.print(j); }
System.out.println();
}
}
}

c)

class RecurringPatterns{
void pats1(int n){
int i,j,k,l,m; //INITIALIZING j,k,lm
i=j=k=l=m=0;char ch='a';
for(i=0;i<n;i++){
for(j=1;j<=n-i;j++){ //running the for loop
System.out.print(ch++); //displayin ch++
}
for(k=1;k<=2*i;k++){
System.out.print(" ");
}
for(l=j-1;l>=1;l--){
System.out.print(--ch);
}
System.out.println("");
}
for(i=1;i<n;i++){
ch='a';
for(j=0;j<=i;j++){
System.out.print(ch);ch++;
}
for(k=2;k<((2*n)-(2*i));k++){ //running the for l
oop
System.out.print(" ");
}
for(l=j;l>=1;l--){
System.out.print(--ch);
}
System.out.println("");
}
}
}

Q3)Define a class NumberProblems with suitable methods which takes an integer ar

gument and prints out all the twin primes below

import java.io.*; //importing

class NumberProblems
{
boolean isprime(int n) //accepting n
{
int i,s=0; //initializing i and s
for(i=2;i<=n/2;i++) //running the for loop
{
if(n%i==0) //cheking wether the remainder is 0
s++;
}
if(s==1)
return false; //if s=1 then it will return false
else
return true; //if s is not equal1 then it will retur
n true
}
public void main()throws IOException
{
int n;String a;int i;
n=Integer.parseInt(a);
for(i=1;i<=n;i++)
{
if(isprime(i)&&isprime(i+2)) //calling the previous funct
ion
{
System.out.print(i+ i+2); //displaying twin prim
no
}
}
}
}