SlideShare a Scribd company logo
1 of 7
Download to read offline
29. Code an application program that keeps track of student information at your college. Include
their names, identification numbers, and grade point averages in a fully encapsulated,
homogeneous sorted singly linked list structure. When launched, the user will be asked to input
the initial number of students and the initial data set. Once this is complete, the user will be
presented with the following menu: Enter: 1 to insert a new student's information, 2 to fetch and
output a student's information, 3 to delete a student's information, 4 to update a student's
information, 5 to output all the student information in sorted order, and 6 to exit the program.
The program should perform an unlimited number of operations until the user enters a 6 to exit
the program. If the user requests an operation on a node not in the structure, the program output
should be “node not in structure.” Otherwise, the message “operation complete” should be
output. in java
Solution
Dear Asker,
Following 3 classes consist the colution to this problem. This will give you an idea to approach
this problem:
//Student Class
package studentinfo;
public class Student implements Comparable {
private String name;
private String id;
private double gpa;
public Student(String id, String name, double gpa) {
this.name = name;
this.id = id;
this.gpa = gpa;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the gpa
*/
public double getGpa() {
return gpa;
}
/**
* @param gpa the gpa to set
*/
public void setGpa(double gpa) {
this.gpa = gpa;
}
@Override
public int compareTo(Student o) {
if (this.id.compareTo(o.id) < 0) {
return -1;
} else if (this.id.compareTo(o.id) > 0) {
return 1;
} else if (this.gpa < o.gpa) {
return -1;
} else if (this.gpa > o.gpa) {
return 1;
}
return 0;
}
public boolean equals(Student o) {
if (this.name == o.name && this.id == o.id && this.gpa == o.gpa) {
return true;
}
return false;
}
}
//Student container class
package studentinfo;
import java.util.Collections;
import java.util.LinkedList;
public class StudentContainer {
LinkedList studentList;
public StudentContainer() {
this.studentList = new LinkedList();
}
public boolean hasStudent(String id, String name, double gpa) {
return this.studentList.contains(new Student(id, name, gpa));
}
public boolean insertStudent(String id, String name, double gpa) {
if (!this.isValidString(id) || !this.isValidString(name) || !this.isValidGpa(gpa)) {
return false;
}
this.studentList.add(new Student(id, name, gpa));
return true;
}
public boolean deleteStudentById(String id) {
Student toRemove = null;
for (Student e : studentList) {
if (e.getId() == id) {
toRemove = e;
break;
}
}
if (toRemove != null) {
this.studentList.remove(toRemove);
return true;
}
return false;
}
public void printStudentById(String id) {
Student toRemove = this.getStudentById(id);
if (toRemove != null) {
this.printStudentInfo(toRemove);
} else {
System.out.println("No student node found");
}
}
public void updateStudentById(String id, String name, double gpa) {
Student s = this.getStudentById(id);
if (s != null) {
if (this.isValidGpa(gpa) && this.isValidString(name)) {
s.setGpa(gpa);
s.setName(name);
}
} else {
System.out.println("No student node found with id :" + id);
}
}
private boolean isValidGpa(double gpa) {
return gpa >= 0 && gpa <= 4;
}
private boolean isValidString(String s) {
return s != null && !"".equals(s);
}
private Student getStudentById(String id) {
for (Student e : studentList) {
if (e.getId().equals(id)) {
return e;
}
}
return null;
}
private void printStudentInfo(Student s) {
System.out.println("Student's info:"
+ " id " + s.getId()
+ " name " + s.getName()
+ " gpa " + s.getGpa());
}
public void printSortedList() {
if (!this.studentList.isEmpty()) {
Collections.sort(studentList);
studentList.forEach((e) -> {
this.printStudentInfo(e);
});
}
}
}
//StudentInfo class, containing the main method
package studentinfo;
import java.util.Scanner;
public class StudentInfo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
StudentContainer studentList = new StudentContainer();
int choice;
Scanner input = new Scanner(System.in);
do {
System.out.println("Please enter your choice (1-6): "
+ "1 to insert a new student's information, "
+ "2 to fetch and output a student's information, "
+ "3 to delete a student's information, "
+ "4 to update a student's information, "
+ "5 to output all the student information in sorted order, "
+ "6 to exit the program. ");
choice = input.nextInt();
String id, name;
double gpa;
switch (choice) {
case 1:
System.out.println("Enter Student's info (id, name and grade, in that order, on different
lines):");
id = input.next().trim();
name = input.next().trim();
gpa = input.nextDouble();
studentList.insertStudent(id, name, gpa);
break;
case 2:
System.out.println("Enter student id:");
id = input.next().trim();
studentList.printStudentById(id);
break;
case 3:
System.out.println("Enter student id:");
id = input.next().trim();
studentList.deleteStudentById(id);
break;
case 4:
System.out.println("Enter student id, new name and new gpa in that order, in different lines:");
id = input.next().trim();
name = input.next().trim();
gpa = input.nextDouble();
studentList.updateStudentById(id, name, gpa);
break;
case 5:
studentList.printSortedList();
break;
default:
break;
}
} while (choice != 6);
}
}

More Related Content

Similar to 29. Code an application program that keeps track of student informat.pdf

Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfforwardcom41
 
Assignment 7
Assignment 7Assignment 7
Assignment 7IIUM
 
Header #include -string- #include -vector- #include -iostream- using.pdf
Header #include -string- #include -vector- #include -iostream-   using.pdfHeader #include -string- #include -vector- #include -iostream-   using.pdf
Header #include -string- #include -vector- #include -iostream- using.pdfgaurav444u
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdffatoryoutlets
 
Refactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteRefactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteMariano Sánchez
 
Student.h #include stdafx.h #include string using names.pdf
Student.h #include stdafx.h #include string using names.pdfStudent.h #include stdafx.h #include string using names.pdf
Student.h #include stdafx.h #include string using names.pdffoottraders
 
Laporan Resmi Algoritma dan Struktur Data :
Laporan Resmi Algoritma dan Struktur Data : Laporan Resmi Algoritma dan Struktur Data :
Laporan Resmi Algoritma dan Struktur Data : Siska Amelia
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
05-OOP-Abstract Classes____________.pptx
05-OOP-Abstract Classes____________.pptx05-OOP-Abstract Classes____________.pptx
05-OOP-Abstract Classes____________.pptxpaautomation11
 

Similar to 29. Code an application program that keeps track of student informat.pdf (11)

Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
Assignment 7
Assignment 7Assignment 7
Assignment 7
 
Manual tecnic sergi_subirats
Manual tecnic sergi_subiratsManual tecnic sergi_subirats
Manual tecnic sergi_subirats
 
Header #include -string- #include -vector- #include -iostream- using.pdf
Header #include -string- #include -vector- #include -iostream-   using.pdfHeader #include -string- #include -vector- #include -iostream-   using.pdf
Header #include -string- #include -vector- #include -iostream- using.pdf
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
PHP OOP
PHP OOPPHP OOP
PHP OOP
 
Refactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteRefactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existente
 
Student.h #include stdafx.h #include string using names.pdf
Student.h #include stdafx.h #include string using names.pdfStudent.h #include stdafx.h #include string using names.pdf
Student.h #include stdafx.h #include string using names.pdf
 
Laporan Resmi Algoritma dan Struktur Data :
Laporan Resmi Algoritma dan Struktur Data : Laporan Resmi Algoritma dan Struktur Data :
Laporan Resmi Algoritma dan Struktur Data :
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
05-OOP-Abstract Classes____________.pptx
05-OOP-Abstract Classes____________.pptx05-OOP-Abstract Classes____________.pptx
05-OOP-Abstract Classes____________.pptx
 

More from arishaenterprises12

It was noted that excess water can kill plants. If water is not toxi.pdf
It was noted that excess water can kill plants. If water is not toxi.pdfIt was noted that excess water can kill plants. If water is not toxi.pdf
It was noted that excess water can kill plants. If water is not toxi.pdfarishaenterprises12
 
In biology, the roles of transition metal ions can be broadly groupe.pdf
In biology, the roles of transition metal ions can be broadly groupe.pdfIn biology, the roles of transition metal ions can be broadly groupe.pdf
In biology, the roles of transition metal ions can be broadly groupe.pdfarishaenterprises12
 
Image that a researcher examined how the people’s heights are associ.pdf
Image that a researcher examined how the people’s heights are associ.pdfImage that a researcher examined how the people’s heights are associ.pdf
Image that a researcher examined how the people’s heights are associ.pdfarishaenterprises12
 
I need help with this one Question 18 of 18 Sapling Learning macmill.pdf
I need help with this one Question 18 of 18 Sapling Learning macmill.pdfI need help with this one Question 18 of 18 Sapling Learning macmill.pdf
I need help with this one Question 18 of 18 Sapling Learning macmill.pdfarishaenterprises12
 
Explain how recombination increases the amount of genetic variation i.pdf
Explain how recombination increases the amount of genetic variation i.pdfExplain how recombination increases the amount of genetic variation i.pdf
Explain how recombination increases the amount of genetic variation i.pdfarishaenterprises12
 
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdfexclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdfarishaenterprises12
 
DNA is a macromolecule that is critical for life. Much of the functi.pdf
DNA is a macromolecule that is critical for life. Much of the functi.pdfDNA is a macromolecule that is critical for life. Much of the functi.pdf
DNA is a macromolecule that is critical for life. Much of the functi.pdfarishaenterprises12
 
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdfChapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdfarishaenterprises12
 
Discuss the benefits of event-driven programming.Contrast event-dr.pdf
Discuss the benefits of event-driven programming.Contrast event-dr.pdfDiscuss the benefits of event-driven programming.Contrast event-dr.pdf
Discuss the benefits of event-driven programming.Contrast event-dr.pdfarishaenterprises12
 
Before 1900, despite its weaknesses in effective management of worke.pdf
Before 1900, despite its weaknesses in effective management of worke.pdfBefore 1900, despite its weaknesses in effective management of worke.pdf
Before 1900, despite its weaknesses in effective management of worke.pdfarishaenterprises12
 
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdf
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdfAlpha particle radiation sensor. A silicon diode radiation sensor is .pdf
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdfarishaenterprises12
 
A ship was caught in a storm and driven to a small island in the mid.pdf
A ship was caught in a storm and driven to a small island in the mid.pdfA ship was caught in a storm and driven to a small island in the mid.pdf
A ship was caught in a storm and driven to a small island in the mid.pdfarishaenterprises12
 
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdfarishaenterprises12
 
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdfAs leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdfarishaenterprises12
 
Among 10 people traveling in a group, 2 have outdated passports. It .pdf
Among 10 people traveling in a group, 2 have outdated passports. It .pdfAmong 10 people traveling in a group, 2 have outdated passports. It .pdf
Among 10 people traveling in a group, 2 have outdated passports. It .pdfarishaenterprises12
 
1.) The normal eye color of Drosophila is red, but strains in which .pdf
1.) The normal eye color of Drosophila is red, but strains in which .pdf1.) The normal eye color of Drosophila is red, but strains in which .pdf
1.) The normal eye color of Drosophila is red, but strains in which .pdfarishaenterprises12
 
Write the code for a small function called myStack, which creates a .pdf
Write the code for a small function called myStack, which creates a .pdfWrite the code for a small function called myStack, which creates a .pdf
Write the code for a small function called myStack, which creates a .pdfarishaenterprises12
 
Why does the neutralization of an acid by a base often produce water.pdf
Why does the neutralization of an acid by a base often produce water.pdfWhy does the neutralization of an acid by a base often produce water.pdf
Why does the neutralization of an acid by a base often produce water.pdfarishaenterprises12
 
Which statement about phloem transport is falseIt takes place in .pdf
Which statement about phloem transport is falseIt takes place in .pdfWhich statement about phloem transport is falseIt takes place in .pdf
Which statement about phloem transport is falseIt takes place in .pdfarishaenterprises12
 
Which of the following is not a primitive data type Which of th.pdf
Which of the following is not a primitive data type Which of th.pdfWhich of the following is not a primitive data type Which of th.pdf
Which of the following is not a primitive data type Which of th.pdfarishaenterprises12
 

More from arishaenterprises12 (20)

It was noted that excess water can kill plants. If water is not toxi.pdf
It was noted that excess water can kill plants. If water is not toxi.pdfIt was noted that excess water can kill plants. If water is not toxi.pdf
It was noted that excess water can kill plants. If water is not toxi.pdf
 
In biology, the roles of transition metal ions can be broadly groupe.pdf
In biology, the roles of transition metal ions can be broadly groupe.pdfIn biology, the roles of transition metal ions can be broadly groupe.pdf
In biology, the roles of transition metal ions can be broadly groupe.pdf
 
Image that a researcher examined how the people’s heights are associ.pdf
Image that a researcher examined how the people’s heights are associ.pdfImage that a researcher examined how the people’s heights are associ.pdf
Image that a researcher examined how the people’s heights are associ.pdf
 
I need help with this one Question 18 of 18 Sapling Learning macmill.pdf
I need help with this one Question 18 of 18 Sapling Learning macmill.pdfI need help with this one Question 18 of 18 Sapling Learning macmill.pdf
I need help with this one Question 18 of 18 Sapling Learning macmill.pdf
 
Explain how recombination increases the amount of genetic variation i.pdf
Explain how recombination increases the amount of genetic variation i.pdfExplain how recombination increases the amount of genetic variation i.pdf
Explain how recombination increases the amount of genetic variation i.pdf
 
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdfexclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
exclange I ren peretr) ol and eleaced by the maxtit wadr Ho t Col pox.pdf
 
DNA is a macromolecule that is critical for life. Much of the functi.pdf
DNA is a macromolecule that is critical for life. Much of the functi.pdfDNA is a macromolecule that is critical for life. Much of the functi.pdf
DNA is a macromolecule that is critical for life. Much of the functi.pdf
 
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdfChapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
Chapter 7 , book Health in the Later Years, 5th EditionGive a his.pdf
 
Discuss the benefits of event-driven programming.Contrast event-dr.pdf
Discuss the benefits of event-driven programming.Contrast event-dr.pdfDiscuss the benefits of event-driven programming.Contrast event-dr.pdf
Discuss the benefits of event-driven programming.Contrast event-dr.pdf
 
Before 1900, despite its weaknesses in effective management of worke.pdf
Before 1900, despite its weaknesses in effective management of worke.pdfBefore 1900, despite its weaknesses in effective management of worke.pdf
Before 1900, despite its weaknesses in effective management of worke.pdf
 
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdf
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdfAlpha particle radiation sensor. A silicon diode radiation sensor is .pdf
Alpha particle radiation sensor. A silicon diode radiation sensor is .pdf
 
A ship was caught in a storm and driven to a small island in the mid.pdf
A ship was caught in a storm and driven to a small island in the mid.pdfA ship was caught in a storm and driven to a small island in the mid.pdf
A ship was caught in a storm and driven to a small island in the mid.pdf
 
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
8. List 4 GENERAL ways that a CELL, can DECREASE the rate of its rea.pdf
 
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdfAs leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
As leaf temperature increases from 20°C to 35°C, the quantum yield o.pdf
 
Among 10 people traveling in a group, 2 have outdated passports. It .pdf
Among 10 people traveling in a group, 2 have outdated passports. It .pdfAmong 10 people traveling in a group, 2 have outdated passports. It .pdf
Among 10 people traveling in a group, 2 have outdated passports. It .pdf
 
1.) The normal eye color of Drosophila is red, but strains in which .pdf
1.) The normal eye color of Drosophila is red, but strains in which .pdf1.) The normal eye color of Drosophila is red, but strains in which .pdf
1.) The normal eye color of Drosophila is red, but strains in which .pdf
 
Write the code for a small function called myStack, which creates a .pdf
Write the code for a small function called myStack, which creates a .pdfWrite the code for a small function called myStack, which creates a .pdf
Write the code for a small function called myStack, which creates a .pdf
 
Why does the neutralization of an acid by a base often produce water.pdf
Why does the neutralization of an acid by a base often produce water.pdfWhy does the neutralization of an acid by a base often produce water.pdf
Why does the neutralization of an acid by a base often produce water.pdf
 
Which statement about phloem transport is falseIt takes place in .pdf
Which statement about phloem transport is falseIt takes place in .pdfWhich statement about phloem transport is falseIt takes place in .pdf
Which statement about phloem transport is falseIt takes place in .pdf
 
Which of the following is not a primitive data type Which of th.pdf
Which of the following is not a primitive data type Which of th.pdfWhich of the following is not a primitive data type Which of th.pdf
Which of the following is not a primitive data type Which of th.pdf
 

Recently uploaded

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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Recently uploaded (20)

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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

29. Code an application program that keeps track of student informat.pdf

  • 1. 29. Code an application program that keeps track of student information at your college. Include their names, identification numbers, and grade point averages in a fully encapsulated, homogeneous sorted singly linked list structure. When launched, the user will be asked to input the initial number of students and the initial data set. Once this is complete, the user will be presented with the following menu: Enter: 1 to insert a new student's information, 2 to fetch and output a student's information, 3 to delete a student's information, 4 to update a student's information, 5 to output all the student information in sorted order, and 6 to exit the program. The program should perform an unlimited number of operations until the user enters a 6 to exit the program. If the user requests an operation on a node not in the structure, the program output should be “node not in structure.” Otherwise, the message “operation complete” should be output. in java Solution Dear Asker, Following 3 classes consist the colution to this problem. This will give you an idea to approach this problem: //Student Class package studentinfo; public class Student implements Comparable { private String name; private String id; private double gpa; public Student(String id, String name, double gpa) { this.name = name; this.id = id; this.gpa = gpa; } /** * @return the name */ public String getName() { return name; } /**
  • 2. * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the id */ public String getId() { return id; } /** * @param id the id to set */ public void setId(String id) { this.id = id; } /** * @return the gpa */ public double getGpa() { return gpa; } /** * @param gpa the gpa to set */ public void setGpa(double gpa) { this.gpa = gpa; } @Override public int compareTo(Student o) { if (this.id.compareTo(o.id) < 0) { return -1; } else if (this.id.compareTo(o.id) > 0) { return 1; } else if (this.gpa < o.gpa) {
  • 3. return -1; } else if (this.gpa > o.gpa) { return 1; } return 0; } public boolean equals(Student o) { if (this.name == o.name && this.id == o.id && this.gpa == o.gpa) { return true; } return false; } } //Student container class package studentinfo; import java.util.Collections; import java.util.LinkedList; public class StudentContainer { LinkedList studentList; public StudentContainer() { this.studentList = new LinkedList(); } public boolean hasStudent(String id, String name, double gpa) { return this.studentList.contains(new Student(id, name, gpa)); } public boolean insertStudent(String id, String name, double gpa) { if (!this.isValidString(id) || !this.isValidString(name) || !this.isValidGpa(gpa)) { return false; } this.studentList.add(new Student(id, name, gpa)); return true; } public boolean deleteStudentById(String id) { Student toRemove = null; for (Student e : studentList) { if (e.getId() == id) {
  • 4. toRemove = e; break; } } if (toRemove != null) { this.studentList.remove(toRemove); return true; } return false; } public void printStudentById(String id) { Student toRemove = this.getStudentById(id); if (toRemove != null) { this.printStudentInfo(toRemove); } else { System.out.println("No student node found"); } } public void updateStudentById(String id, String name, double gpa) { Student s = this.getStudentById(id); if (s != null) { if (this.isValidGpa(gpa) && this.isValidString(name)) { s.setGpa(gpa); s.setName(name); } } else { System.out.println("No student node found with id :" + id); } } private boolean isValidGpa(double gpa) { return gpa >= 0 && gpa <= 4; } private boolean isValidString(String s) { return s != null && !"".equals(s); } private Student getStudentById(String id) {
  • 5. for (Student e : studentList) { if (e.getId().equals(id)) { return e; } } return null; } private void printStudentInfo(Student s) { System.out.println("Student's info:" + " id " + s.getId() + " name " + s.getName() + " gpa " + s.getGpa()); } public void printSortedList() { if (!this.studentList.isEmpty()) { Collections.sort(studentList); studentList.forEach((e) -> { this.printStudentInfo(e); }); } } } //StudentInfo class, containing the main method package studentinfo; import java.util.Scanner; public class StudentInfo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here StudentContainer studentList = new StudentContainer(); int choice; Scanner input = new Scanner(System.in); do { System.out.println("Please enter your choice (1-6): "
  • 6. + "1 to insert a new student's information, " + "2 to fetch and output a student's information, " + "3 to delete a student's information, " + "4 to update a student's information, " + "5 to output all the student information in sorted order, " + "6 to exit the program. "); choice = input.nextInt(); String id, name; double gpa; switch (choice) { case 1: System.out.println("Enter Student's info (id, name and grade, in that order, on different lines):"); id = input.next().trim(); name = input.next().trim(); gpa = input.nextDouble(); studentList.insertStudent(id, name, gpa); break; case 2: System.out.println("Enter student id:"); id = input.next().trim(); studentList.printStudentById(id); break; case 3: System.out.println("Enter student id:"); id = input.next().trim(); studentList.deleteStudentById(id); break; case 4: System.out.println("Enter student id, new name and new gpa in that order, in different lines:"); id = input.next().trim(); name = input.next().trim(); gpa = input.nextDouble(); studentList.updateStudentById(id, name, gpa); break; case 5: