Forums Register Login

New guy with a problem

+Pie Number of slices to send: Send
Hello everyone! How you guys doin? First off, let me introduce myself. I am TJ Hacker and I am a freshman at RIT. I currently have a Introduction to Programming class.

As for the problem, I have to make two classes, one real and the test. I got the test class all worked out and perfect. the Real class is NEARLY there.

The program states that i have to create two methods using fractionals and summations.
i got the positive fractionals and summations up and working, but i'm stuck with the negative inputs.

Sorry, i'm asking for an input to ask which method to use and then a number. if it's positive, works perfect. If it's negative, however, i'm clueless lol.. any takers?

Any help would be appreciated! smile.gif biggrin.gif

Here's the Java code....It's in two classes but you don't really need the Real class so.



The negative parts are wrong i know, i was just messing around to see what i could come up with.
+Pie Number of slices to send: Send
Welcome to the Javaranch !!!

We could try to help you, if you help us a bit. Could you remind us how factorials work with negative numbers? (I wouldn't be surprised if your instructor has a special definition for it)

Henry
+Pie Number of slices to send: Send
ah. It states in the paper that Factorial (-n) are defined as = -1 * factorial(n).

As a friendly reminder, factorials work in n! as in 6! = 720. So for example, -6! would be -720.

For the Summations, it states that if a negative number is inputted, make sure it is changed to a positive number. HINT: use the multiplication of -1.

I just dont understand this fully.
+Pie Number of slices to send: Send
I could give you the answer, but trust me, you will hate me for it...

The key to the problem is following this quote...

It states in the paper that Factorial (-n) are defined as = -1 * factorial(n).



And writing it as a recursive expression. If "num" is negative, how would you write the expression for result that follows the quote.



Henry
+Pie Number of slices to send: Send
BTW, if you give up, scroll down... but seriously try to figure it out first.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.



Henry
[ November 08, 2006: Message edited by: Henry Wong ]
+Pie Number of slices to send: Send
Yeah, I finally got that (-num) thing. Whew! Now about the Summation negative method.......

Summation is like a factorial just with addition instead of multiplication.
EX: summation(4) = 4+3+2+1 = 10.
+Pie Number of slices to send: Send
Never mind, I finally got it after playing around with the -1 and the logical operators...




+Pie Number of slices to send: Send


From mathematics we know that this is the same as



which is the same as


or
Lookout! Runaway whale! Hide behind this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 784 times.
Similar Threads
Introduction and a question about recursion
Can't get the result of factorial method
Reading a String backward
How to get a method to call a method
Taylor Cosine Approximation (help!!!)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:25:49.