I have created 2 java files: XCompanyShortlist.java and StudentDemo.java. The XCompanyShortlist.java contains the main method and all the user input like Student Registration No., Name, Semester, GPA, CGPA, Branch Name, Placement status and Internship status.
The StudentDemo.java has a superclass StudentDemo which initializes Reg. No., Name, Semester, GPA, CGPA using parameterized constructor and it also contains a method display() which displays all there informations.
A class BranchStudent extends StudentDemo class and contains an extra String named BranchName. This class also contains a display() method which calls the display() method in the superclass and also prints the BranchName. Another class StudentPlacement contains variables for InternshipStatus, PlacementStatus, and an array of preferred company list.
Here is the StudentDemo.java file code:
class StudentDemo {
long RegNo;
String fname;
short sem;
float gpa;
float cgpa;
StudentDemo() {
RegNo = 0;
fname = "";
sem = 0;
gpa = (float) 0.0;
cgpa = (float)0.0;
}
StudentDemo(long RegNo, String fname, short sem, float gpa, float cgpa) {
this.RegNo = RegNo;
this.fname = fname;
this.sem = sem;
this.gpa = gpa;
this.cgpa = cgpa;
}
StudentDemo(StudentDemo obj) {
RegNo = obj.RegNo;
fname = obj.fname;
sem = obj.sem;
gpa = obj.gpa;
cgpa = obj.cgpa;
}
void display() {
System.out.println("------------------------------------------");
System.out.println("Registration No. :"+RegNo);
System.out.println("Full Name: "+fname);
System.out.println("Semester: "+sem);
System.out.println("GPA: "+gpa);
System.out.println("CGPA: "+cgpa);
System.out.println("------------------------------------------");
}
}
class BranchStudent extends StudentDemo {
public String BranchName;
BranchStudent(long RegNo,String fname,short sem,float gpa,float cgpa,String BranchName) {
super(RegNo,fname,sem,gpa,cgpa);
this.BranchName = BranchName;
}
BranchStudent() {
super();
BranchName = "CSE";
}
BranchStudent(BranchStudent obj) {
super(obj);
BranchName = obj.BranchName;
}
void display() {
super.display();
System.out.println("Student Branch: "+BranchName);
}
}
class StudentPlacement extends BranchStudent {
String compList[];
int StatusPlacement, StatusIntern;
StudentPlacement() {
super();
StatusPlacement = 0;
StatusIntern = 0;
compList = new String[3];
}
StudentPlacement(StudentPlacement obj) {
super(obj);
StatusPlacement = obj.StatusPlacement;
StatusIntern = obj.StatusIntern;
compList = obj.compList;
}
StudentPlacement(long RegNo, String fname, short sem, float gpa, float cgpa, String BranchName,String compList[], int StatusPlacement,int StatusIntern) {
super(RegNo, fname, sem, gpa, cgpa, BranchName);
this.compList = compList;
this.StatusPlacement = StatusPlacement;
this.StatusIntern = StatusIntern;
}
}
Here is the XCompanyShortlist.java file code:
import java.util.Scanner;
public class XCompanyShortlist {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter The Number Of Students: ");
int n = sc.nextInt();
StudentPlacement obj[] = new StudentPlacement[n];
for(int i = 0; i < n; i++) {
obj[i] = new StudentPlacement();
}
System.out.println("Please Enter The Student Details: ");
for(int i = 0; i < n; i++) {
System.out.print("Please Enter The Reg. No. :");
long RegNo = sc.nextLong();
sc.nextLine();
System.out.print("Please Enter The Full Name: ");
String fname = sc.nextLine();
System.out.print("Please Enter The Semester: ");
short sem = sc.nextShort();
System.out.print("Please Enter The GPA: ");
float gpa = sc.nextFloat();
System.out.print("Please Enter The CGPA: ");
float cgpa = sc.nextFloat();
System.out.print("Please Enter Branch Name:");
String branchName = sc.nextLine();
sc.nextLine();
System.out.println("Please Enter 3 Preferred Choice: ");
String compList[] = new String[3];
for(int x = 0; x < 3; x++) {
compList[x] = sc.nextLine();
}
System.out.print("Please Enter The Status Of Placement(0/1): ");
int statusPlacement = sc.nextInt();
System.out.print("Please Enter Status Of Internship(0/1): ");
int statusIntern = sc.nextInt();
obj[i] = new StudentPlacement(RegNo,fname,sem,gpa,cgpa,branchName,compList,statusPlacement,statusIntern);
System.out.println();
}
for(int i = 0; i < n; i++) {
obj[i].display();
}
sc.close();
}
}
The problem I am facing is that all the student details from the StudentDemo superclass is being dislayed but the subclass BranchStudent is not printing the BranchName. I am unable to find the problem in my code.
OUTPUT:
Please Enter The Number Of Students:
1
Please Enter The Student Details:
Please Enter The Reg. No. :159101046
Please Enter The Full Name: Bitan Basak
Please Enter The Semester: 3
Please Enter The GPA: 8.86
Please Enter The CGPA: 8.64
Please Enter Branch Name:CSE
Please Enter 3 Preferred Choice:
HP
Dell
Microsoft
Please Enter The Status Of Placement(0/1): 0
Please Enter Status Of Internship(0/1): 0
------------------------------------------
Registration No. :159101046
Full Name: Bitan Basak
Semester: 3
GPA: 8.86
CGPA: 8.64
------------------------------------------
Student Branch:
This is the output given by my program. As you can see the Student Branch is not being printed. I am unable to understand why.
From what I can tell the issue has nothing to do with inheritance but rather that you are feeding an empty line to the constructor.
This means something is wrong with the usage of the Scanner.nextLine() method. If I change your code to this:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter The Number Of Students: ");
int n = sc.nextInt();
StudentPlacement obj[] = new StudentPlacement[n];
for(int i = 0; i < n; i++) {
obj[i] = new StudentPlacement();
}
System.out.println("Please Enter The Student Details: ");
for(int i = 0; i < n; i++) {
System.out.print("Please Enter The Reg. No. :");
long RegNo = sc.nextLong();
sc.nextLine();
System.out.print("Please Enter The Full Name: ");
String fname = sc.nextLine();
System.out.print("Please Enter The Semester: ");
short sem = sc.nextShort();
System.out.print("Please Enter The GPA: ");
float gpa = sc.nextFloat();
System.out.print("Please Enter The CGPA: ");
float cgpa = sc.nextFloat();
sc.nextLine();
System.out.print("Please Enter Branch Name:");
String branchName = sc.nextLine();
System.out.println("Please Enter 3 Preferred Choice: ");
String compList[] = new String[3];
for(int x = 0; x < 3; x++) {
compList[x] = sc.nextLine();
}
System.out.print("Please Enter The Status Of Placement(0/1): ");
int statusPlacement = sc.nextInt();
System.out.print("Please Enter Status Of Internship(0/1): ");
int statusIntern = sc.nextInt();
obj[i] = new StudentPlacement(RegNo,fname,sem,gpa,cgpa,branchName,compList,statusPlacement,statusIntern);
System.out.println();
}
for(int i = 0; i < n; i++) {
obj[i].display();
}
sc.close();
}
I.e. move the sc.nextLine() before the Branch Name input the scanner picks up the correct value from the console.
Hope that helps.
Greetings
in void display() method you are calling super display() method so the super display() method is calling not that branch display method and add this.branchname
Related
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
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Getting a main method error which is only affecting my retrieve salary method I'm not sure what to do to fix the issue I have added particular items but I can't get the error to go away. Is the only thing on my program that brings up an error and I am unable to continue. Image included of the only issues I'm encountering now
"Error: Main method not found in class, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application"
Image included
public class finalproject {
public static class employeeCase {
EMPLOYEE[] employees;
int AMOUNT;
employeeCase(){
employees = new EMPLOYEE[100];
AMOUNT = 0;
}
private void loadEmployee() {
String ID = null;
int SALARY = 0;
Scanner sc = new Scanner(System.in);
System.out.println(" ");
System.out.println("How many employees do you want to load?: ");
int num = sc.nextInt();
for(int i = 0; i < num; i++){
// Display parallel arrays
System.out.println(" ");
System.out.println("Name: " + employees[i] + " " + "ID: " + ID + " " + "Salary: " + SALARY);
sc.close();
}
}
private int addEmployee() {
Scanner sc = new Scanner(System.in);
System.out.println(" ");
System.out.println("How many employees do you want to enter?: ");
AMOUNT = 0;
AMOUNT = sc.nextInt();
String Again1 = "no";
String Fname;
String ID;
int SALARY = 0;
do {
for(int i = 0; i < AMOUNT; i++) {
System.out.printf("Enter employee's first name: ");
Fname = sc.nextLine();
System.out.printf("Enter employee ID (5 digits): ");
ID = sc.next();
System.out.printf("Enter employee salary: ");
SALARY = sc.nextInt();
System.out.println(" ");
this.employees[this.AMOUNT] = new EMPLOYEE(Fname, ID, SALARY);
this.AMOUNT++;
sc.close();
} } while (Again1.equalsIgnoreCase("yes"));
return SALARY;
}
private void displayEmployee() {
for(int i = 0; i < AMOUNT; i++){
// Display parallel arrays
System.out.println(" ");
System.out.println(this.employees[i]);
}
}
private void retrieveSpecific() {
Scanner sc = new Scanner(System.in);
System.out.println(" ");
System.out.println("Enter employee ID: ");
String id = sc.next();
//Search for ID in all the stored employees
for(int i=0; i<this.AMOUNT; i++) {
if(id.contentEquals(this.employees[i].ID)) {
System.out.println(this.employees[i]);
sc.close();
}}}
private void retrieveSalary() {
Scanner scan = new Scanner(System.in);
System.out.println(" ");
System.out.println("Enter lowest employee salary: ");
int LSALARY = scan.nextInt();
System.out.println(" ");
System.out.println("Enter highest employee salary: ");
int HSALARY = scan.nextInt();
for(int i = 0; i < AMOUNT; i++) {
if(employees[i].SALARY >= LSALARY & employees[i].SALARY <= HSALARY) {
System.out.println(employees[i]);
scan.close();}}
}
public static void main(String[] args) {
employeeCase EmployeeData = new employeeCase();
Scanner sc = new Scanner(System.in);
int Select = 0;
do {
displayMenu();
System.out.print("Input your selection from the menu: ");
Select = sc.nextInt();
switch (Select) {
case 1 : EmployeeData.loadEmployee();
break;
case 2 : EmployeeData.addEmployee();
break;
case 3 : EmployeeData.displayEmployee();
break;
case 4 : EmployeeData.retrieveSpecific();
break;
case 5 : EmployeeData.retrieveSalary();
break;
case 6 : System.out.println("Thank you, goodbye!");
break;
default : System.err.println("Invalid Input");
break;
}
} while (Select != 6);
sc.close();
}
public static void displayMenu() {
System.out.println(" MENU");
System.out.println("============================================");
System.out.println("1: Load employees' data");
System.out.println("2: Add new employee");
System.out.println("3: Display all employees");
System.out.println("4: Retrieve specfic employee data");
System.out.println("5: Retrieve employee based on salary range");
System.out.println("6: Exit program");
}
}}
Your main method needs to be static. Change public void main to public static void main.
Access modifier for main method should be static here you define a non static main method
Replace your main method with
public static void main(String[] args){}
So for this program I need to have three arrays accept data and display the gross pay, It seems to work at first but after enter the first person's data, my code begins to stack on top of itself in the window, please help me fix this to work properly.
I am required to use arrays. Objects are not allowed.
import java.util.Scanner;
public class ThreeArrays {
public static void main(String args[]) {
float[] payRate = new float[5];
float[] hours = new float[5];
String[] name = new String[5];
getPayData(name, hours, payRate);
displayGrossPay(name, hours, payRate);
}
public static void getPayData(String[] name, float[] hours, float[] payRate) {
Scanner kb = new Scanner(System.in);
for (int i = 0; i < hours.length; i++) {
System.out.print("Enter the employee's name: ");
name[i] = kb.nextLine();
System.out.print("Enter the employee's hours: ");
hours[i] = kb.nextFloat();
System.out.print("Enter the employee's hourly rate: ");
payRate[i] = kb.nextFloat();
}
}
public static void displayGrossPay(String[] name, float[] hours, float[] payRate) {
for (int i = 0; i < hours.length; i++) {
System.out.println("Employee name: " + name[i] + " Gross Pay: " + hours[i] *
payRate[i]);
}
}
}
Put System.out.println(); between each statement where you ask for data.
EDIT: It could also be that the \n character isn't being read with .nextInt(). To fix it, put kb.nextLine(); after kb.nextFloat();
for (int i = 0; i < hours.length; i++) {
System.out.print("Enter the employee's name: ");
name[i] = kb.nextLine();
System.out.println("");
System.out.print("Enter the employee's hours: ");
hours[i] = kb.nextFloat();
kb.nextLine();
System.out.println("");
System.out.print("Enter the employee's hourly rate: ");
payRate[i] = kb.nextFloat();
kb.nextLine();
System.out.println("");
}
// Enter the employee's name: Foo
// (Blank Line)
// Enter the employee's hours: 1
// (Blank Line)
// Enter the employee's hourly rate: -20.00 // They owe me now. :D
// (Blank Line)
The problem is related to stdin flushing. Because last entered float value for line payRate[i] = kb.nextFloat(); don't removes \n character. This \n character is being fetched by line name[i] = kb.nextLine(); in next iteration. Which further leaves a String value for line hours[i] = kb.nextFloat();. Since it is not a valid float hence you are getting exception: java.util.InputMismatchException.
To solve this use line if(i < hours.length-1) kb.next(); after line payRate[i] = kb.nextFloat();.
Following is corrected code. See complete working code here:
public class ThreeArrays {
public static void main(String args[]) {
float[] payRate = new float[5];
float[] hours = new float[5];
String[] name = new String[5];
getPayData(name, hours, payRate);
displayGrossPay(name, hours, payRate);
}
public static void getPayData(String[] name, float[] hours, float[] payRate) {
Scanner kb = new Scanner(System.in);
for (int i = 0; i < hours.length; i++) {
System.out.print("Enter the employee's name: ");
name[i] = kb.nextLine();
System.out.print("Enter the employee's hours: ");
hours[i] = kb.nextFloat();
System.out.print("Enter the employee's hourly rate: ");
payRate[i] = kb.nextFloat();
if(i < hours.length-1) kb.next();
}
}
public static void displayGrossPay(String[] name, float[] hours, float[] payRate) {
for (int i = 0; i < hours.length; i++) {
System.out.println("Employee name: " + name[i] + " Gross Pay: " + (hours[i] *
payRate[i]));
}
}
}
I have figured it out everyone
The problem lies with using
System.out.print("Enter the employee's name: ");
name[i] = kb.nextLine();
I had to change it to
System.out.print("Enter the employee's name: ");
name[i] = kb.next();
My program below prompts the user for how many children they have in their class. After entering the number they will enter all of the names of their students (first) and (last). Because of this I entered a scan Next Line statement instead of just scan.next. Because of this whatever number you enter the program will prompt you for one less. Please help.
public class studentRoster {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
String [] students;
int size;
System.out.println("Enter the amount of students in your class: ");
size = scan.nextInt();
students = new String[size];
for (int i = 0; i < students.length; i++ ){
System.out.println("Enter a student name: ");
students [i] = scan.next();
}
System.out.println("Student Roster");
for ( int i = 0; i < students.length; i++ ){
System.out.println(students[i]);
}
}
}
Using scan.next() only captures up to the first space encountered, so you'll want to use .nextLine() if the user is entering both the first and last name at the same time.
To make this code work, add scan.nextLine(); after you assign sizeto the user input. Then, change students [i] = scan.next(); to students [i] = scan.nextLine();.
The reason you need to do this is because .nextInt() doesn't take in the last newline of the user's input, so you need to call .nextLine() to account for that.
public class StudentRoster {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
String [] students;
int size;
System.out.print("Enter the amount of students in your class: ");
size = scan.nextInt();
scan.nextLine();
students = new String[size];
for (int i = 0; i < students.length; i++ ){
System.out.print("Enter a student name: ");
students [i] = scan.nextLine();
}
System.out.println("Student Roster");
for ( int i = 0; i < students.length; i++ ){
System.out.println(students[i]);
}
}
}
Test output
Enter the amount of students in your class: 4
Enter a student name: john Q
Enter a student name: albert E
Enter a student name: tyler D
Enter a student name: mickey M
Student Roster
john Q
albert E
tyler D
mickey M
the problem is this line
size = scan.nextInt();
becuase nextInt() method doesn't consume all the input buffer, it leaves the last (\n) character. When you call nextLine() after that it will not wait for the user to enter any thing but it will consume the (\n) character left in the buffer as a residue from the previous nextInt() method
so to correct this you have 2 options :
put additional scan.nextLine() directly after each scan.nextInt() method to consume the (\n)
size = scan.nextInt();
scan.nextLine();
students = new String[size];
//your code
Get the size as a string then convert it to int
String temp = scan.nextLine();
int size = Integer.parseInt(temp);
I suggest you to use an object better suited for your purpose (I think it's easier to hold data and improves readability):
import java.util.Scanner;
public class StudentRoster {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Student[] students;
int size;
String name;
String lastname;
System.out.println("Enter the amount of students in your class: ");
size = scan.nextInt();
students = new Student[size];
Student student;
for (int i = 0; i < students.length; i++) {
student = new Student();
System.out.println("Enter a student name: ");
name = scan.next();
System.out.println("Enter a student lastname: ");
lastname = scan.next();
student.setName(name);
student.setLastname(lastname);
students[i] = student;
}
System.out.println("Student Roster");
for (int i = 0; i < students.length; i++) {
System.out.println(students[i].getName());
System.out.println(students[i].getLastname());
}
}
static class Student {
String name;
String lastname;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
}
}
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?