0% found this document useful (0 votes)
49 views9 pages

COMP421star Lab Report 2

The document is a lab report for a computer programming course. It includes 5 programming assignments on topics like string arrays, object-oriented concepts, and exception handling. For each assignment, the student is asked to provide the code, output, and an explanation. The report also lists the course code, title, student name and ID, and has sections for the preparer, reviewer, verifier and approver to sign.

Uploaded by

hamza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views9 pages

COMP421star Lab Report 2

The document is a lab report for a computer programming course. It includes 5 programming assignments on topics like string arrays, object-oriented concepts, and exception handling. For each assignment, the student is asked to provide the code, output, and an explanation. The report also lists the course code, title, student name and ID, and has sections for the preparer, reviewer, verifier and approver to sign.

Uploaded by

hamza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES

Week No: 4, Period: Test 1 / Test 2  / Final,


Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

METHODS, CLASSES, OBJECT AND CONSTRUCTORS


TOPIC
ASSIGNMENT Q1.Develop a java program to create a string array and print the strings stored in that array.
(5 marks)
DIRECTION &
REQUIREMEN Q2. Use object oriented concept to create an array of 5 objects and write the program how these
T/S object access a single method. (5 marks)
(Identify the
ILOs to be Q3. Formulate a procedure to call various methods on strings. (5 marks)
assessed at the
end of each Q4. Choose an exception handling mechanism for handling divide by zero error and develop the
requirement. complete program. (5 marks)
Include the
rubric or marking Q5. Create a java program to perform addition of two strings. (5 marks)
scheme for each
item/requirement
.)

ASSIGNMENT
OUTPUT Q1:

SOLUTION-
I have solve the problem in python code with comments and screenshot for
easy understanding :)
1)
CODE-
//simple method declaration and return
public class Main
{
public static int min (int a, int b)
{
if (a <= b)
return a;
else
return b;
}
   public static void main(String[] args) {
       System.out.println( Math.min(3,5) );
   }
}

Prepared by : Reviewed / Checked by: Verified by: Approved by:


1

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :
COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES
Week No: 4, Period: Test 1 / Test 2  / Final,
Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

OUTPUT-

OUTPUT-

Prepared by : Reviewed / Checked by: Verified by: Approved by:


2

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :
COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES
Week No: 4, Period: Test 1 / Test 2  / Final,
Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

2)
CODE-
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
  
//get 5 number
System.out.print("Input the first number: ");
double x = in.nextDouble();
System.out.print("Input the second number: ");
double y = in.nextDouble();
System.out.print("Input the third number: ");
double z = in.nextDouble();
System.out.print("The average value is " + average(x, y, z)+"\n" );
}
//function with parameterized method
public static double average(double x, double y, double z)
{
return (x + y + z) / 5;
}
}

OUTPUT-

Prepared by : Reviewed / Checked by: Verified by: Approved by:


3

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :
COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES
Week No: 4, Period: Test 1 / Test 2  / Final,
Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

Prepared by : Reviewed / Checked by: Verified by: Approved by:


4

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :
COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES
Week No: 4, Period: Test 1 / Test 2  / Final,
Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

3-

ass Main{
   public static void main(String args[]){
     //create array of employee object 
     Employee[] obj = new Employee[2] ;
 
     //create actual employee object
     obj[0] = new Employee();
     obj[1] = new Employee();
 
     //assign data to employee objects
     obj[0].setData(100,"ABC");
     obj[1].setData(200,"XYZ");
 
     //display the employee object data
     System.out.println("Employee Object 1:");
     obj[0].showData();
     System.out.println("Employee Object 2:");
     obj[1].showData();
  }
}
//Employee class with empId and name as attributes
class Employee{
    int empId;
    String name;
    public void setData(intc,String d){
        empId=c;
        name=d;
     }
    public void showData(){
        System.out.print("EmpId = "+empId + "  " + " Employee Name = "+name);
        System.out.println();
     }

Prepared by : Reviewed / Checked by: Verified by: Approved by:


5

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :
COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES
Week No: 4, Period: Test 1 / Test 2  / Final,
Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

4-

/* Multiple errors with single catch block� */

class Demonstration_108 {
public static int j;
public static void main (String args[ ] ) {
for (int i = 0; i < 4; i++ ) {
try {
switch (i) {
case 0 :
int zero = 0;
j = 999/ zero; // Divide by zero
break;
case 1:
int b[ ] = null;
j = b[0] ; // Null pointer error
break;
case 2:
int c[] = new int [2] ;
j = c[10]; // Array index is out-of-bound
Prepared by : Reviewed / Checked by: Verified by: Approved by:
6

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :
COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES
Week No: 4, Period: Test 1 / Test 2  / Final,
Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

break;
case 3:
char ch = "Java".charAt(9) ;// String index is
out-of-bound
break;
}
} catch (Exception e) {
System.out.println("In Test case#"+i+ "\n");

System.out.println (e.getMessage() );
}
}
}
}

OUTPUT:
In Test case#0
/ by zero
In Test case#1
null
In Test case#2
10
In Test case#3
String index out of range: 9

Prepared by : Reviewed / Checked by: Verified by: Approved by:


7

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :
COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES
Week No: 4, Period: Test 1 / Test 2  / Final,
Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

5-

public class GFG {


 
    static String addBinary(String a, String b)
    {
   
        String result = "";
         
        int s = 0;        
        int i = a.length() - 1, j = b.length() - 1;
        while (i >= 0 || j >= 0 || s == 1)
        {
                         s += ((i >= 0)? a.charAt(i) - '0': 0);
            s += ((j >= 0)? b.charAt(j) - '0': 0);
 
            // If current digit sum is
            // 1 or 3, add 1 to result
            result = (char)(s % 2 + '0') + result;
 
            // Compute carry
            s /= 2;
 
            // Move to next digits
            i--; j--;
        }
         
    return result;
    }
 
    //Driver code
    public static void main(String args[])
    {
        String a = "1101", b="100";
         
        System.out.print(addBinary(a, b));
    }
}
Prepared by : Reviewed / Checked by: Verified by: Approved by:
8

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :
COLLEGE OF ADMINISTRATIVE AND FINANCIAL SCIENCES
Week No: 4, Period: Test 1 / Test 2  / Final,
Trimester: 1st / 2nd / 3rd, AY 2019-2020
Lab Report No. 2
MARKS

COURSE CODE COMP421* COURSE TITLE COMPUTER PROGRAMMING 2


SECTION TIME DAYS ROOM
STUDENT NAME ID NO. DATE

RUBRIC / Rubric for 5 marks questions


MARKING
SCHEME 5 All accurate statements with clear syntax are written in the program with correct
logical sequence.

4 All accurate statements with few mistakes in syntax are written in the program with
correct logical sequence.

3 At least few accurate statements are written with clear syntax are written in the
program.

2 Fewer than 2 accurate statements with syntax are written in the program.

1 Inaccurate statements with clear syntax are written in the program.


LEARNING ASSESSMENT/MARKING FACULTY/MARKER’S FEEDBACK
ITEM CILOs MARKS MARKS AWARDED
Q1 C2 5
Q2 C4 5
Q3 C5 5
Q4 C6 5
Q5 C2 5
TOTAL 25

Prepared by : Reviewed / Checked by: Verified by: Approved by:


9

Dr. Vinodh Natarajan Dr. Marluna Lim Urubio


Dr.Nivas Mohideen Jinna Dr. Vishwas Chakranarayan
Coordinator Member Teachers: Program Head Associate Dean College Dean
Date : Date : Date : Date :

You might also like