views:

40

answers:

1
enter import java.io.*;
class eval
{
double add(double a,double b)
 {
 return (a+b);
 }
double sub(double a,double b)
 {
 return (a-b);
 }
double mul(double a,double b)
 { 
 return (a*b);
 }
double div(double a,double b)
 {
 return (a/b);
 }
}

class cal extends eval
{
 public static void main(String args[])throws IOException
 {
  eval a1=new eval();
   try{
   System.out.println("1) Add");
   System.out.println("2) Subtract");
   System.out.println("3) Multiply");
   System.out.println("4) Divide");
   System.out.println("5) Enter your choice");
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   int ch;ch=Integer.parseInt(br.readLine());
   System.out.println("Enter two number");
   double a;a=Integer.parseInt(br.readLine());
   double b;b=Integer.parseInt(br.readLine());
   switch(ch)
    {
     case 1: 
      a1.add(a,b);
      break;
     case 2:
      a1.sub(a,b);
      break;
     case 3:
      a1.mul(a,b);
      break;
    case 4:
     a1.div(a,b);
     break;
   }
}
catch (IOException e)
{
    System.out.println("Error occured, please restart application.");
} 
}

}

+4  A: 

You're trying to run it like this:

java cal.class

You should just specify the class name not the file name:

java cal

(I suspect you may have many more questions about the actual code, but please use other questions for those. For a start, there's no reason for cal to extend eval... and you might consider more meaningful names.)

Jon Skeet
I first compiled it by typing :-javac cal.javaand the run by java cal
Gaurav
I am sorry for a mistake , the error ocurred while I tried to run the cal.class file
Gaurav
@Gaurav Those are both right; are you positive you did `java cal` instead of `java cal.class`? Java interprets the `.` as a package separator, so it tries to find the class `class` in the package `cal`; hence `NoClassDefFoundError: cal/class`
Michael Mrozek
when I try to run by typing java cal.class , then too error occurs. Please check out the screenshot of what I did imagebin.org/101188
Gaurav
@Guarav: Read my answer carefully. You *shouldn't* be running `java call.class`. You *should* be running `java cal`.
Jon Skeet
Thanks for the answer , I got it.
Gaurav