First CIE QP and Scheme Java

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CIE-I Sub. Code: BCS306A Semester: 3rd Sem.

Sub:Object Oriented Programming with JAVA Marks: 25 Marks Date: 16-10-2024Max


Note: - Solve any ONE full Question from each PART
Q.No. Question Marks CO RBTL
PART-A
Q.1.a List and Explain the three OOP Principles. 04 1 2
b. Describe type conversion? Illustrate different ways of
04 1 2
type conversion with examples.
c. Write java code to initialize one dimensional array by 1
05 1 3
to 5 integers and print only even numbers on terminal.
OR
Q.2.a Discuss the Lexical Issues in Java. 04 1 2
b. Write differences between
04 1 2
a)while & do…while b) break & continue
c. Write Java code to find largest 3 integers reading from
05 1 3
users by using ternary operator.
PART-B
Q.3.a. Discuss classes and objects. Write the syntax for
04 2 2
declaring and initializing an object with examples.
b. Describe method overloading? Write overloaded
method area() to calculate area of circle and area of 04 2 3
rectangle.
c. Write Java program to define a class called Student
with the data members (USN, Name, Branch, Phone
04 2 3
Number) and write methods to read and display the
students details with appropriate messages.
OR
Q.4.a. Discuss the concept of static in Java. Write a program
that illustrates the use of static variables and methods 04 2 2
in a class.
b. Write a Java program to demonstrate the difference
between private and public access modifiers. Explain
04 2 3
how these modifiers affect the visibility of class
members.
c. Develop a stack class to hold a maximum of 10 integers
04 2 3
with suitable methods.
SCHEME OF EVALUATION-I
Subject: Object Oriented Programming with JAVA Sub. Code: BCS306A
rd
Semester: 3 Sem. Max Marks: 25 Marks
Note: - Solve any ONE full Question from each PART
Q.No. Question Marks
Q.1.a Three OOP Principles: Encapsulation, Inheritance & Polymorphism
04
List = 1 m, Explanation-3 m, Total=1+3=4 m
b. Implicit and Explicit type conversion
04
Definition of type conversion=1 m, Explanation of two types=3 m, Total=1 +3 = 4 m
c. Write java code to initialize one dimensional array by 1 to 10 integers and print only
even numbers on terminal.
public class HelloWorld {
public static void main(String[] args) {
int i;
int [] a = {1, 2,3,4,5,6,7,8,9,10};
System.out.println("Even Numbers"); 05
for (i=0;i<10;i++)
if(a[i]%2==0)
System.out.println(a[i]);
}
}
If, core code is correct= 3 m, If, entre source code is correct= 5 m
Q.2.a Lexical Issues in Java: white space identifiers, comments, literals, operators, separators,
and keywords 04
List = 1m, Explanation=3 m, Total = 1+3=4 m
b. Minimum 3 differences between
04
a)while & do…while = 2 m, b) break & continue = 2 m, Total= 2+ 2 = 4m
c. Write Java code to find largest 3 integers reading from users by using ternary operator.
import java.util.Scanner;
public class example
{
public static void main(String[] args)
{
int a, b, c, largest, temp; 05
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number:");
a = sc.nextInt();
System.out.println("Enter the second number:");
b = sc.nextInt();
System.out.println("Enter the third number:");
c = sc.nextInt();
temp=a>b?a:b;
largest=c>temp?c:temp; (
System.out.println("The largest number is: "+largest);
}
}

Or

public class LargestOfThree {


public static void main(String[] args) {
int a = 10;
int b = 20;
int c = 15;

// Using the conditional operator to find the largest


int largest = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);

System.out.println("The largest number is: " + largest);


}
}

If, core code is correct= 3 m, If, entre source code is correct= 5 m


Q.3.a. Definition & Syntax to define class and object=2m Examples=2m
Class Declaration in Java
Syntax:
access_modifier class <class_name>
{
data member;
method;
constructor; 04
nested class;
interface;
}
Defining objects in Java:
Syntax:
ClassName object = new ClassName();

b. Definition of method overloading= 1m,


// Java program to find the area of
// the circle and rectangle using Method Overloading
04
class Demo {
void Area(double r)
{
System.out.println("Area of the circle: "
+ 3.142*r*r);
}
void Area(double l, double b)
{
System.out.println("Area of the rectangle: "
+ l * b);
}
}
class exam {
public static void main(String[] args)
{
// Creating object of Demo class
Demo obj = new Demo();
// Calling function
obj.Area(2.5);
obj.Area(10.5, 5.5);
}
}
Writing overloaded method area() to calculate area of circle and area of
rectangle= 3 m, Total= 1+3 = 4 m

c. Write Java program to define a class called Student with the data members (USN, Name,
Branch, Phone Number) and write methods to read and display the students details with
appropriate messages.
class Student
{

String name,USN,branch,phoneno;
void insertData(String n, String u, String b, String p)
{
04
name = n;
USN=u;
branch=b;
phoneno=p;
}
void displayInformation()
{
System.out.println("Name "+name);
System.out.println("USN "+USN);
System.out.println("Branch "+branch);
System.out.println("Mobile Number "+phoneno);
}
}
class StudentInfo
{
public static void main(String args[])
{
Student s1 = new Student();
s1.insertData("John","2BL22CS100","cse","9797979797");
s1.displayInformation();
}
}
If, core code is correct= 2 m, If, entre source code is correct= 4 m
Q.4.a. static
Static variables are also known as class variables. These variables are declared similarly
to instance variables. The difference is that static variables are declared using the static
keyword within a class outside of any method, constructor, or block.
 Unlike instance variables, we can only have one copy of a static variable per class,
irrespective of how many objects we create.
 Static variables are created at the start of program execution and destroyed
automatically when execution ends.
this keyword in Java 04
The this keyword in Java is a reference variable that refers to the current object of a
method or a constructor. The main purpose of using this keyword in Java is to remove
the confusion between class attributes and parameters that have same names.
Explanation of static with examples=2 m, Explanation of this with
examples=2 m

b. List and explain the access specifiers in Java

04
c. Develop a stack class to hold a maximum of 10 integers with suitable methods.
class Stack {
int stck[] = new int[10];
int tos;
Stack() {
tos = -1;
}
void push(int item) {
if(tos==9)
System.out.println("Stack is full.");
else
stck[++tos] = item;
}
int pop() {
if(tos < 0) {
System.out.println("Stack underflow.");
04
return 0;
}
else
return stck[tos--];
}
}
class TestStack {
public static void main(String args[]) {
Stack mystack1 = new Stack();
for(int i=0; i<10; i++) mystack1.push(i);
System.out.println("Stack in mystack1:");
for(int i=0; i<10; i++)
System.out.println(mystack1.pop());
}
}
If, core code is correct= 2 m, If, entre source code is correct= 4 m

You might also like