SlideShare a Scribd company logo
1 of 9
Download to read offline
I'm getting 'List Full' when I try to add 2nd student.
//Driver.java
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
new Driver();
}
public Driver() {
Scanner input = new Scanner(System.in);
Student[] newStudent = new Student[3];
System.out.println("Select option below");
System.out.println("");
while(true) {
System.out.println("1: Add Student");
System.out.println("2: Display Student");
System.out.println("3: Exit");
int userChoice = input.nextInt();
switch(userChoice) {
case 1:
addStudent(newStudent);
break;
case 2:
displayStudent(newStudent);
break;
case 3:
System.out.println("Exit");
System.exit(3);
}
}
}
//Student[] newStudent = new Student[3];
//Flower[] flowerPack = new Flower[25];
private void addStudent(Student[] newStudent) {
Scanner input = new Scanner(System.in);
String FirstName, LastName;
double GPA;
System.out.print("Enter First Name: ");
FirstName = input.nextLine();
System.out.print("Enter Last Name: ");
LastName = input.nextLine();
System.out.print("Enter GPA: ");
GPA = input.nextDouble();
for(int i = 0; i < 3; i++) {
if(newStudent[i] == null) {
newStudent[i] = new Student(FirstName, LastName, GPA);
break;
} else if(newStudent[i] != null) {
System.out.println("List Full");
break;
}
}
}
private void displayStudent(Student[] newStudent) {
int x = 0;
for(int i = 0; i < 3; i++) {
if(newStudent[i] != null)
System.out.println(newStudent[i].toString());
else
x++;
}
if(newStudent == null)
System.out.println("no record");
}
}
//Student.java
import java.util.Scanner;
public class Student {
private String FirstName;
private String LastName;
private double GPA;
public Student(String FirstName, String LastName, double GPA) {
this.FirstName = FirstName;
this.LastName = LastName;
this.GPA = GPA;
}
public Student() {
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String FirstName) {
FirstName = FirstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String LastName) {
LastName = LastName;
}
public double getGPA() {
return GPA;
}
public void setGPA(double GPA) {
GPA = GPA;
}
public String toString() {
return "First Name: " + FirstName + " Last Name: " + LastName
+ " GPA: " + GPA;
}
}
Solution
Note
This application will adds only 3 students data.And Dislpay those 3 students data.
I just modified some code which rectifies your problem.Thank You
___________________
Driver.java
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
new Driver();
}
public Driver() {
Scanner input = new Scanner(System.in);
Student[] newStudent = new Student[3];
System.out.println("Select option below");
System.out.println("");
while(true) {
System.out.println("1: Add Student");
System.out.println("2: Display Student");
System.out.println("3: Exit");
int userChoice = input.nextInt();
switch(userChoice) {
case 1:
addStudent(newStudent);
break;
case 2:
displayStudent(newStudent);
break;
case 3:
System.out.println("Exit");
System.exit(3);
}
}
}
private void addStudent(Student[] newStudent) {
Scanner input = new Scanner(System.in);
String FirstName, LastName;
double GPA;
System.out.print("Enter First Name: ");
FirstName = input.nextLine();
System.out.print("Enter Last Name: ");
LastName = input.nextLine();
System.out.print("Enter GPA: ");
GPA = input.nextDouble();
for(int i = 0; i < 3; i++) {
if(newStudent[i] == null) {
newStudent[i] = new Student(FirstName, LastName, GPA);
if(newStudent[2] != null)
System.out.println("List Full");
break;
}
}
}
private void displayStudent(Student[] newStudent) {
int x = 0;
for(int i = 0; i < 3; i++) {
if(newStudent[i] != null)
System.out.println(newStudent[i].toString());
else if(newStudent[0] == null)
{
System.out.println("no record");
break;
}
}
}
}
____________________
Student.java
public class Student {
private String FirstName;
private String LastName;
private double GPA;
public Student(String FirstName, String LastName, double GPA) {
this.FirstName = FirstName;
this.LastName = LastName;
this.GPA = GPA;
}
public Student() {
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String FirstName) {
FirstName = FirstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String LastName) {
LastName = LastName;
}
public double getGPA() {
return GPA;
}
public void setGPA(double GPA) {
GPA = GPA;
}
public String toString() {
return "First Name: " + FirstName + " Last Name: " + LastName
+ " GPA: " + GPA;
}
}
_______________________
Output:
Select option below
1: Add Student
2: Display Student
3: Exit
1
Enter First Name: Kane
Enter Last Name: Williams
Enter GPA: 8.8
1: Add Student
2: Display Student
3: Exit
1
Enter First Name: Ryan
Enter Last Name: Harris
Enter GPA: 7.8
1: Add Student
2: Display Student
3: Exit
1
Enter First Name: Paul
Enter Last Name: Thomson
Enter GPA: 6.5
List Full
1: Add Student
2: Display Student
3: Exit
2
First Name: Kane
Last Name: Williams
GPA: 8.8
First Name: Ryan
Last Name: Harris
GPA: 7.8
First Name: Paul
Last Name: Thomson
GPA: 6.5
1: Add Student
2: Display Student
3: Exit
3
Exit
____________thank you

More Related Content

Similar to Im getting List Full when I try to add 2nd student.Driver..pdf

Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Java Program I keep receiving the following error in my code- Can you.pdf
Java Program I keep receiving the following error in my code- Can you.pdfJava Program I keep receiving the following error in my code- Can you.pdf
Java Program I keep receiving the following error in my code- Can you.pdfRyanF2PLeev
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming AssignmentCoding Assignment Help
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...Nithin Kumar,VVCE, Mysuru
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfAnkitchhabra28
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfkostikjaylonshaewe47
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfrajat630669
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfrajat630669
 
import java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfimport java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfanupamagarud8
 

Similar to Im getting List Full when I try to add 2nd student.Driver..pdf (15)

Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Java Program I keep receiving the following error in my code- Can you.pdf
Java Program I keep receiving the following error in my code- Can you.pdfJava Program I keep receiving the following error in my code- Can you.pdf
Java Program I keep receiving the following error in my code- Can you.pdf
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
 
import java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfimport java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdf
 
Lab 3
Lab 3Lab 3
Lab 3
 

More from forwardcom41

Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfHello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfforwardcom41
 
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfHey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfforwardcom41
 
Given technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfGiven technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfforwardcom41
 
Explain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfExplain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfforwardcom41
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfforwardcom41
 
Complete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfComplete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfforwardcom41
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfforwardcom41
 
Describe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfDescribe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfforwardcom41
 
Why is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfWhy is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfforwardcom41
 
What are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfWhat are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfforwardcom41
 
What is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfWhat is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfforwardcom41
 
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfw Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfforwardcom41
 
Which of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfWhich of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfforwardcom41
 
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfUsing the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfforwardcom41
 
why we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfwhy we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfforwardcom41
 
What property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfWhat property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfforwardcom41
 
What is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfWhat is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfforwardcom41
 
What is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfWhat is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfforwardcom41
 
What are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfWhat are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfforwardcom41
 
Use the following information to answer the next Question. The graph.pdf
Use the following information to answer the next Question.  The graph.pdfUse the following information to answer the next Question.  The graph.pdf
Use the following information to answer the next Question. The graph.pdfforwardcom41
 

More from forwardcom41 (20)

Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdfHello!Can someone help me to answer Task4 and Task7Complete T.pdf
Hello!Can someone help me to answer Task4 and Task7Complete T.pdf
 
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfHey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
 
Given technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfGiven technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdf
 
Explain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfExplain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdf
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
 
Complete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfComplete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdf
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
Describe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfDescribe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdf
 
Why is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfWhy is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdf
 
What are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfWhat are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdf
 
What is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfWhat is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdf
 
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfw Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
 
Which of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfWhich of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdf
 
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfUsing the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
 
why we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfwhy we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdf
 
What property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfWhat property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdf
 
What is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfWhat is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdf
 
What is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfWhat is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdf
 
What are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfWhat are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdf
 
Use the following information to answer the next Question. The graph.pdf
Use the following information to answer the next Question.  The graph.pdfUse the following information to answer the next Question.  The graph.pdf
Use the following information to answer the next Question. The graph.pdf
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 

Im getting List Full when I try to add 2nd student.Driver..pdf

  • 1. I'm getting 'List Full' when I try to add 2nd student. //Driver.java import java.util.Scanner; public class Driver { public static void main(String[] args) { new Driver(); } public Driver() { Scanner input = new Scanner(System.in); Student[] newStudent = new Student[3]; System.out.println("Select option below"); System.out.println(""); while(true) { System.out.println("1: Add Student"); System.out.println("2: Display Student"); System.out.println("3: Exit"); int userChoice = input.nextInt(); switch(userChoice) { case 1: addStudent(newStudent); break; case 2: displayStudent(newStudent); break; case 3: System.out.println("Exit"); System.exit(3); } }
  • 2. } //Student[] newStudent = new Student[3]; //Flower[] flowerPack = new Flower[25]; private void addStudent(Student[] newStudent) { Scanner input = new Scanner(System.in); String FirstName, LastName; double GPA; System.out.print("Enter First Name: "); FirstName = input.nextLine(); System.out.print("Enter Last Name: "); LastName = input.nextLine(); System.out.print("Enter GPA: "); GPA = input.nextDouble(); for(int i = 0; i < 3; i++) { if(newStudent[i] == null) { newStudent[i] = new Student(FirstName, LastName, GPA); break; } else if(newStudent[i] != null) { System.out.println("List Full"); break; } } } private void displayStudent(Student[] newStudent) { int x = 0; for(int i = 0; i < 3; i++) { if(newStudent[i] != null) System.out.println(newStudent[i].toString()); else x++; }
  • 3. if(newStudent == null) System.out.println("no record"); } } //Student.java import java.util.Scanner; public class Student { private String FirstName; private String LastName; private double GPA; public Student(String FirstName, String LastName, double GPA) { this.FirstName = FirstName; this.LastName = LastName; this.GPA = GPA; } public Student() { } public String getFirstName() { return FirstName; } public void setFirstName(String FirstName) { FirstName = FirstName; } public String getLastName() { return LastName; }
  • 4. public void setLastName(String LastName) { LastName = LastName; } public double getGPA() { return GPA; } public void setGPA(double GPA) { GPA = GPA; } public String toString() { return "First Name: " + FirstName + " Last Name: " + LastName + " GPA: " + GPA; } } Solution Note This application will adds only 3 students data.And Dislpay those 3 students data. I just modified some code which rectifies your problem.Thank You ___________________ Driver.java import java.util.Scanner; public class Driver { public static void main(String[] args) { new Driver(); } public Driver() { Scanner input = new Scanner(System.in); Student[] newStudent = new Student[3]; System.out.println("Select option below");
  • 5. System.out.println(""); while(true) { System.out.println("1: Add Student"); System.out.println("2: Display Student"); System.out.println("3: Exit"); int userChoice = input.nextInt(); switch(userChoice) { case 1: addStudent(newStudent); break; case 2: displayStudent(newStudent); break; case 3: System.out.println("Exit"); System.exit(3); } } } private void addStudent(Student[] newStudent) { Scanner input = new Scanner(System.in); String FirstName, LastName; double GPA; System.out.print("Enter First Name: "); FirstName = input.nextLine(); System.out.print("Enter Last Name: "); LastName = input.nextLine(); System.out.print("Enter GPA: "); GPA = input.nextDouble(); for(int i = 0; i < 3; i++) {
  • 6. if(newStudent[i] == null) { newStudent[i] = new Student(FirstName, LastName, GPA); if(newStudent[2] != null) System.out.println("List Full"); break; } } } private void displayStudent(Student[] newStudent) { int x = 0; for(int i = 0; i < 3; i++) { if(newStudent[i] != null) System.out.println(newStudent[i].toString()); else if(newStudent[0] == null) { System.out.println("no record"); break; } } } } ____________________ Student.java public class Student { private String FirstName; private String LastName; private double GPA; public Student(String FirstName, String LastName, double GPA) { this.FirstName = FirstName; this.LastName = LastName; this.GPA = GPA;
  • 7. } public Student() { } public String getFirstName() { return FirstName; } public void setFirstName(String FirstName) { FirstName = FirstName; } public String getLastName() { return LastName; } public void setLastName(String LastName) { LastName = LastName; } public double getGPA() { return GPA; } public void setGPA(double GPA) { GPA = GPA; } public String toString() { return "First Name: " + FirstName + " Last Name: " + LastName + " GPA: " + GPA; } } _______________________
  • 8. Output: Select option below 1: Add Student 2: Display Student 3: Exit 1 Enter First Name: Kane Enter Last Name: Williams Enter GPA: 8.8 1: Add Student 2: Display Student 3: Exit 1 Enter First Name: Ryan Enter Last Name: Harris Enter GPA: 7.8 1: Add Student 2: Display Student 3: Exit 1 Enter First Name: Paul Enter Last Name: Thomson Enter GPA: 6.5 List Full 1: Add Student 2: Display Student 3: Exit 2 First Name: Kane Last Name: Williams GPA: 8.8 First Name: Ryan Last Name: Harris GPA: 7.8 First Name: Paul Last Name: Thomson
  • 9. GPA: 6.5 1: Add Student 2: Display Student 3: Exit 3 Exit ____________thank you