Full Version: Java Error- netbeans
UtterAccess Discussion Forums > And More... > JAVA and C#
savanna
2 Error states
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Angela\My Documents\NetBeansProjects\CharAtMethod\build\classes
C:\Documents and Settings\Angela\My Documents\NetBeansProjects\CharAtMethod\src\charatmethod\Grade.java:28: illegal start of expression
private String letterGrade;
C:\Documents and Settings\Angela\My Documents\NetBeansProjects\CharAtMethod\src\charatmethod\Grade.java:29: reached end of file while parsing
}
Any help would greatly be appreciated.
****************************************
package charatmethod;
import java.util.Scanner;
public class CharAtMethod
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

System.out.println("Enter a letter grade:");
String input = in.nextLine();
Grade g = new Grade(input);
double grade = g.getNumericGrade();
System.out.println("Numeric value: " + grade);
}
}
*************************************
package charatmethod;
public class Grade
{
public Grade(String initGrade)
{
letterGrade = initGrade;
}
public double getNumericGrade()
{
double grade = 0;
switch(letterGrade.charAt(0))
{
case 'A': grade = 4.0;break;
case 'B': grade = 3.0; break;
case 'C': grade = 2.0; break;
case 'D': grade = 1.0; break;
default: grade = 0.0; break;
}
for (int i = 0; i < letterGrade.length(); i++)
{
if (letterGrade.charAt(i) == '-')
grade = grade - 0.3;
else if (letterGrade.charAt(i) == '+')
grade = grade + 0.3;
}
private String letterGrade
}
savanna
2 Error states
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Angela\My Documents\NetBeansProjects\CharAtMethod\build\classes
C:\Documents and Settings\Angela\My Documents\NetBeansProjects\CharAtMethod\src\charatmethod\Grade.java:28: illegal start of expression
private String letterGrade;
C:\Documents and Settings\Angela\My Documents\NetBeansProjects\CharAtMethod\src\charatmethod\Grade.java:29: reached end of file while parsing
}
Any help would greatly be appreciated.
****************************************
package charatmethod;
import java.util.Scanner;
public class CharAtMethod
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a letter grade:");
String input = in.nextLine();
Grade g = new Grade(input);
double grade = g.getNumericGrade();
System.out.println("Numeric value: " + grade);
}
}
*************************************
package charatmethod;
public class Grade
{
public Grade(String initGrade)
{
letterGrade = initGrade;
}
public double getNumericGrade()
{
double grade = 0;
switch(letterGrade.charAt(0))
{
case 'A': grade = 4.0;break;
case 'B': grade = 3.0; break;
case 'C': grade = 2.0; break;
case 'D': grade = 1.0; break;
default: grade = 0.0; break;
}
for (int i = 0; i < letterGrade.length(); i++)
{
if (letterGrade.charAt(i) == '-')
grade = grade - 0.3;
else if (letterGrade.charAt(i) == '+')
grade = grade + 0.3;
}
private String letterGrade;
}
b0b1
I don't know Java but this seems pretty close to C++.
tring should be lower case - "string"
Possibly the Class should have a ";" after the last "}"
HTH
savanna
Solution:
package charatmethod;
import java.util.Scanner;
ublic class CharAtMethod
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

System.out.println("Enter a letter grade:");
String input = in.nextLine();
Grade g = new Grade(input);
double grade = g.getNumericGrade();
System.out.println("Numeric value: " + grade);
}
}
*****************************************
package charatmethod;
public class Grade
{
public Grade(String initGrade)
{
letterGrade = initGrade;
}
public double getNumericGrade()
{
double grade = 0;
switch(letterGrade.charAt(0))
{
case 'A': grade = 4.0;break;
case 'B': grade = 3.0; break;
case 'C': grade = 2.0; break;
case 'D': grade = 1.0; break;
default: grade = 0.0; break;
}
for (int i = 0; i < letterGrade.length(); i++)
{
if (letterGrade.charAt(i) == '-')
grade = grade - 0.3;
else if (letterGrade.charAt(i) == '+')
grade = grade + 0.3;
}
return grade;

}
private String letterGrade;
}
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.