programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# New guy with a problem

Thomas Hacker
Greenhorn
Posts: 4
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.

Henry Wong
author
Sheriff
Posts: 23283
125
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

Thomas Hacker
Greenhorn
Posts: 4
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.

Henry Wong
author
Sheriff
Posts: 23283
125
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

Henry Wong
author
Sheriff
Posts: 23283
125
BTW, if you give up, scroll down... but seriously try to figure it out first.

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

Henry
[ November 08, 2006: Message edited by: Henry Wong ]

Thomas Hacker
Greenhorn
Posts: 4
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.

Thomas Hacker
Greenhorn
Posts: 4
Never mind, I finally got it after playing around with the -1 and the logical operators...

Garrett Rowe
Ranch Hand
Posts: 1296

From mathematics we know that this is the same as

which is the same as

or

 Consider Paul's rocket mass heater.