Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 10th, 2005, 11:12 PM   #1
Emperor
Newbie
 
Join Date: Apr 2005
Posts: 10
Rep Power: 0 Emperor is on a distinguished road
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.
Emperor is offline   Reply With Quote
Old Apr 10th, 2005, 11:25 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Apr 10th, 2005, 11:29 PM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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
Mjordan2nd is offline   Reply With Quote
Old Apr 10th, 2005, 11:47 PM   #4
java_roshan
Professional Programmer
 
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4 java_roshan is on a distinguished road
As suggested earlier, post the error messages and we may be then able to identify the error and correct them.
java_roshan is offline   Reply With Quote
Old Apr 10th, 2005, 11:53 PM   #5
Emperor
Newbie
 
Join Date: Apr 2005
Posts: 10
Rep Power: 0 Emperor is on a distinguished road
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!
Emperor is offline   Reply With Quote
Old Apr 11th, 2005, 2:21 AM   #6
Emperor
Newbie
 
Join Date: Apr 2005
Posts: 10
Rep Power: 0 Emperor is on a distinguished road
Guys please help I really need to get this done!
Emperor is offline   Reply With Quote
Old Apr 11th, 2005, 6:05 AM   #7
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
sounds like you are asking to do your homework for you :/
Berto is offline   Reply With Quote
Old Apr 11th, 2005, 7:12 AM   #8
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
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 !
xavier is offline   Reply With Quote
Old Apr 11th, 2005, 11:33 AM   #9
blueandconfused
Newbie
 
Join Date: Apr 2005
Posts: 16
Rep Power: 0 blueandconfused is on a distinguished road
Quote:
Originally Posted by Emperor
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!
Why do you have the class Complex as a return type in your method readComplex? Do you need to have the class complex or where is the code for that class?
blueandconfused is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC