Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Java Recursion (Harmonic Sum) help
Closed Thread
Old 07-24-2009, 08:40 PM   #1 (permalink)
 
Newb Techie

Join Date: Jul 2009

Location: Minnesota

Posts: 2

clank is on a distinguished road

Default Java Recursion (Harmonic Sum) help

EDIT - This was originally two threads that have been merged.

Hello, I need help with using recursion in a Java program! My assignment is to:
Write a program to compute the harmonic sum using a recursive harmonicSum() function. HarmonicSum = 1 + 1/2 + 1/3 + …. 1/n
Here is what I have so far:
class Harmonic
{
public harmonicSum(int n)
{
if (n == 1) return 1;
return n * fractor(n-1);
}
}


public static void main(String[] args)
{
Harmonic factor = new Harmonic();

factor.harmonicSum(int n)

}

-I do not completely understand all of this yet, so any input is appreciated. Also am I going to need some kind of loop?

Last edited by Saxon; 07-25-2009 at 08:32 PM.
clank is offline  
Old 07-24-2009, 09:03 PM   #2 (permalink)
 
Newb Techie

Join Date: Jul 2009

Location: Minnesota

Posts: 2

clank is on a distinguished road

Default Help with error message- displayData(float[],float[],int) in DollarToYen cannot be a

:exclamation:I need help figuring out a couple errors.

Basically my assignment is to write a program to display the Japanese Yen value of the balance of up to 100 American Dollar bank deposits. Your program should be able to convert Dollar to Yen. Write functions that read in data, convert the currency from Dollars to Yen for each bank deposit and display the value of each deposit in both Dollars and Yen.

I keep getting a few error messages saying: DollarToYen.java:62: displayData(float[],float[],int) in DollarToYen cannot be a
pplied to (float[],float[])
deposits.displayData(dollars, yen);


Here's my code:
import java.util.*;

class DollarToYen
{
public static final int MAX_DEPOSITS = 100;
public static final float DOLLAR_TO_YEN = 94.02684f;

// read number of Dollars in each account from the keyboard
void readDollars(float[] dollars, int count )
{
Scanner kb = new Scanner(System.in);
for(int index = 0; index < count; index++)
{
System.out.print("Enter the deposit amount(dollars) : $");
dollars[index] = kb.nextInt();
}
}

// Convert Dollars to Yen
void dollarsToYen(float dollars[],float yen[],int count)
{
for (int index = 0; index < count; index++ )
yen[index] = dollars[index] * DOLLAR_TO_YEN;
}

// Display the amount in each account in both Dollars and Yen
void displayData(float dollars[],float yen[],int count )
{
for(int index = 0; index < count; index++ )
{
System.out.println("\nAccount ["+(index+1)+"] : ");
System.out.println("\t"+dollars[index]+" dollars");
System.out.println("\t"+yen[index]+" yen");
}
System.out.println();
}

public static void main(String[] args)
{
int num; // Actual number of deposits
float[] dollars = new float[MAX_DEPOSITS]; // Dollars
float[] yen = new float[MAX_DEPOSITS]; // Yen

Scanner kb = new Scanner(System.in);
DollarToYen deposits = new DollarToYen();


// Prompt the user for the number of deposits
System.out.print("Enter the number of deposits: ");
num = kb.nextInt();

{
// Read the amount in each deposit
deposits.readDollars(dollars);

// Convert Dollars to Yen.
deposits.dollarsToYen(dollars, yen);

// Display the amount in each deposit
deposits.displayData(dollars, yen);


}
}
}
clank is offline  
Old 07-25-2009, 05:24 PM   #3 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Java Recursion (Harmonic Sum) help

We are not going to do your school work for you, that much is in our rules. I will say though, that if you are supposed to be using recusion for this task, your code so far does not.
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
Old 07-25-2009, 05:32 PM   #4 (permalink)
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: Help with error message- displayData(float[],float[],int) in DollarToYen cannot b

As I said in your other thread - we are not going to do your school work for you. And as I did there, I will give you a tip to get you in the right direction - look at your usage of the displayData method compared to its specification.
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline  
Old 07-25-2009, 08:30 PM   #5 (permalink)
Saxon's Avatar
 

Join Date: Feb 2007

Posts: 6,362

Saxon is just really niceSaxon is just really niceSaxon is just really niceSaxon is just really nice

Default Re: Help with error message- displayData(float[],float[],int) in DollarToYen cannot b

Quote:
Originally Posted by kmote View Post
As I said in your other thread - we are not going to do your school work for you. And as I did there, I will give you a tip to get you in the right direction - look at your usage of the displayData method compared to its specification.
And as such this thread is now locked.
__________________
I am not here for long I am deploying soon so please don't expect anything long winded.

Saxon is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Error 25099 Unzipping Core Files Failed Osiris Tips, Tricks & Tutorials 0 06-30-2009 09:24 AM
Java Problem s1nglef1sh Windows Operating Systems and Software 5 10-06-2008 05:10 PM
Need Java help CrazeD Programming Discussions 4 09-29-2008 06:29 PM
Updates for Java eliminate many security holes Trotter Browser & General Internet Questions 1 07-11-2008 09:54 PM