Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Java charAt method

Posted on 2008-11-17
7
Medium Priority
?
1,061 Views
Last Modified: 2012-05-05
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
}
0
Comment
Question by:ca1358
7 Comments
 
LVL 13

Expert Comment

by:MicheleMarcon
ID: 22982566
private String letterGrade
^^^^^^^^^^^^^^^^^

 private String letterGrade;

You forgot the ";"
0
 

Author Comment

by:ca1358
ID: 22982582
still getting
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
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22982844
Post current code *in the code snippet window* please
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Accepted Solution

by:
pellep earned 750 total points
ID: 22982852
You're missing a curly bracket ( "}" ) before the offending variable declaration to close the getNumericGrade() function.
0
 
LVL 13

Assisted Solution

by:MicheleMarcon
MicheleMarcon earned 750 total points
ID: 22983896
I suggest to use a systax-checking IDE, such as netbeans www.netbeans.org
0
 

Author Comment

by:ca1358
ID: 22990632
Solution mssing return statment
Thank for the input.


****************************************************8
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;
}
    return grade;
            
}  
    private String letterGrade;
}

Open in new window

0
 

Author Closing Comment

by:ca1358
ID: 31517755
Thanks for the input!!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches viewers about errors in exception handling.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question