How do I count data objects in Java - java

I have an assignment that asks me to create students with first name, last name, GPA and major as options the user can input and I am supposed to give these "students" a student ID as well. I can give them an ID in the constructor of one of the classes but I can't seem to iterate through the student count, to give the students the correct type of student id, eg. 123456, 123457, 123458 etc. I am only pasting a few lines because the whole assignment is about 300 lines long and I didn't think anyone cared to read it all over. Can anyone tell me what I'm doing wrong or if this doesn't even make sense to try? I know of another way but I don't like it because it makes me have the student id numbers stored in a separate ArrayList than the other student data and then I would just match up indices. Here's the constructor, with count being initialized as a field with 0...
public Student( String fName, String lName, String maj, double gpa) {
sNumber += count++;
firstName = fName;
lastName = lName;
major = maj;
this.gpa = gpa;
}
Here's the add method from another class....
private static void addStudent(ArrayList<Student> L) {
System.out.println();
Scanner input = new Scanner(System.in);
System.out.print("First name: ");
String uFName = input.nextLine();
System.out.print("Last name: ");
String uLName = input.nextLine();
System.out.print("Major: ");
String studyMaj = input.nextLine();
System.out.print("GPA: ");
double grades = input.nextDouble();
Student newStudent = new Student(uFName, uLName, studyMaj, grades);
L.add(newStudent);
input.close();
}

try this
public Student( String fName, String lName, String maj, double gpa,number ) {
firstName = fName;
lastName = lName;
major = maj;
this.gpa = gpa;
sNumber = number;
}
private static void addStudent(ArrayList<Student> L) {
System.out.println();
Scanner input = new Scanner(System.in);
System.out.print("First name: ");
String uFName = input.nextLine();
System.out.print("Last name: ");
String uLName = input.nextLine();
System.out.print("Major: ");
String studyMaj = input.nextLine();
System.out.print("GPA: ");
double grades = input.nextDouble();
int number=0;
if(l.size()>0){
number=l.get(l.size()-1).getSNumber()+1;
}
Student newStudent = new Student(uFName, uLName, studyMaj, grades,number);
L.add(newStudent);
input.close();
}

Related

I'm trying to store 2 user inputs (doubles) inisde a local array. I don't know the Syntax

Instruction for the method:
readMarks(): accepts Scanner object, return nothing. Reads number of courses, and then reads marks of all courses and stored them in a local array.
I just need the syntax to store all the values inside the array and eventually use that array somewhere else. Is there a way to do that?
import java.util.Scanner;
public class Student extends Person{
private int studentNumber;
private String programName;
private double gpa;
private double baseFees;
private double maxMarks = 100;
private double maxGPA = 4;
public Student(int studentNumber, String programName, double gpa,
double baseFees, String fName, String lName, String mail, long pNumber, double maxMarks, double maxGPA) {
super(fName, lName, mail, pNumber);
this.studentNumber = studentNumber;
this.programName = programName;
this.gpa = gpa;
this.baseFees = baseFees;
this.maxGPA = maxGPA;
this.maxMarks = maxMarks;
}
public void readInfo(Scanner input) {
System.out.println("Enter first Name: ");
String fName = input.next();
System.out.println("Enter last name: ");
String lName = input.next();
System.out.println("Enter email: ");
String mail = input.next();
System.out.println("Enter phone number: ");
long pNumber = input.nextLong();
System.out.println("Enter GPA: ");
double gpa = input.nextDouble();
System.out.println("Enter baseFees: ");
double baseFees = input.nextDouble();
readMarks(input);
}
public void readMarks(Scanner input) {
System.out.println("Enter number of courses: ");
double numberOfCourses = input.nextDouble();
System.out.println("Enter marks: ");
double courseMarks = input.nextDouble();
}
}
The number of courses should be int, no need to support fractions for it. And then you will need to create a double array and fill the values:
public void readMarks(Scanner input) {
System.out.println("Enter number of courses: ");
int numberOfCourses = input.nextInt();
System.out.println("Enter marks: ");
double[] courseMarks = new double[numberOfCourses];
for (int i = 0; i < numberOfCourses; i++) {
courseMarks[i] = input.nextDouble();
}
// Now you have an array, do something with it, but note, it's local
}

how to add bunch of data into linked list

Basically, I just tried to learn linked lists but I can't seem to understand how to insert a bunch of data from different variables into it. Does it work as an array/ ArrayList? Before we end the loop we are supposed to store the data right, but how??
Let say I have variables ( name, age, phonenum).
'''
char stop='Y';
while(stop!='N'){
System.out.println("\nEnter your name : ");
int name= input.nextLine();
System.out.println("\nEnter your age: ");
int age= input.nextInt();
System.out.println("\nEnter your phone number: ");
int phonenum= input.nextLine();
System.out.println("Enter 'Y' to continue, 'N' to Stop: ");
stop = sc.nextLine().charAt(0);
}
'''
First, change your code to use appropriate types. Name and phone should be of type String, not int.
Define a class to hold your fields. Records are an easy way to do that.
record Person ( String name , int age , String phone ) {}
Declare your list to hold objects of that class.
List< Person > list = new LinkedList<>() ;
Instantiate some Person objects, and add to list.
list.add( New Person( "Alice" , 29 , "477.555.1234" ) ) ;
In the line above, I hard-coded some example data. In your own code, you will be passing to the constructor the variables you populated by interacting with the user.
list.add( New Person( name , age , phonenum ) ) ;
You can create an object which has name, age and phenomenon then create an insert method which you call in your while loop.
In psuedo code it would look something like this:
public class Data {
String name;
int age;
int phenomenon;
//constructor
//getters & setters
}
This class above will hold contain the user input. You can gather all the user input and store it in an array and perform the insert with array of data instead of inserting one object at a time
public void InsertData(LinkedList<Data> list, Arraylist<Data> input) {
for(Data d: input){
list.add(d);
}
}
You can read up on linkedlists a bit more here to understand how exactly linkedlists work and implement your own from scratch: https://www.geeksforgeeks.org/implementing-a-linked-list-in-java-using-class/
Try this
Possibility : 1
import java.util.*;
public class Naddy {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char stop = 'Y';
LinkedList<Object> list = new LinkedList<Object>();
while (stop != 'N') {
System.out.println("\nEnter your name : ");
String name = input.nextLine();
System.out.println("\nEnter your age: ");
int age = input.nextInt();
System.out.println("\nEnter your phone number: ");
long phonenum = input.nextLong();
list.add(name);
list.add(age);
list.add(phonenum);
System.out.println("Enter 'Y' to continue, 'N' to Stop: ");
input.nextLine();
stop = input.nextLine().charAt(0);
}
System.out.println(list);
}
}
possibility : 2
import java.util.*;
public class Naddy {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char stop = 'Y';
LinkedList<User> list = new LinkedList<User>();
while (stop != 'N') {
System.out.println("\nEnter your name : ");
String name = input.nextLine();
System.out.println("\nEnter your age: ");
int age = input.nextInt();
System.out.println("\nEnter your phone number: ");
long phonenum = input.nextLong();
list.add(new User(name, age, phonenum));
System.out.println("Enter 'Y' to continue, 'N' to Stop: ");
input.nextLine();
stop = input.nextLine().charAt(0);
}
System.out.println(list);
}
}
class User {
private String name;
private int age;
private long phonenum;
public User() {
}
public User(String name, int age, long phonenum) {
this.name = name;
this.age = age;
this.phonenum = phonenum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public long getPhonenum() {
return phonenum;
}
public void setPhonenum(long phonenum) {
this.phonenum = phonenum;
}
#Override
public String toString() {
return "User [age=" + age + ", name=" + name + ", phonenum=" + phonenum + "]";
}
}

how can i call a variable from another function/method?

I have an assignment to do a CV that users will input on and display it. However, I don't know how I can call a variable to another to function to print/display.
Here is the code:
import java.util.Scanner;
public class curriculumVitae1{
public static String firstName;
public static String middleName, lastName, birthDate, maritalStatus, homeAddress, provincialAddress, mobileNumber, anotherMobile, landlineNumber, anotherLandline, primaryYears;
private static void main (String args[]){
Scanner input = new Scanner(System.in);
System.out.print("\nCurriculum Vitae");
System.out.print("\nInput your last name: ");
String lastName;
lastName = input.nextLine();
System.out.print("\nInput your first name: ");
String firstName;
firstName = input.nextLine();
System.out.print("\nInput your middle name: ");
String middleName;
middleName = input.nextLine();
System.out.print("\nInput your birthdate: ");
String birthDate;
birthDate = input.nextLine();
System.out.print("\nInput your marital status (Married, Widowed, Separated, Divorced, Single) : ");
String maritalStatus;
maritalStatus = input.nextLine();
System.out.print("\nInput your home address: ");
String homeAddress;
homeAddress = input.nextLine();
curriculumVitae1.cv();
}
private static void provincial(String args[]){
Scanner input = new Scanner(System.in);
System.out.print("\nDo you have a provincial address? Enter Y if yes, and N if no: ");
char provincialQuestion;
provincialQuestion = input.nextLine().charAt(0);
if (provincialQuestion=='Y'){
System.out.print("\nInput your provincial address: ");
String provincialAddress;
provincialAddress = input.nextLine();
}
else if(provincialQuestion=='N'){
}
}
private static void mobile(String args[]){
Scanner input = new Scanner(System.in);
System.out.print("\nContact Details ");
System.out.print("\nInput your mobile number: ");
String mobileNumber;
mobileNumber = input.nextLine();
System.out.print("\nDo you have another mobile number? Enter Y if yes, and N if no: ");
char mobileQuestion;
mobileQuestion = input.nextLine().charAt(0);
if (mobileQuestion=='Y'){
System.out.print("\nInput another mobile number: ");
String anotherMobile;
anotherMobile = input.nextLine();
}
else if(mobileQuestion=='N'){
}
}
private static void landline(String args[]){
Scanner input = new Scanner(System.in);
System.out.print("\nInput your landline number: ");
String landlineNumber;
landlineNumber = input.nextLine();
System.out.print("\nDo you have another landline number? Enter Y if yes, and N if no: ");
char landlineQuestion;
landlineQuestion = input.nextLine().charAt(0);
if (landlineQuestion=='Y'){
System.out.print("\nInput another mobile number: ");
String anotherLandline;
anotherLandline = input.nextLine();
}
else if (landlineQuestion=='N'){
}
}
private static String email(){
Scanner input = new Scanner(System.in);
System.out.print("\nInput your email address: ");
String emailAddress;
emailAddress = input.nextLine();
return emailAddress;
}
private static String tertiary(){
Scanner input = new Scanner(System.in);
System.out.print("\nEducation History ");
System.out.print("\nTertiary Education ");
System.out.print("\nInput your tertiary education course: ");
String tertiaryCourse;
tertiaryCourse = input.nextLine();
System.out.print("\nInput your tertiary education school: ");
String tertiarySchool;
tertiarySchool = input.nextLine();
System.out.print("\nInput your tertiary education inclusive years (xxxx-xxxx): ");
String tertiaryYears;
tertiaryYears = input.nextLine();
System.out.print("\nDo you have any honors/achivements received during your tertiary education? Enter Y if yes, and N if no: ");
char tertiaryQuestion;
tertiaryQuestion = input.nextLine().charAt(0);
if (tertiaryQuestion=='Y'){
System.out.print("\nInput your honor/s or achivement/s:");
String tertiaryAchievements;
tertiaryAchievements = input.nextLine();
return tertiaryAchievements;
}
else if (tertiaryQuestion=='N'){
return "------";
}
}
private static void secondary(String args[]){
Scanner input = new Scanner(System.in);
System.out.print("\nSecondary Education ");
System.out.print("\nInput your secondary education school: ");
String secondarySchool;
secondarySchool = input.nextLine();
System.out.print("\nInput your secondary education inclusive years (xxxx-xxxx): ");
String secondaryYears;
secondaryYears = input.nextLine();
System.out.print("\nDo you have any honors/achivements received during your secondary education? Enter Y if yes, and N if no: ");
char secondaryQuestion;
secondaryQuestion = input.nextLine().charAt(0);
if (secondaryQuestion=='Y'){
System.out.print("\nInput your honor/s or achivement/s:");
String secondaryAchievements;
secondaryAchievements = input.nextLine();
}
else if (secondaryQuestion=='N'){
}
}
public static void primary(String args[]){
Scanner input = new Scanner(System.in);
System.out.print("\nPrimary Education ");
System.out.print("\nInput your primary education school: ");
String primarySchool;
primarySchool = input.nextLine();
System.out.print("\nInput your primary education inclusive years (xxxx-xxxx): ");
String primaryYears;
primaryYears = input.nextLine();
System.out.print("\nDo you have any honors/achivements received during your primary education? Enter Y if yes, and N if no: ");
char primaryQuestion;
primaryQuestion = input.nextLine().charAt(0);
if (primaryQuestion=='Y'){
System.out.print("\nInput your honor/s or achivement/s:");
String primaryAchievements;
primaryAchievements = input.nextLine();
}
else{
System.out.print("------");
}
}
public static void cv(String args[]){
System.out.println(" Curriculum Vitae");
System.out.print("\nName:" + firstName + " " + middleName + " "+ lastName);
System.out.print("\nBirthdate:" + birthDate);
System.out.print("\nMarital Status:" + maritalStatus);
System.out.print("\nHome Address:" + homeAddress);
System.out.print("\nProvincial Address:" + provincialAddress);
System.out.print("\nMobile Number:" + mobileNumber );
System.out.print("\nAnother Mobile Number:" + anotherMobile);
System.out.print("\nLandline:" + landlineNumber);
System.out.print("\nYear: " + primaryYears);
}
}
However, I always get the error that
C:\Users\BEST\Desktop\wew>javac curriculumVitae1.java
curriculumVitae1.java:33: error: method cv in class curriculumVitae1 cannot be applied to given types;
curriculumVitae1.cv();
^
required: String[]
found: no arguments
reason: actual and formal argument lists differ in length
1 error
Please help me on how can I print out another variable from other function. Or some alternatives that I can do.
Your methods expect an (String[] args) however since you don't use them I would remove them. Try
public static void cv() {
The error details highlight that you're calling the method without providing the required parameters in the method signature public static void cv(String args[]):
The required part tells you what types of arguments are expected, here String[] and the found part tells you what it saw instead, here it saw you passed no arguments.
The reason tells you that the actual (what you provided) number of arguments differs from the formal (what the method signature defines) number of arguments expected, i.e. not enough or too many arguments were provided.
You can also get this from the original error message:
error: method cv in class curriculumVitae1 cannot be applied to given types;
curriculumVitae1.cv();
It doesn't explicitly state it, but from the line of code shown below you can see that the "given types" are nothing because the method was called with no arguments—nothing inside the parentheses.
Like Peter Lawrey said, you can just remove the String args[] from your method signature since you don't use it.
Hope this helps you understand error messages and what they're telling you a little better!
Make the following changes to your program:
Change the access specifier of main() method from private to public. Otherwise the code will throw the error - Does not contain a main method
Since you have firstName, middleName, lastName, birthDate etc. declared as static variables do not declare them as local variables in main method. Assign the values to the already declared static variables in the main() method as shown below:
public static void main (String args[]){
Scanner input = new Scanner(System.in);
System.out.print("\nCurriculum Vitae");
System.out.print("\nInput your last name: ");
//String lastName;
lastName = input.nextLine();
System.out.print("\nInput your first name: ");
//String firstName;
firstName = input.nextLine();
System.out.print("\nInput your middle name: ");
//String middleName;
middleName = input.nextLine();
System.out.print("\nInput your birthdate: ");
//String birthDate;
birthDate = input.nextLine();
System.out.print("\nInput your marital status (Married, Widowed, Separated,
Divorced, Single) : ");
//String maritalStatus;
maritalStatus = input.nextLine();
System.out.print("\nInput your home address: ");
//String homeAddress;
homeAddress = input.nextLine();
//System.out.println();
cv();
}
Remove the String[] args argument from cv() method as it is not being used.
Since cv() is a static method, it can be called directly from the main().
Return the string type varaible from tertiary() method as it is giving a compile error. You can do so by declaring tertiaryAchievements variable outside the if-else block and then returning it as shown below:
String tertiaryAchievements="";
if (tertiaryQuestion=='Y')

Number format exception in java, taking wrong input

When using the code
else if(command.equalsIgnoreCase("add")) {
System.out.println("Enter the Student's Name: ");
String name = input.nextLine();
System.out.println("Enter the Student's Number: ");
String studNum = input.nextLine();
System.out.println("Enter the Student's Address: ");
String address = input.nextLine();
langara.addStudent(name, address, studNum);
System.out.println("A Student added to the College Directory");
}
If the user enters add, it's suppose to go through the above procedure, In the collage class (langara) there is a "addStudent" method :
public void addStudent(String name, String address, String iD) {
Student firstYear = new Student(name, address, iD);
collegeStudents.add(firstYear);
}
And this creates a student object of the student class using the constructor:
public Student(String name, String address, String iD) {
long actualId = Long.parseLong(iD);
studentName = name;
studentID = actualId;
studentAddress = new Address(address);
numberOfQuizzes = 0;
scoreTotal = 0;
}
I'm getting the error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "Abernathy, C."
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at Student.<init>(Student.java:48)
at College.addStudent(College.java:33)
at CollegeTester.main(CollegeTester.java:53)
It's as if it's trying to convert the Students name to long, but it's supposed to convert the student ID to long..
This is where scanner is created, college is created, and command is initialized:
Scanner input = new Scanner(System.in);
College langara = new College();
String command = "";
System.out.print("College Directory Commands:\n" +
"add - Add a new Student\n" +
"find - Find a Student\n" +
"addQuiz - Add a quiz score for a student\n" +
"findHighest - Find a student with the highest quiz score\n" +
"delete - Delete a Student\n" +
"quit - Quit\n");
command = input.nextLine();
The input is being read from a input.txt file, with each input on it's own line.
The input at the beginning of the file for this command is:
add
Abernathy, C.
10010123
100, West 49 Ave, Vancouver, BC, V7X2K6
What is going wrong here?
It looks right now, but I would swear that when I first looked at this (and copy/pasted your code) that the call to langara.addStudent had the parameters as name, studNum, address. I put this class together with your input file and it appears to work fine:
import java.io.FileInputStream;
import java.util.Scanner;
public class StackOverflow_32895589 {
public static class Student
{
String studentName;
long studentID;
String studentAddress;
long numberOfQuizzes;
long scoreTotal;
public Student(String name, String address, String iD)
{
studentName = name;
studentID = Long.parseLong(iD);
studentAddress = address;
numberOfQuizzes = 0;
scoreTotal = 0;
}
}
public static void main(String[] args)
{
try{
System.setIn(new FileInputStream("c:\\temp\\input.txt"));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
Scanner input = new Scanner(System.in);
String command = input.nextLine();
if (command.equals("add"))
{
System.out.println("Enter the Student's Name:");
String name = input.nextLine();
System.out.println("Enter the Student's Number:");
String studNum = input.nextLine();
System.out.println("Enter the Student's Address:");
String address = input.nextLine();
System.out.println("[" + name + "][" + studNum + "][" + address + "]");
input.close();
addStudent(name, address, studNum);
}
}
public static void addStudent(String name, String address, String iD)
{
Student firstYear = new Student(name, address, iD);
}
}

How can I combine an extra variable to an array/method?

I have created a simple program which outputs student details. Ideally I would like to give the user an option to add both courses. Will this require a lot of messing about changing code? If not can someone help?
class Student
{
public static void main(String[]args)//The main method; starting point of the program.
{
Scanner input = new Scanner(System.in);
String surName, foreName, courseName;
int age,telephone;
System.out.println("\t\t\t***********************************************");
System.out.println("\t\t\tWelcome to the Mobile College's Student Records");
System.out.println("\t\t\t***********************************************");
System.out.println("\nHow many students would you like to add?");
int noStudents = input.nextInt();
Stu [] TheStu = new Stu [noStudents];
for (int x = 0; x < noStudents; x++)
{
System.out.println("Please enter Surname: ");
surName = input.next();
System.out.println("Please enter Forename: ");
foreName = input.next();
System.out.println("Please enter Age: ");
age = input.nextInt();
System.out.println("Please enter Telephone No. ");
telephone = input.nextInt();
System.out.println("Which course do you want to add the student to? .......Literacy or Numeracy ");
courseName = input.next();
TheStu [x] = new Stu (surName, foreName, age, telephone, courseName);
}
for (int y = 0; y < noStudents; y++)
{
System.out.println("\t\t\t***********************************************");
System.out.println ("\t\t\tName: " + TheStu[y].getfName() + " " + TheStu[y].getsName());
System.out.println ("\t\t\tAge: " + TheStu[y].getstuAge());
System.out.println ("\t\t\tTelephone No. 0" + TheStu[y].getphone());
System.out.println ("\t\t\tEnrolled on the " + TheStu[y].getcourseType() + " Course.");
System.out.println("\t\t\t***********************************************");
}
}// end of class
}
class Stu
{
private String sName;
private String fName;
private int stuAge;
private int phone;
private String courseType;
Stu (String s, String f, int a, int p, String c)
{
sName = s;
fName = f;
stuAge = a;
phone = p;
courseType = c;
}
String getsName()
{
return sName;
}
String getfName()
{
return fName;
}
int getstuAge()
{
return stuAge;
}
int getphone()
{
return phone;
}
String getcourseType()
{
return courseType;
}
}
If you want something pretty basic, you could change your courses into a String array so you could store both courses. Also when asking the user to input a course name, you could have an ALL option, so you automatically register the student for all courses. See below for a slightly modified version of your code :
import java.util.Scanner;
class Student
{
public static void main(String[] args)//The main method; starting point of the program.
{
Scanner input = new Scanner(System.in);
String surName, foreName, courseName;
String[] courses = new String[]{};
int age,telephone;
System.out.println("\t\t\t***********************************************");
System.out.println("\t\t\tWelcome to the Mobile College's Student Records");
System.out.println("\t\t\t***********************************************");
System.out.println("\nHow many students would you like to add?");
int noStudents = input.nextInt();
Stu [] TheStu = new Stu [noStudents];
for (int x = 0; x < noStudents; x++)
{
System.out.println("Please enter Surname: ");
surName = input.next();
System.out.println("Please enter Forename: ");
foreName = input.next();
System.out.println("Please enter Age: ");
age = input.nextInt();
System.out.println("Please enter Telephone No. ");
telephone = input.nextInt();
System.out.println("Which courses do you want to add the student to? .......Literacy or Numeracy or both ");
courseName = input.nextLine();
// change to either upper case or lower case for easy treatment
courseName = courseName.toUpperCase();
// Also verify that the user entered a valid course name
if(courseName.equals("LITERACY")){
courses = new String[]{"LITERACY"};
} else if(courseName.equals("NUMERACY")){
courses = new String[]{"NUMERACY"};
} else if(courseName.equals("BOTH")){
courses = new String[]{"LITERACY", "NUMERACY"};
} else{
System.out.println("Error : You entered an invalid option.... \n This student won't be registered for any courses");
}
TheStu [x] = new Stu (surName, foreName, age, telephone, courses);
}
for (int y = 0; y < noStudents; y++)
{
System.out.println("\t\t\t***********************************************");
System.out.println ("\t\t\tName: " + TheStu[y].getfName() + " " + TheStu[y].getsName());
System.out.println ("\t\t\tAge: " + TheStu[y].getstuAge());
System.out.println ("\t\t\tTelephone No. 0" + TheStu[y].getphone());
System.out.println ("\t\t\tEnrolled in the following courses : ");
courses = TheStu[y].getcourseTypes();
for(int i = 0; i < courses.length; i++){
System.out.println(courses[i]);
}
if(courses.length < 1){
System.out.println("No Courses");
}
System.out.println("\t\t\t***********************************************");
}
}// end of class
}
class Stu
{
private String sName;
private String fName;
private int stuAge;
private int phone;
private String[] courseTypes;
Stu (String s, String f, int a, int p, String[] c)
{
sName = s;
fName = f;
stuAge = a;
phone = p;
courseTypes = c;
}
String getsName()
{
return sName;
}
String getfName()
{
return fName;
}
int getstuAge()
{
return stuAge;
}
int getphone()
{
return phone;
}
String[] getcourseTypes()
{
return courseTypes;
}
}
I tried as much as possible not to make any serious changes to your code as i assume you're a beginner, but there are a lot of changes you could make to improve your code. Happy Coding :)
When you ask for the course name, keep asking until they have entered in a sentinal value. Inside Stu keep an List<String> courseTypes. Store the entered courses in courseTypes. Also, you may want to add a set value to some of the fields in Stu. What if their phone number changes?

Categories