Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I need some help

Name: Anonymous 2009-09-30 1:00

I'm a first time /prog/er here and I know these kinds of threads are looked down upon, but Ive got an assignment due tomorrow and I just started on it a few hours ago. I have to write a Java program that takes in two numbers and a math sign like plus, minus, times and divide and gives the answer. Ive been trying to use parameters but I'm not sure if Im doing it right. Its not compiling yet but this is what I have so far. Any help would be appreciated.


import StringTokenizer
import JOptionPane

public void class calculate
{
    public static void main(string args[])
    {
             int[] para = input;
             if(para[3] = +)
                  para[1+2] = output;
             if(para[3] = -)
                  para[1-2] = output;
             if(para[3] = *)
                  para[1*2] = output;
             if(para[3] = /)
                  para[1/2] = output;
        }
}

Name: Anonymous 2009-09-30 1:02

>>1
Are you sure you arnt programming in LISP?

Name: Anonymous 2009-09-30 1:04

>>1
ahAHAHAHHAHAHHAHHAA!!!! Drop that class now or you are gonna fail. I hope it's an elective.

Name: Anonymous 2009-09-30 1:06

>>1
What IDE are you using and why isnt it sending you warnings? (Hint: they might look like spellcheck errors)

Name: Anonymous 2009-09-30 1:07

>>4
Eclipse, and I'm not getting any warnings.

Name: Anonymous 2009-09-30 1:09

>>5
I dont even... Eclipse... warnings.... I'm going to kill myself

Name: Anonymous 2009-09-30 1:11

Eclipse, and I'm not getting any warnings.
Go install your JDK. Then we can work from there.

Name: Anonymous 2009-09-30 1:16

There is so much wrong in this program...

Since when did this turn into "let's do other people's homework"?

Name: Anonymous 2009-09-30 1:25

I started writing this, but then I became depressed.

Name: Anonymous 2009-09-30 2:24

Woah... OP is serious. I want to help him, but on the other hand, no.

Name: Anonymous 2009-09-30 2:25

>>1
First of all, the demonym for people on /prog/ is /prog/rider.
Secondly nobody is going to help you with your homework.

Name: Anonymous 2009-09-30 2:26

public void class calculate
I loled HARD. Does this say something bad about me?

Name: !MILKRIBS5K 2009-09-30 2:29

>>1
Wowee! Thats a terrible program!

Name: Anonymous 2009-09-30 2:32

>>1
I found your problem OP!
You simply forgot to capitalize String!

Name: Anonymous 2009-09-30 2:42

>>14
Thanks but it still doesnt work.

Name: ed 2009-09-30 2:50

Your code is broken man. Seriously, try NOT postponing stuff 'til the last minute next time. Ask for an extended deadline and go read up on some java.

TipØ You'll need to read up on the scanner class if you're to accept userinput.

Name: Anonymous 2009-09-30 2:54

>>1
don't expect to get help on 4chan, fail is its overlord

Name: Anonymous 2009-09-30 3:27

There's way too much wrong with your program OP.
Wrong things that are obvious from the start:
public void class calculate
a void class? what?
int[] para = input;
Where do you get that input variable/argument/member from? It doesn't exist.
if(para[3] = +)
Assigning(you probably wanted to compare), para[3] with the + operator, what. Maybe if this were Lisp, + would be a symbol and you could do that, but this is Java.
para[1+2] = output;
now assigning para[3] with output. Where does output come from? Do you realize that para[1?2] you're doing makes no sense at all?

The only line that makes some sense is
    public static void main(string args[])
but you probably copy-pasted it from some manual.

It's like you don't understand the language at all.
I don't even know Java(I do know C#) and could write a simple evaluator in Java.
I'll mirror >>2's sentiment, as this would be trivial to do in Lisp, since symbols are basic types (as long as the input was a S-Expression).

Name: >>18 2009-09-30 3:46

Here's a simple arithmethic evaluator I wrote in Common Lisp, just 4 minutes ago:

(defun simple-eval (e)
  (if (atom e) e
      (destructuring-bind (op . args) e
    (assert (member op '(+ - * / sin cos expt)) (op) "Unknown operation ~A" op)
    (apply op (mapcar #'simple-eval args)))))

;;; Examples:
(simple-eval '(+ (* (* 1 2) (/ 1 2)) 0 1 2)) ;=> 4
(simple-eval '(+ (expt (cos 123) 2) (expt (sin 123) 2))) ;=> 0.99999994 in the implementation I'm using, it's not 1 due to floating point errors. Better accuracy can be obtained by tweaking some options, but that's not the point here.

Name: Anonymous 2009-09-30 7:12

>>19
Idiotic.

Name: Anonymous 2009-09-30 7:29

>>20
Troll.
If you have any problem with it other than the fact that EVAL would have worked just as well(except it would perform, much much more), feel free to report them.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List