I am very Java illiterate and I need to know how would i set all the variables in the first class to null or 0 to make a new method to clear everything. Thanks so much
import java.util.Arrays;
import java.util.Scanner;
public class studentMethods
{
private double totalScore;
private int count;
private String name;
Scanner in = new Scanner(System.in);
/*
System.out.println("Please enter your name: ");
in.nextString = name;
*/
public void setName()
{
System.out.println("Please enter your name: ");
String name = in.nextLine();
}
public void addQuiz()
{
System.out.println();
System.out.print("How many grades will be entered?");
while(!in.hasNextInt())
{
System.out.print("Please enter an integer: ");
in.next();
}
int numberOfGrades = in.nextInt();
for(int i = 1; i <= numberOfGrades; i++)
{
System.out.println("Enter score "+ i +": ");
while(!in.hasNextDouble())
{
System.out.print("Please enter a number: ");
in.next();
}
double score = in.nextDouble();
totalScore = totalScore + score;
count++;
}
}
public void getTotalScore()
{
}
/*
the getAverageScore method needs to be able to divide the totalScore by the number of
grades. It must then PRINT the result in the format "[student's name]'s grade average is [averageScore]"
*/
public void getAverageScore()
{
double averageScore = totalScore / count;
System.out.printf(name + "'s grade average is %.2f\n", averageScore);
public void clearEverything()
{
}
public char promptContinue()
{
System.out.println("New Student?");
char contin = in.next().charAt(0);
return contin;
}
}
public class Student
{
Scanner in = new Scanner(System.in);
public static void main(String[]args)
{
studentMethods grade = new studentMethods();
char contin = 'y';
while(contin == 'y'||contin == 'Y')
{
grade.setName();
grade.addQuiz();
grade.getTotalScore();
grade.getAverageScore();
contin = grade.promptContinue();
grade.clearEverything();
}
}
}