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

home / study / engineering / computer science / questions and answers / design a

ID: 3679069 • Letter: H

Question

home / study / engineering / computer science / questions and answers / design a java class report that models a student ... Question Design a java class Report that models a student enrollment report. A report has a student name, semester name, and list of courses the student is enrolled. Support the following methods: A constructor that takes the student name and semester name A method addCourse that adds course title as a line to the report A method getReport that returns as follows(sample output) Write a program(tester) that uses this class to create the report and print it. Create Student Name, semester name, and courses as user input.

Explanation / Answer

public class HelloWorld{

     public static void main(String []args){
        Student s=new Student("David","Second");
        s.addCourse("Maths");
        s.addCourse("AI");
        s.getReport(s);
     }
}
class Student
{
    private String StudentName;
    private String SemesterName;
    private String[] CoursesName=new String[10];
    int size=-1;
  
    public Student(String StudentName,String SemesterName)
    {
        this.StudentName=StudentName;
        this.SemesterName=SemesterName;
    }
    public void addCourse(String CourseName)
    {
        this.CoursesName[size+1]=CourseName;
        size++;
    }
    public void getReport(Student s)
    {
        System.out.println("Student Details:");
        System.out.println("Name: "+s.StudentName);
        System.out.println("Semester: "+s.SemesterName);
        System.out.println("Courses Details");
        for(int i=0;i<=size;i++)
        System.out.println(s.CoursesName[i]);
    }
}