![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 10
Rep Power: 0
![]() |
Someone plz help
Hey guys, I'm fairly new to Java and I'm trying to figure out these two methods for my project. Someone please help, here's the code for the entire class, the bottom two methods are the one I'm trying to figure out:
// Program to add and multiply complex numbers. // Lab #1 for cs258; uses a class that handles complex numbers (Complex.java). import java.io.*;
public class Calculator
{
public static void main(String[] args)
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Complex num1, num2, result = new Complex();
char op;
boolean more;
System.out.println("\nComplex number calculation program\n");
do
{ num1 = readComplex(in);
num2 = readComplex(in);
op = readChar(in, "Enter the operation '+, -, *, or /': ", "+-*/");
switch (op)
{ case '+': result = num1.add(num2);
break;
case '*': result = num1.multiply(num2);
break;
case '/': result = num1.divide(num2);
break;
case '-': result = num1.subtract(num2);
}
System.out.println(num1+" "+op+" "+num2+" = "+result);
more = (readChar(in, "Perform another calculation? (y/n): ", "yn") !='n');
} while (more);
System.out.println("\n\nCalculation program completed\n");
}
// Method to read a complex number
public static Complex readComplex(BufferedReader in)
{
System.out.print("Enter a complex number: ");
String comp = in.readLine();
}
// Method to read the first character of a string
public static char readChar(BufferedReader in, String prompt, String chars)
{
String pr = prompt;
String ch = chars;
pr = in.readLine();
ch = in.readLine();
}
}Last edited by sykkn; Apr 11th, 2005 at 8:31 AM. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
ummm what errors are you getting when you compile?
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Don't know if this is the whole problem, but you are missing return statements for both of them.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4
![]() |
As suggested earlier, post the error messages and we may be then able to identify the error and correct them.
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Apr 2005
Posts: 10
Rep Power: 0
![]() |
In all honesty I'm pretty sure my methods are completely wrong.
I'm trying to figure out the readComplex method and the readChar method. First off, seeing what's done so far in that class, could you guys figure out a method that would only read the first character of a string? Also, what would the method look like to read a complex number? I greatly appreciate any help! |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Apr 2005
Posts: 10
Rep Power: 0
![]() |
Guys please help I really need to get this done!
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() |
sounds like you are asking to do your homework for you :/
|
|
|
|
|
|
#8 |
|
Professional Programmer
|
So, u'r trying to calculate an expresion. Then look at this : http://www.programmingforums.org/for...ght=calculator
maybe it will help you.
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#9 | |
|
Newbie
Join Date: Apr 2005
Posts: 16
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|