Scanner, syntax, char, string help, etc.
Hello all,
First off, this is a school project, and I'm a rabid do-it-yourselfer, so I'm looking for some pointed explanations of why things aren't working, not outright solutions. I've looked over some of the relevant documentation and run an internet search, and I'm pretty sure that whatever is going on is fundamental; so much so that Im not seeing it. I've added comments in the current code below to explain the errors I'm running into. Most of the methods I have cannot be renamed, as the professor is using his own tester to check our work. I have the tester itself on hand if need be. I can modify it as much as I like, but the original is being used for the grading process. Ideally, the end result should allow the user to input the relevant information, and recieve a letter grade based on their current average. Be as ruthless as you wish with the code, I've only been doing this for a few weeks now, but I'm of the opinion the best way to learn is with a critical eye watching. Let me know if you have any additional questions, and I'll do my best to answer them. Thanks in advance!
/*
* StudentQuizScores.java
*
* Created on February 19, 2007, 9:52 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author removed to protect the noobish
*/
import java.util.*;
publicclass StudentQuizScores{
//Attributes
private String email;
privateint quizCount;
privatedouble quizTotal;
privatedouble average;
private String name;
private String letterGrade;
privateboolean isPassing;
/** Creates a new instance of StudentQuizScores */
public StudentQuizScores(){
email ="john.doe@richmond.edu";
quizCount = 10;
quizTotal = 100;
average = 100;
name ="john.doe";
letterGrade ="A";
}
public StudentQuizScores(String email,double total,int n){
total = quizTotal;
n = quizCount;
}
//Returns the email address of the student.
public String getEmail(String getEmail){
email = getEmail;
return (email);
}
//Returns the number of quizzes taken so far.
publicint getQuizCount(){
return quizCount;
}
//Returns the total of quiz scores taken so far.
publicdouble getQuizTotal(){
return quizTotal;
}
//Returns the current quiz average.
publicdouble getAverage(){
return average;
}
/** Returns just the name portion of the email address, i.e. everything
* to the left of the "@".
*/
public String getName(){
return name;
}
/**
* Returns the letter grade for this student, based on a 10 point scale.
* 90 or above is an A, 80 or above a B, etc.
*/
public String getLetterGrade(){
Scanner in =new Scanner(System.in);
System.out.print("Enter the current numerical grade average: ");
/**THIS IS THE FIRST TROUBLE SPOT. I'M ATTEMPTING TO PULL THE NUMERIC
* GRADE FROM THE INPUT AND HAVE IT RETURN AN ALPHABETICAL ASSIGNMENT
* WITH THE IF/THEN STATEMET BELOW. CAN I PULL THE DIGITS/DECIMAL IN A
* DOUBLE VALUE TO A CHAR STRING?
*/
Double average = in.next();
char averageStr = averageStr.charAt(0, 1, 2, 3);
if (average >= 90){
System.out.println("A");
}elseif (average >= 80){
System.out.println("B");
}elseif (average >= 70){
System.out.println("C");
}elseif (average >= 60){
System.out.println("D");
}else{
System.out.println("F");
}
}
/**
* Returns true if the student is currently passing, or false if not.
* Passing is 60 or above.
*/
publicboolean isPassing(){
if (average >= 60){
isPassing =true;
}else{
isPassing =false;
}
}
/** Add a new quiz score to the class. Note that any data members having
* to do with calculating the average should be updated as well.
*/
publicvoid addNewScore(double score){
}
/** Allows for modification of old quiz grades to simplify curving
* grades, re-takes, etc.
*/
/** THIS ALSO RETURNS AN ERROR, BUT I THINK I KNOW HOW TO FIX IT. IT SHOULD
* JUST BE A MATTER OF CREATING THE PROPER ACCESSOR METHOD AND ASSIGNING IT
* TO ONE OF THE ORIGINAL ATTRIBUTES, CORRECT?
*/
publicvoid replaceOldScore(double oldScore,double newScore);{
}
}
Message was edited by:
Axewerfer

