10-20-2004, 05:52 PM
|
#1
|
|
Member (9 bit)
Join Date: Jan 2004
Location: Kansas City(westwood), KS
Posts: 458
|
Help me please, can't make a custom class file work
I need to make a program where we make our own class and what it is suppoused to do is take two numbers and an operation sign, then compute. Here is my code and i get a couple errors i can't fix. Whats wrong with it?
Code:
public class Exercise
{
public static void main(String args[])
{
System.out.println( Compute.computer(2.5, 0.5, + ));
}
}
class Compute
{
public static double computer(double double1, double double2, char char1)
{
double result;
result = 0;
switch (char1)
{
case '+':
result = double1 + double2;
break;
case '-':
result = double1 - double2;
break;
case '*':
result = double1 * double2;
break;
case '/':
result = double1 / double2;
break;
}
return result;
}
}
EDIT:
never mind i made it work, i just needed to put the operation in single quotes. Any mods that see this can go ahead and delete. No one replied so its sort of useless.
Last edited by colecifer; 10-20-2004 at 07:41 PM.
|
|
|