Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OBJECT-ORIENTED PROGRAMMING Problem 1: In the market there are different types o

ID: 3728717 • Letter: O

Question

OBJECT-ORIENTED PROGRAMMING

Problem 1:

In the market there are different types of printers such as laserjet, deskjet, dot matrix, ..etc. All these printers can be represented as different sub classes under the printer class. For example, laserjet printer is a printer, deskjet printer is a printer, and dotmatrix printer is a printer.

Your task is to demonstrate how can polymorphism be utilized between printer super class and laserjet, deskjet, and dotmatrix sub classes. Explain your answer and implement it in code.

Problem 2:

Student class has the following attributes and methods.

String name;

Int studentId;

String [] coursesRegistered; // courses registered by the student this semester. Maximum 4.

Your task is to create an array of type Student that holds the students objects. Then create a method that print each student information (name, studentId, and coursesRegistered). Students array cannot be less than a size of 5.

Explanation / Answer

Please find my implementation of Q2.

Please repost others in separate post.

import java.util.Arrays;

public class Student {

  

   private String name;;

   private int studentId;

   private String [] coursesRegistered; // courses registered by the student this semester

  

   public Student(String name, int id, String[] c) {

       this.name = name;

       studentId = id;

       coursesRegistered = c;

   }

  

   public Student() {

       coursesRegistered = new String[4];

   }

  

   public String getName() {

       return name;

   }

   public int getStudentId() {

       return studentId;

   }

   public String[] getCoursesRegistered() {

       return coursesRegistered;

   }

   public void setName(String name) {

       this.name = name;

   }

   public void setStudentId(int studentId) {

       this.studentId = studentId;

   }

   public void setCoursesRegistered(String[] coursesRegistered) {

       this.coursesRegistered = coursesRegistered;

   }

   @Override

   public String toString() {

       return studentId+","+name+", "+Arrays.toString(coursesRegistered);

   }

   public static void main(String[] args) {

      

       Student[] students = new Student[5];

      

       String[] c = {"Networking", "DBMS", "Data Structure", "Java"};

      

       students[0] = new Student("Pravesh Kumar", 101, c);

       students[1] = new Student("Rahul M", 102, c);

       students[2] = new Student("Pinky Rani", 105, c);

       students[3] = new Student("Prity Mehta", 110, c);

       students[4] = new Student("Vaishnavi A", 111, c);

      

       for(Student s : students)

           System.out.println(s);

      

      

   }

}

/*

Sampel run:

101,Pravesh Kumar, [Networking, DBMS, Data Structure, Java]

102,Rahul M, [Networking, DBMS, Data Structure, Java]

105,Pinky Rani, [Networking, DBMS, Data Structure, Java]

110,Prity Mehta, [Networking, DBMS, Data Structure, Java]

111,Vaishnavi A, [Networking, DBMS, Data Structure, Java]

*/