Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

CSE1007 Java Programming – A1+TA1 Slot

Continuous Assessment Test (CAT) – I Answer Key

1. Write a Java program to get n numbers using Scanner class to store it in an array then find
the sum of diagonal numbers. If the sum of diagonal number value is even number then print
all even numbers from the array. [4+6 Marks] [CO1] [BL – L6]
Key:
import java.util.*;
Scanner class obj;
Obj.nextInt();
forming array
Sum=sum+array[i][i];
if(sum%2==0)
display all even number from array

Or
Write a Java program to get n numbers using command line arguments to store it in an array,
find and display the sum of each rows and each columns on the screen. [4+6 Marks] [CO1]
[BL – L6]
Command line arguments inputs, convert string to integer and forming array
Sum of rows
rsum=rsum+array[i][j];
show rsum
rsum=0 and repeat
Sum of columns
csum=csum+array[j][i];
show csum
csum=0 and repeat

2. Create a class Student with data members Name, Register_No and address. Create a class
Quiz1 which inherits from Student class and it contains Register_No and Quiz1_Mark. Create
a class QUIZ2 which inherits from Quiz1 class and it contains Register_No, Quiz2_Marks as
member and two member function called get() and put(). Write the appropriate code to
implement the above said code to get student details using get() and display the student
details using put() method through the Quiz2 class object. [2+3+5 Marks] [CO2] [BL – L6]
Answer:
class Student_Quiz
{
String Name,Register_No,address;
}
class Quiz1 extends Student_Quiz
{
String Register_No;
int Quiz1_Mark;
}
class QUIZ2 extends Quiz1
{
String Register_No;
int Quiz2_Mark;
void get(String n,String r,String a,int Q1,int Q2)
{
Name=n;
Register_No=r;
address=a;
Quiz1_Mark=Q1;
Quiz2_Mark=Q2;
}
void put()
{
System.out.println("Student Name is "+ Name);
System.out.println("Student Register_No "+Register_No);
System.out.println("Student Address is "+address);
System.out.println("Quiz1 Mark is "+Quiz1_Mark);
System.out.println("Quiz2 Mark is "+Quiz2_Mark);
}
public static void main(String args[])
{
QUIZ2 obj=new QUIZ2();
obj.get("kumar","19BCE0001","SJT413 A21",8,9);
obj.put();
}
}
Or
Create a class Student with data members Name, Student_Code and email. Create a class
Internals which inherits from Student class and it contains one member CAT_Mark and one
member function show_internal_mark() is used to show internal mark of the student. Create a
class a External which inherits from Internal class and it contains one member as
External_Mark and one member function as show_marks(), which is used to display internal
and external marks of the student. Write the appropriate code to implement the above said
code to display Student Name, Student_Code, email and student marks only with help of
constructor of External class.[2+3+5 Marks] [CO2] [BL – L6]
Answer:
class Student_CAT1
{
String Name,Student_code,email;
}
class Internals extends Student_CAT1
{
int CAT_Mark;
void show_internal_mark()
{
System.out.println("Internal CAT Mark is "+CAT_Mark);
}
}
class External extends Internals
{
int External_Mark;
External(String n,String c,String e,int internal,int external)
{
Name=n;
Student_code=c;
email=e;
CAT_Mark=internal;
External_Mark=external;
System.out.println("Student Name is "+ Name);
System.out.println("Student Code is "+Student_code);
System.out.println("Student Email is "+email);
show_mark();
}
void show_mark()
{
show_internal_mark();
System.out.println("External Mark is "+External_Mark);
}
public static void main(String args[])
{
External obj=new External("kumar","19BCE0001","kumar@gmail.com",30,50);
}
}

3. If there are errors in the below Java program, rectify it then write down the outputs
separated by new line. [3+7 Marks] [CO2] [BL – L1]
Note: No need to rewrite the complete code again, just write only error rectified code and
outputs.

Two Errors:
```````````````
address="Vellore " + '632000'; address="Vellore" + "632000"
int room_no=this.no+1; int room_no=no+1;

Output(Separated by new line):


``````````````````````````````````````
8
Vellore632000
Back Side
8
House no 8
Back Side
Room No 9
updated address is Vellore632000

Or
3 If there are errors in the below Java program, rectify it then write down the outputs
separated by new line. [2+8 Marks] [CO2] [BL – L1]
Note: No need to rewrite the complete code again, just write only error rectified code and
outputs.
Three Errors:
````````````````
int emp_id,int age;long emp_id; int age; //, and long
void employee(static int count) void employee(int count) //static
Output(Separated by new line):
``````````````````````````````````````
Four
Five
-5
One
Three
Two
1

You might also like