Question
need number 4 in JAVA 3. Storing a Student Create a class named Student which contains student information. Specifically, create three variables: name, grade, and
need number 4 in JAVA 3. Storing a Student Create a class named Student which contains student information. Specifically, create three variables: name, grade, and gpa. Create an instance of type Student and read the values from user input. Create three files on your desktop named: names, grades, and gpas. Store the information from this Student in those files. (name stored in names, grade => grades, gpa => gpas) Here is my soltion for number 3:
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Student {
static String name;
static int grade;
static double gpa;
static boolean exit = true;
static String exitProgram;
public static void main(String[] args) throws IOException {
FileWriter names = new FileWriter("C:\\Users\\Students\\Desktop\\files\ ames.csv",true);
FileWriter grades = new FileWriter("C:\\Users\\Students\\Desktop\\files\\grades.csv",true);
FileWriter gpas = new FileWriter("C:\\Users\\Students\\Desktop\\files\\gpas.csv",true);
Scanner input = new Scanner(System.in);
do {
System.out.print("Enter student name: ");
name = input.nextLine();
name = name.substring(0, 1).toUpperCase() + name.substring(1);
System.out.print("Enter student grade: ");
grade = input.nextInt();
System.out.print("Enter student GPA: ");
gpa = input.nextDouble();
names.append(name+", ");
grades.append(grade+", ");
gpas.append(gpa+", ");
System.out.print("Exit? (y/n): ");
exitProgram = input.next().toLowerCase().trim();
input.nextLine();
if (exitProgram.equals("n")) {
exit = false;
names.close();
grades.close();
gpas.close();
input.close();
}
} while (exit == true);
}
}
4. Students revisited Create a method in your Student class called getInfo(), which prints a line that looks like this: My name is Mike. I'm in grade 15 and I have a 4.0 GPA. For now, at least... Create three files on your desktop named: names, grades, and gpas. Create 10 lines of information in each file. Read the lines of each file and store their contents in their own arrays. Create an array of type Student[] and fill it using those arrays. To confirm your work, loop through your Student[] array and call the getInfo method on each Student.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started