JAVA HELP FOR COMP:
Can someone please modify the code to create LowestGPA.java that prints out the name of the student with the lowestgpa.
In the attached zip file, you will find two files HighestGPA.java and students.dat. Students.dat file contains names of students and their gpa. Check if the code runs correctly in BlueJ or any other IDE by running the code. Modify the data to include few more students and their gpa.
import java.util.*; // for the Scanner class
import java.io.*; // for the File class
public class HighestGPA
{
public static void main (String[ ] args) throws
FileNotFoundException
{
new HighestGPA().run();
} // method main
public void run() throws FileNotFoundException
{
final double NEGATIVE_GPA = -1.0;
final String NO_VALID_INPUT =
"Error: the given file has no valid input.";
final String BEST_MESSAGE =
"\n\nThe student with the highest grade point average is ";
Scanner fileScanner = new Scanner (new File ("students.dat"));
String name,
bestStudent = null;
double gpa,
highestGPA = NEGATIVE_GPA;
while (fileScanner.hasNextLine())
{
Scanner lineScanner = new Scanner (fileScanner.nextLine());
name = lineScanner.next();
gpa = lineScanner.nextDouble();
if (gpa > highestGPA)
{
highestGPA = gpa;
bestStudent = name;
} // if
} // while
if (highestGPA == NEGATIVE_GPA)
System.out.println (NO_VALID_INPUT);
else
System.out.println (BEST_MESSAGE + bestStudent);
} // method run
} // class HighestGPA
Students.dat file:
Larry 3.3
Curly 3.7
Moe 3.2
import java.util.*; // for the Scanner class
import java.io.*; // for the File class
// Defines class LowestGPA
public class LowestGPA
{
// main method definition
public static void main (String[ ] args) throws FileNotFoundException
{
// Creates an anonymous object of the class LowestGPA and calls the run() method
new LowestGPA().run();
} // End of method main
// Method to find and display the lowest GPA student name
public void run() throws FileNotFoundException
{
// Creates a constant to store maximum double value
final double MAX_GPA = Double.MAX_VALUE;
// Creates a string constant to store error message for file
final String NO_VALID_INPUT = "Error: the given file has no valid input.";
// Creates a string constant to store message for student
final String BEST_MESSAGE = "\n\nThe student with the lowest grade point average is ";
// Creates a string constant to store message for student GPA
final String GPA_MESSAGE = " having GAP: ";
// Creates an object of the Scanner class to open the file for reading
Scanner fileScanner = new Scanner (new File ("students.dat"));
// To store the name read from file and poor student name
String name, poorStudent = null;
// To store the GPA read from file and lowest GPA is assigned to maximum double value constant
double gpa, lowestGPA = MAX_GPA;
// To store the record read from file
Scanner lineScanner = null;
// Loops till end of the file
while (fileScanner.hasNextLine())
{
// Reads a record from file
lineScanner = new Scanner (fileScanner.nextLine());
// Extracts student name
name = lineScanner.next();
// Extracts student GPA
gpa = lineScanner.nextDouble();
// Checks if current GPA read from file is less than the earlier lowestGPA
if (gpa < lowestGPA)
{
// Update the GPA by assigning the current GPA read from the file to lowestGAP
lowestGPA = gpa;
// Update the poor student name by assigning the current student name
// read from the file to poorStudent
poorStudent = name;
} // End of if condition
} // End of while loop
fileScanner.close();
// Checks if lowestGPA is equals to constant MAX_GPA then display the constant error message
if (lowestGPA == MAX_GPA)
System.out.println (NO_VALID_INPUT);
// Otherwise
else
// Display the constant message for student with poor student name with
// GPA constant message with lowest GAP
System.out.println (BEST_MESSAGE + poorStudent + GPA_MESSAGE + lowestGPA);
} // End of method run
} // End of class LowestGPA
Sample Output:
The student with the lowest grade point average is Rita having GAP: 3.1
Students.dat file contents:
Larry 3.3
Curly 3.7
Moe 3.2
Anil 8.2
Sunil 4.5
Rita 3.1
Gita 7.7
JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out...
Please provide the full code...the skeleton is down below: Note: Each file must contain an int at the beginning, stating the number of records in the file. Afterwards, the number of records in the file will follow. Each record that follows will consist of a last name (String), and a gpa (double). However, to test the error handling of your program, the number of records will not always match the int value. All possible combinations should be tested. 1.) Prompt...
Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...
Modify your program in Lab Assignment 4A to throw an exception if the file does not exist. An error message should result. Use the same file name in your program as 4A, however, use the new input file in 4B assignment dropbox. My code: import java.io.*; import java.util.*; public class Lab4B { public static void main(String[] args) throws IOException { final String input_file = "Lab_4A.txt"; final String output_file = "Lab_4A.txt"; Scanner x = null; FileWriter y = null; try {...
Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...
JAVA program Note: you can't change anything is already written Student.java public class Student { private String name; private String major; private double gpa; public Student(String name, String major, double gpa) { // TO-DO: Assign the given parameters to the data fields. Use the this keyword. } public double getGPA() { // TO-DO: return this.gpa } public String getName() { // TO-DO: return this.name }...
JAVA Modify the code to create a class called box, wherein you find the area. I have the code in rectangle and needs to change it to box. Here is my code. Rectangle.java public class Rectangle { private int length; private int width; public void setRectangle(int length, int width) { this.length = length; this.width = width; } public int area() { return this.length * this.width; } } // CONSOLE / MAIN import java.awt.Rectangle; import java.util.Scanner; public class Console...
Please, modify the code below to use the Switch Statements in Java instead of “if” statements to make the decisions. import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter code(C for circle, R for rectangle, S for square): "); char code = in.next().charAt(0); if(code == 'C') { System.out.print("Enter radius: "); double radius = in.nextDouble(); System.out.println("Area of circle is " + (Math.PI * radius * radius)); } else if(code == 'R') {...
How to write a Java file out that that reads from numbers.txt with these numbers 2 6 7 9 5 4 3 8 0 1 6 8 2 3 and write to a file called totalSum.txt that looks like: 2+6+7+9=24 and so on using this code import java.io.*; import java.util.Scanner; public class FileScanner { public static void main(String[] args) { /* For Homework! Tokens*/ Scanner file = null; PrintWriter fout= null; ...
Java : Please help me correct my code: create a single class (Program11.java) with a main method and some auxiliary methods to input a 2-D array from a disk file, input some “transactions” to change the 2-D array and output the changed 2-D array to another file. Your main method will be minimal (see below). Most of the work will go on in your methods. In main, declare (but do not instantiate) 2-D array. Then call the three methods. The...
FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...