• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help in fixing the error

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.....i have finished the program that determines if the students fails or not..according to the grades.....well....i have an error..i dont know how to overcome it...it says " class expexted...here is the code :

import java.util.Vector;
import javax.swing.JOptionpane;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class student

{
double mark[]= new double[5];
String grade;
string name;
int id;

Vector v=new Vector();


student()

{

grade="";
name="";
id=0;

for(int i=0; i<5; i++)
{
mark[i]=0;
}

}


student (double d[], String g, String n, int idno)

{

mark =d;
grade=g;
name=n;
id=idno;
}



public void menu()

{
int choice = Integer.parseInt(JOptionPane.showInputDialog (" Enter No. for the Operation"
+"\n 1. Add a student."
+"\n 2. Total number of student."
+"\n 3. No. of students falling."
+"\n 4. Generate an annual report."
+"\n 5. Continue."
+"\n 6. Exit."));


if (choice ==1)
{ getValues(); }

else if (choice==2)
{ getTotalNumber(); }

else if(choice==3)
{ getfallgrade();}

else if(choice==4)
{display();}

else if(choice==5)
{menu();}

else
{ System.exit(0); }

menu();

}


public void getValues()

{

student s=new student();
s.name = JOptionPane.showInputDialog("Input student name:");
String idno = JOptionPane.showInputDialog("Enter ID:");
s.id =Integer.parseInt(idno);

String m = JOptionPane.showInputDialog("Marks for Mathematics");
String m1 = JOptionPane.showInputDialog("Marks for Arts");
String m2 = JOptionPane.showInputDialog("Marks for Science");
String m3 = JOptionPane.showInputDialog("Marks for Games");
String m4 = JOptionPane.showInputDialog("Marks for Computers");


s.mark[0]= double.parseDouble(m);
s.mark[1]= double.parseDouble(m1);
s.mark[2]= double.parseDouble(m2);
s.mark[3]= double.parseDouble(m3);
s.mark[4]= double.parseDouble(m4);

v.add(s);

}



public void getmark()

{

for (int i=0; i<5; i++)
{
System.out.println(mark[i]);
}
}



public void getfallgrade()

{

int acount=0;
int bcount=0;
int ccount=0;
int dcount=0;
int fcount=0;

for (int i=0; i<v.size(); i++)
{
student s = (student) v.elementAt(i);

if(s.grade=='A')
acount++;
else if(s.grade=='B')
bcount++;
else if(s.grade=='c')
ccount++;
else if(s.grade=='D')
dcount++;

}


System.out.println("students under A:"+acount);
System.out.println("students under B:"+bcount);
System.out.println("students under C:"+ccount);
System.out.println("students under D:"+dcount);
System.out.println("students under F:"+fcount);

}


public void getgrade()

{


double sum=0, avg=0;

for (int j=0; j<5; j++)
{
sum+= mark[j];
}

avg=sum/5;

System.out.println(avg);

if(avg>=90) grade="A";
else if (avg>=80) grade ="B";
else if (avg>=70) grade ="C";
else if (avg>=60) grade ="D";
else grade="F";
System.out.println(grade);
}


void getTotalNumber()

{

System.out.println( "Total number of students =" + v.size());
}

public void getname()
{
System.out.println(name);
}

public void getid()
{
System.out.println("ID:"+id);
}

void display()

{

for (int i=0; i<v.size(); i++)
{
student s =(sudent) v.elementAt(i);
System.out.println("Marks for students");
s.getmark();
s.getgrade();
s.getname();
s.getid();
}
}


public static void main( String args[]) throws Exception

{
student s = new student();
s.menu();
}
}


the error i get is in this part :

s.mark[0]= double.parseDouble(m);
^
s.mark[1]= double.parseDouble(m1);
^
s.mark[2]= double.parseDouble(m2);
^
s.mark[3]= double.parseDouble(m3);
^
s.mark[4]= double.parseDouble(m4);
^

thannks
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Double is a class whose name is in title case. You have it in lower case ("double").

s.mark[0]= double.parseDouble(m);
s.mark[1]= double.parseDouble(m1);
s.mark[2]= double.parseDouble(m2);
s.mark[3]= double.parseDouble(m3);
s.mark[4]= double.parseDouble(m4);



Here's a hint for debugging your own code, or anybody else's: Always look for typographical errors first because they seem to be by far and away the most common cause of a program not compiling and sometimes of runtime errors too.
[ October 29, 2004: Message edited by: Jeff Bosch ]
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once you have sorted out all the typos and spelling in your code, you still have a problem with your grading algorithm: you are trying to do
s.grade == 'A' etc.
This will not work as you are trying to compare a String (grade) with a char primitive 'A'. These are incompatible types and cannot be compared by using the comparison operator ==.

You want to do something like:
s.grade.equals("A"),
this should work better.
Apart from that, I can't see too many compiler errors with your code, except I'm not sure that the counting methods you are using are doing what you want.

DD
 
reply
    Bookmark Topic Watch Topic
  • New Topic