Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Array Homework assignment

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array Homework assignment

    I was given a homework assignment to create a program to convert money in accounts from usd to yen. With the code given to us, this is what I have came up with so far:

    import java.util.*;
     
    class DollarToYen
    {
      public static final int MAX_DEPOSITS = 100;
      public static final float DOLLAR_TO_YEN = 0.098f;
     
      // read number of Dollars in each  account from the keyboard
      void readDollars(float[] dollars, int count )
      {
        Scanner kb = new Scanner(System.in);
        for(int j = 0; j < count; j++)
        {
          System.out.print("Enter the deposit amount(dollars) : $");
                   j  = kb.nextInt();
        }
      }
     
      // Convert Dollars to Yen
      void dollarsToYen(float dollars[],float yen[],int count)
      {
      //  for (int j = 0; j < count; j++ )
        //	/DOLLAR_TO_YEN;
      }
     
      // Display the amount in each account in both Dollars and Yen
      void displayData(float dollars[],float yen[],int count )
      {
        for(int j = 0; j < count; j++ )
        {
          System.out.println("\nAccount ["+(j+1)+"] : ");
          System.out.println("\t"+dollars[j]+" dollars");
          System.out.println("\t"+yen[j]+" 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( );
     
    	    // Convert Dollars to Yen.
    	    deposits.dollarsToYen( );
     
    	    // Display the amount in each deposit
    	    deposits.displayData( );
    	  }
    	}
    I cannot figure out how to get it to work correctly. Any help would be greatly appreciated.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Array Homework assignment

    Hello lich0802, welcome to the forums.

    What doesn't work about it? Does any of it work? Are you looking for help with the conversion?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array Homework assignment

    The parts that I cannot figure out are:
     System.out.print("Enter the deposit amount(dollars) : $");
                   j  = kb.nextInt();
        }
      }
     
      // Convert Dollars to Yen
      void dollarsToYen(float dollars[],float yen[],int count)
      {
      //  for (int j = 0; j < count; j++ )
        DONT KNOW WHAT TO PUT HERE /DOLLAR_TO_YEN;
    and for the j= kb.nextInt(); im not sure if j is right. also 
    these three parts: // Read the amount in each deposit
    	    deposits.readDollars( );
     
    	    // Convert Dollars to Yen.
    	    deposits.dollarsToYen( );
     
    	    // Display the amount in each deposit
    	    deposits.displayData( );
    Last edited by JavaPF; February 28th, 2011 at 10:38 AM.

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array Homework assignment

    lich0802 A few tips only: first of all you defined your methods with attributes but you dont use the same signature of your methods in main. Additional you dont need all of those attributes. for example in displayData method. Finally use nextFloat instead of nextInt.

Similar Threads

  1. [SOLVED] Array related assignment
    By Melawe in forum Java Theory & Questions
    Replies: 36
    Last Post: July 21st, 2010, 03:22 AM
  2. Replies: 1
    Last Post: February 22nd, 2010, 07:20 AM
  3. Homework help
    By cd247 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 11th, 2009, 05:56 PM
  4. need help with homework!
    By programmer12345 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 27th, 2009, 05:34 AM
  5. [SOLVED] What is cast operator and how to use it?
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 27th, 2009, 06:11 AM

Tags for this Thread