This is the question:
These are in Java format.
Comments are required on these two Classes (Student.java and StudentDemo.java) all over the coding:
Provide proper comments all over the codings.
---------------------------------------------------------------------------------------------------------------
import java.io.*;
import java.util.*;
class Student {
private String name;
private double gradePointAverage;
public Student(String n , double a){
name = n;
gradePointAverage = a;
}
public String getName(){
return name;
}
public double getGradePointAverage(){
return gradePointAverage;
}
public void setName(String n){
name = n;
}
public void setGradePointAverage(double a){
gradePointAverage = a;
}
}
----------------------------------------------------------------------------------------------------------------
import java.util.ArrayList;
import java.util.Scanner;
public class StudentDemo{
public static ArrayList<Student>
sort(ArrayList<Student> list){
ArrayList<Student> list1 = new
ArrayList<Student>();
for (int i = 0; i<list.size(); i++){
int index = -1;
for (int j = 0; j< list1.size(); j++){
if (list.get(i).getGradePointAverage() >
list1.get(j).getGradePointAverage()){
index = j;
list1.add(j,list.get(i));
break;
}
}
if (index == -1)
list1.add(list.get(i));
}
return list1;
}
public static void main(String[] args){
ArrayList<Student> list = new
ArrayList<Student>();
Scanner sc = new Scanner(System.in);
while(true){
System.out.print("Enter student name or quit:");
String name = sc.nextLine();
if (name.equals("quit"))
break;
System.out.print("Enter grade point ave:");
double gpa = Double.parseDouble(sc.nextLine());
Student st = new Student(name,gpa);
int index = -1;
for (int i = 0; i< list.size(); i++){
if (name.compareTo(list.get(i).getName()) < 0){
index = i;
list.add(i,st);
break;
}
}
if (index == -1)
list.add(st);
}
System.out.println("Students:");
System.out.print("[ ");
for (int i = 0; i<list.size(); i++){
if (i < list.size() -1)
System.out.print(list.get(i).getName() + " Grade Point Avg:" +
list.get(i).getGradePointAverage() + ",");
else
System.out.print(list.get(i).getName() + " Grade Point Avg:" +
list.get(i).getGradePointAverage());
}
System.out.println(" ]");
list = sort(list);
System.out.println("Students in order of Grade Point
Average:");
System.out.print("[ ");
for (int i = 0; i<list.size(); i++){
if (i < list.size() -1)
System.out.print(list.get(i).getName() + " Grade Point Avg:" +
list.get(i).getGradePointAverage() + ",");
else
System.out.print(list.get(i).getName() + " Grade Point Avg:" +
list.get(i).getGradePointAverage());
}
System.out.println(" ]");
}
}
Student.java
public class Student {
//Declaring instance variables
private String name;
private double gradePointAverage;
//Parameterized constructor
public Student(String n , double a){
name = n;
gradePointAverage = a;
}
// getters and setters
public String getName(){
return name;
}
public double getGradePointAverage(){
return gradePointAverage;
}
public void setName(String n){
name = n;
}
public void setGradePointAverage(double a){
gradePointAverage = a;
}
}
_________________
StudentDemo.java
import java.util.ArrayList;
import java.util.Scanner;
public class StudentDemo{
public static ArrayList<Student> sort(ArrayList<Student> list){
//Creating an ArrayList Which holds Student Objects
ArrayList<Student> list1 = new ArrayList<Student>();
/* This nested for loop will sort the ArrayList which holds
* Students based on Student grade Point in Ascending order
*/
for (int i = 0; i<list.size(); i++){
int index = -1;
for (int j = 0; j< list1.size(); j++){
if (list.get(i).getGradePointAverage() > list1.get(j).getGradePointAverage()){
index = j;
list1.add(j,list.get(i));
break;
}
}
if (index == -1)
list1.add(list.get(i));
}
return list1;
}
public static void main(String[] args){
ArrayList<Student> list = new ArrayList<Student>();
Scanner sc = new Scanner(System.in);
/* This while loop continues to execute
* until the user enters "quit"
*/
while(true){
//Getting the name entered by the user
System.out.print("Enter student name or quit:");
String name = sc.nextLine();
//checking whether user enters "quit" or not
if (name.equals("quit"))
break;
//Getting the grade entered by the user
System.out.print("Enter grade point ave:");
double gpa = Double.parseDouble(sc.nextLine());
/* Creating the Student Object parameterized constructor
* by passing the name and student average passing as arguments
*/
Student st = new Student(name,gpa);
int index = -1;
//Sorting the array List based on user entered name
for (int i = 0; i< list.size(); i++){
if (name.compareTo(list.get(i).getName()) < 0){
index = i;
list.add(i,st);
break;
}
}
if (index == -1)
list.add(st);
}
//Displaying the Student objects Before Sorting based on Student average in decending order
System.out.println("Students:");
System.out.print("[ ");
for (int i = 0; i<list.size(); i++){
if (i < list.size() -1)
System.out.print(list.get(i).getName() + " Grade Point Avg:" + list.get(i).getGradePointAverage() + ",");
else
System.out.print(list.get(i).getName() + " Grade Point Avg:" + list.get(i).getGradePointAverage());
}
System.out.println(" ]");
//calling the sort method
list = sort(list);
System.out.println("Students in order of Grade Point Average:");
System.out.print("[ ");
//Displaying the Student objects after Sorting based on Student average in decending order
for (int i = 0; i<list.size(); i++){
if (i < list.size() -1)
System.out.print(list.get(i).getName() + " Grade Point Avg:" + list.get(i).getGradePointAverage() + ",");
else
System.out.print(list.get(i).getName() + " Grade Point Avg:" + list.get(i).getGradePointAverage());
}
System.out.println(" ]");
}
}
____________________
Output:
Enter student name or quit:Williams
Enter grade point ave:89.00
Enter student name or quit:John
Enter grade point ave:78.00
Enter student name or quit:Kevin
Enter grade point ave:92.00
Enter student name or quit:Mike
Enter grade point ave:65.00
Enter student name or quit:Rahul
Enter grade point ave:79.00
Enter student name or quit:Vivek
Enter grade point ave:94.00
Enter student name or quit:quit
Students:
[ John Grade Point Avg:78.0,Kevin Grade Point Avg:92.0,Mike Grade
Point Avg:65.0,Rahul Grade Point Avg:79.0,Vivek Grade Point
Avg:94.0,Williams Grade Point Avg:89.0 ]
Students in order of Grade Point Average:
[ Vivek Grade Point Avg:94.0,Kevin Grade Point Avg:92.0,Williams
Grade Point Avg:89.0,Rahul Grade Point Avg:79.0,John Grade Point
Avg:78.0,Mike Grade Point Avg:65.0 ]
______________Thank You
This is the question: These are in Java format. Comments are required on these two Classes...
In Java, Please do not forget the ToString method in the Student class! In this exercise, you will first create a Student class. A Student has two attributes: name (String) and gradePointAverage (double). The class has a constructor that sets the name and grade point average of the Student. It has appropriate get and set methods. As well, there is a toString method that prints the student's name and their grade point average (highest is 4.0) You will then write...
java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...
Look for some finshing touches java help with this program. I just two more things added to this code. A loop at the end that will ask the user if they want to quit if they do want to quit the program stops if they don't it loads a new number sequence. import java.util.Random; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; import java.util.List; import java.util.Collections; public class main { public static void main(String[] args) { List < Sequence > list =...
please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the program is supposed to read from my input file and do the following 1) print out the original data in the file without doing anything to it. 2) an ordered list of all students names (last names) alphabetically and the average GPA of all student togther . 3) freshman list in alphabeticalorder by last name with the average GPA of the freshmen...
Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...
Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....
Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...