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

1. Write a class Student with two instance variables: name (a String for the nam

ID: 3655536 • Letter: 1

Question

1. Write a class Student with two instance variables: name (a String for the name of the student) and courses (an array of length 5 with type String naming the courses being taken by the student). The class should have a default constructor that initializes name to be "NoName". Add a method called assignCourses() that has no input parameters and returns void. This method should ask a user to input up to 5 courses from the console window until the user enters an empty line, which indicates the end of the array. Then add a void method writeStudent(String filename) that writes the name of the student and the names of the student

Explanation / Answer

package com.cramster.nov8; import java.io.FileNotFoundException; import java.util.Formatter; import java.util.Scanner; public class Student { protected String name; protected String[] courses = new String[5]; protected int numberOfCourses; public Student() { name = "NOName"; } public Student(String studentName) { name = studentName; } public void assignCourses() { Scanner console = new Scanner(System.in); int courseNumber = 1; do { System.out.printf("Enter %d course : ",courseNumber); String course = console.nextLine(); if(!course.isEmpty()) { courses[courseNumber - 1] = course; courseNumber++; } else break; } while(courseNumber < 6); numberOfCourses = courseNumber - 1; } public void writeStudent(String fileName) { try { Formatter output = new Formatter(fileName); output.format("Name : %s ",name); for(int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote