CS201 MID TERM SOLVED MCQs || PAST PAPERS || GROUP-1 || INTRODUCTION TO PROGRAMMING || VuTech Visit Website For More Solutions www.vutechofficial.blogspot.com …
CS506 ASSIGNMENT NO. 1 FALL 2022 || 100% RIGHT SOLUTION || COMPILER CONSTRUCTION || BY VuTech
SEND WHATSAPP OR E-MAIL FOR ANY QUERY
0325-6644800
kamranhameedvu@gmail.com
Instructions:
Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:
§The assignment is submitted after due date.
§The submitted assignment does not open or file is corrupt.
§Assignment is copied (partial or full) from any source (websites, forums, students, etc.) Strict action will be taken in this regard.
§The assignment format is other than Notepad.
Objectives:
The objective of this assignment is to provide hands-on experience of Java Programming concepts including:
·Classes and Objects
·Default and Parameterized Constructors
·Member Functions and main function
For any assignment related query, contact at CS506@vu.edu.pk
Covered Lectures: Assignment no.1 is from 1-9 lectures.
Software (s) Used to develop Assignment
Note: Use Notepad or Notepad++ for coding and JDK package for java source code compilation and running.Submit a single Test.java file including both classes(Student and Test) in one file(No multiple or zip files allowed)
SEND WHATSAPP OR E-MAIL FOR ANY QUERY
0325-6644800
kamranhameedvu@gmail.com
Problem Statement:
Write a program in java that will have two classes i.e. Student and Test. Student class will have three attributes (id, name and program) and methods of constructors, getters, setters and print etc. Test class will have the main method in which you are required to create four objects of Student class and store them in an array. You have to write code for error exception handling as well in case if the array index is to be accessed out of bound.
Detail:
Student class will have three attributes (id, name and program).
Methods of Constructors i.e default and parameterized to initialize the attribute.
1. Default constructors: If an object of Student class is created without passing any parameter default constructor should be executed and set the values of attributes (id, name, and program) to your own student id, name and program.
2. Parameterized Constructors: When parameters are provided then parameterized constructor will initialize the data members with the given values.
If the first two characters of the program string for example BS does not match the first two characters of Student id i. e BC457810241 then error should displayed as:
“Your program does not match your student Id”
It should have getter and setter functions to get or set the values of any one attribute.
print function of Student class should display the students object data store in the array list.
Test class will have the main method in which you are required to create four objects of Student class and store them in an Array.
First object should be without providing the parameters so it should call the default constructor.
Display the data of all the four students using for loop with one more index i.e 0,1,2,3,4. On index 4, the Index out of Bounds Exception should be displayed.
SOLUTION
STUDENT:
//public class Student ()
public class Student {
private String id;
private String name;
private String program;
// default constructor
public Student () {
id = "BSc00000000";
name = "Ahmed";
program = "BSc Computer Science";
}
// parameters constructor
public Student (String id, String name, String program) {
We provide Virtual University of Pakistan Study Materials such as Solution of Assignments, GDBs, Mid Term Solved Papers, Final Term Solved Papers, Mid Term Solved MCQs, and Final Term Solved MCQs. We also provide regular Semester Quizzes, Updated Handouts, and Short Questions and Answers. We help you with your research and many other educational-related topics, as far as we know. Furthermore, Share your problem with us and Please feel free to ask any related questions.