You are to develop a program that will store names and grades of students in a l
ID: 3715236 • Letter: Y
Question
You are to develop a program that will store names and grades of students in a linked list. You are to prompt the user for the number of students in the class. Use the class size to determine how many names and grades to accept as input. Store the names and grades in a linked list.
Create two files to submit.
StudentNode.java - contains the class declaration
ClassLinkedList.java - contains the main() method
Build the StudentNode class per the following specifications.
Private fields
String name - Initialized to empty string in default constructor
double courseAvg - Initialized to 0 in default constructor
StudentNode nextNodePtr - Initialized to null in default constructor
public StudentNode() - Default constructor which sets private fields as specified above
public StudentNode(String name, double courseAvg) - Parameterized constructor
Public member methods
public void insertAfter(StudentNode nodeLoc) - Inserts the nodeLoc student object between this and next student objects
public StudentNode getNext() - returns the object pointed to by nextNodePtr
public void printNodeData() - prints the name and average for a single student
In your main method, inform the user the purpose of the program and then prompt the user for a class size. You should then input a name and corresponding grade for the number of students specified. As student names and grades are read in, the data should be stored in a linked list.
Sample program input and output:
This program will store class data (names and grades) in a linked list How many students are in the class? 3 Enter a name for student 1: Jane Smith Enter the course grade for Jane Smith: 100 Enter a name for student 2: Pat Jones Enter the course grade for Pat Jones:90 Enter a name for student 3: Juan Lopez Enter the course grade for Juan Lopez: 95 Linked list of students and grades Jane Smith: 100.0 Pat Jones: 9 Juan Lopez: 95.0 0.0Explanation / Answer
package com.logicboxes.timepass; import java.util.Scanner; //StudentNode.java class StudentNode { private String name; private double courseAvg; private StudentNode nextNodePtr; public StudentNode() { name=null; courseAvg=0; nextNodePtr=null; } public StudentNode(String name,double courseAvg) { this.name=name; this.courseAvg=courseAvg; } public void insertAfter(StudentNode nodeLoc) { nodeLoc.nextNodePtr=this.nextNodePtr; this.nextNodePtr=nodeLoc; } public StudentNode getNext() { return this.nextNodePtr; } public void printNodeData() { System.out.println("name="+this.name+" average="+this.courseAvg); } } //ClassLinkedList.java public class ClassLinkedList { public static void main(String[] args) { System.out.println("This program will store class data(names and grades) in a linked list"); System.out.println("How many students in class?"); int classSize; String name; double courseAvg; StudentNode curr,prev,head=new StudentNode(); prev=head; Scanner s=new Scanner(System.in); classSize=s.nextInt(); for(int i=1;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.