Define three classes for the students who are pursuing their higher education in Stanford University

0

Assignment: Module 02 - Part 02

Define three classes for the students who are pursuing their higher education in Stanford University with the following details and print the same details of those students. Each student has their own set of properties but they share common behavior. To depict the behavior create a simple method in each of the three classes with public access modifier.
Assignment: Module 02 - Part 02
04. Define three classes for the students who are pursuing their higher education in Stanford University with the following details and print the same details of those students. Each student has their own set of properties but they share common behavior. To depict the behavior create a simple method in each of the three classes with public access modifier.

134

Common Behavior 

Attend Lecture, submit Assignment and attend Lab

Expected Output :

Name : John

Gender : Male

Year of Study : 2016

Course Name : Java

University : Stanford

Attending Lecture

Submitted Assignment

Attending Lab.

Here is a simple implementation of the three classes in Java with the specified properties and methods:

class Student {
    String name;
    String gender;
    int yearOfStudy;
    String courseName;
    String university;
    
    public Student(String name, String gender, int yearOfStudy, String courseName, String university) {
        this.name = name;
        this.gender = gender;
        this.yearOfStudy = yearOfStudy;
        this.courseName = courseName;
        this.university = university;
    }
    
    public void attendLecture() {
        System.out.println("Attending Lecture");
    }
    
    public void submitAssignment() {
        System.out.println("Submitted Assignment");
    }
    
    public void attendLab() {
        System.out.println("Attending Lab");
    }
}

class StanfordStudent extends Student {
    public StanfordStudent(String name, String gender, int yearOfStudy, String courseName) {
        super(name, gender, yearOfStudy, courseName, "Stanford");
    }
}

class JavaStanfordStudent extends StanfordStudent {
    public JavaStanfordStudent(String name, String gender, int yearOfStudy) {
        super(name, gender, yearOfStudy, "Java");
    }
    
    public void printDetails() {
        System.out.println("Name : " + name);
        System.out.println("Gender : " + gender);
        System.out.println("Year of Study : " + yearOfStudy);
        System.out.println("Course Name : " + courseName);
        System.out.println("University : " + university);
    }
}

public class Main {
    public static void main(String[] args) {
        JavaStanfordStudent student = new JavaStanfordStudent("John", "Male", 2016);
        student.printDetails();
        student.attendLecture();
        student.submitAssignment();
        student.attendLab();
    }
}  

The output of the above code would be:

Name : John
Gender : Male
Year of Study : 2016
Course Name : Java
University : Stanford
Attending Lecture
Submitted Assignment
Attending Lab   

👉Create two classes named “Dog” and “Cat”.Define the objects for it and check if the objects are the instance of the classes or not.The class Dog and Cat should have the properties as : Name (string) ,Colour (string) , Breed (string) and Age (Integer). code and output. ðŸ‘ˆ

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates