0% found this document useful (0 votes)
57 views5 pages

CS506 SOLUTION-1 by JUNAID

The document is code for a Java program that creates an array of Student objects. It initializes some of the Student objects by passing values to the constructor. It then iterates through the array and prints out the ID, name, and program for each Student. An exception is caught for when it tries to access an invalid index in the array.
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)
57 views5 pages

CS506 SOLUTION-1 by JUNAID

The document is code for a Java program that creates an array of Student objects. It initializes some of the Student objects by passing values to the constructor. It then iterates through the array and prints out the ID, name, and program for each Student. An exception is caught for when it tries to access an invalid index in the array.
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/ 5

CS506- Web-development and

Designing
ASSIGNMENT NO-1 F2022
SOLVED by: JUNAID MALIK
AL-JUNAID TECH INSTITUTE
public class CS506_SOLTION_1 {

public static void main(String[] args) {

Student st[] = new Student[4];

st[0] = new Student();

st[1] = new Student("BSXXXXXXXX", "Student 1", "BS");

st[2] = new Student("BcXXXXXXXX ", "Student 2", "BS");

st[3] = new Student("BSXXXXXXXX", " Student 3", "MCS");

for (int i = 0; i <= 4; i++) {

Student s = new Student();

try {

s.Print(st[i]);

} catch (ArrayIndexOutOfBoundsException e) {

System.out.println("\nIndex out of bounds.");

class Student {

private String id, name, program;

public Student() {

id = "0304-1659294";

name = "JUNAID MALIK";


AL-JUNAID TECH INSTITUTE
program = "BS";

public Student(String id, String name, String program) {

this.id = id;

this.name = name;

if (id.substring(0, 2).equals(program.substring(0, 2))) {

this.program = "Your program does not match your student Id";

} else {

this.program = program;

public String getId() {

return id;

public void setId(String id) {

this.id = id;

public String getName() {

return name;

public void setName(String name) {


AL-JUNAID TECH INSTITUTE
this.name = name;

public String getProgram() {

return program;

public void setProgram(String program) {

this.program = program;

public void Print(Student s) {

System.out.println("FOR PAID CONTACT ON ME 0304-1659294:");

System.out.println("\nID : " + s.getId() + "\nName : " + s.getName() + "\nProgram : " +


s.getProgram());

OUTPUT:
AL-JUNAID TECH INSTITUTE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy