This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New guy with a problem

 
Thomas Hacker
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind, I finally got it after playing around with the -1 and the logical operators...




 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


From mathematics we know that this is the same as



which is the same as


or
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic