GeeCON Prague 2014*
The moose likes Java in General and the fly likes New guy with a problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "New guy with a problem" Watch "New guy with a problem" New topic
Author

New guy with a problem

Thomas Hacker
Greenhorn

Joined: Nov 08, 2006
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

Joined: Sep 28, 2004
Posts: 18876
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Thomas Hacker
Greenhorn

Joined: Nov 08, 2006
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

Joined: Sep 28, 2004
Posts: 18876
    
  40

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

Joined: Sep 28, 2004
Posts: 18876
    
  40

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

Joined: Nov 08, 2006
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

Joined: Nov 08, 2006
Posts: 4
Never mind, I finally got it after playing around with the -1 and the logical operators...




Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296


From mathematics we know that this is the same as



which is the same as


or


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
GeeCON Prague 2014
 
subject: New guy with a problem