I am doing a program that will convert euros and yens to US dollars and then give the total amount of money upon exiting the program. I need a gift class to hold the total. Basically I did two file a ConvertCurrency file and a gift file. It is has been pretty much down hill from there. Any suggestion how to link the files correctly.

import java.util.*;

public class ConvertCurrency

{
    public static void main (String [] args) //start main method

    // define constants
    final double USdollars_Rate = 1.0
    final double Euro_Rate = 1.24
    final double Yen_Rate = .0091

    // define variables
    int choice = 0;
    double value = 0;
    double answer = 0;

    // description of Program to user
    System.out.print ("This program will convert USdollars, Euros, ad Yen");
    System.out.println ("to Usdollars based on the selction of the user.");
    System.out.println ("Please make you selection.");

    // set up input scanner
    scanner stdin1 = new scanner (System.in);

    // get choice from user
    System.out.print ("To convert USdollars to US dollars, press 1");
    System.out.println ("To convert Euros to USdollars, press 2");
    System.out.println ("To convert Yen to USdollars, press 3");
    System.out.println ("To exit the program, press 4");
    System.out.println ( );
    choice = stdin1.nextInt();

    Gift choice = new Gift ();

    while (choice != 4) // set up the while statement

    {
        switch ( choice ) // use a switch statement to switch choice

        {
            case 1: // USdollars conversion
            choice.enterUSdollars;
            break;

            case 2: // Euros conversion
            choice.enterEuros;
            break;

            case 3: // Yen conversion
            choice.enterYen;
            break;

            default: // Exit to accumulate total
            System.out.println ("Exit the program and give total.");
        }
    }

}

gift file

import java.util.*;

public class Gift () {

{

// method to enter USdollars
System.out.println ("Enter amount of US dollars received: "); 
value = stdin1.nextDouble() ; // read in the user input
answer = value * USdollars_RATE ; // do the math
totalCollected += USD; 
System.out.println(USD + "US dollars equals " + USD + "US"); 

//method to enter Euros
System.out.println ("Enter amount of Euros received: "); 
value = stdin1.nextDouble() ; // read in the user input 
answer = value * Euros_RATE; 
totalCollected += USD; 
System.out.println(USD + "US dollars equals " + USD + "US"); 

// method to enter Yen
System.out.println ("Enter amount of Yen received: "); 
value = stdin1.nextDouble() ; // read in the user input
answer = value * Yen_RATE; 
totalCollected += USD; 
System.out.println(USD + "US dollars equals " + USD + "US"); 

// default method
System.out.println ("totalCollected" = USD ") ;

}
}
}
}

I don't think it would make sense to 'link' the classes, or at least the way you have written them it doesn't make sense. From what I can see, you need to make the 'CurrencyConvert' class nothing but methods and possibly aggregate that class into the Gift class. With what you have now, there's really nothing you can do. Not being rude or anything, but it'd probably be best to start over.

I'll give a small example of what it should look like:

public class ConvertCurrency
{
    private final double USdollars_Rate = 1.0
    private final double Euro_Rate = 1.24
    private final double Yen_Rate = .0091

   public ConvertCurrency()
   {
       super();
   }
    
   public void convertToUS(double amount)
   {
         //conversion
   }
}

Second class

class Gift
{
   private ConvertCurrency  cc;
  
   public Gift()
   {
      super();
      cc = new ConvertCurrency();
   }
   public void getAmount()
   {
      System.out.print("Enter an amount --> ");
     //get the input
    cc.convertToUS(input);
   }
}

There may be better options of combining the classes, but I'm not sure the exact functionality you expect out of this.

I understand completely where you are coming from. I have started over. I had what I thought was a really good program, it work, met the requirements. I submitted and was told I needed a gift class. I'm having problems not only comprehending how to get the gift class linked and why it is necessary.

I don't think it would make sense to 'link' the classes, or at least the way you have written them it doesn't make sense. From what I can see, you need to make the 'CurrencyConvert' class nothing but methods and possibly aggregate that class into the Gift class. With what you have now, there's really nothing you can do. Not being rude or anything, but it'd probably be best to start over.

I'll give a small example of what it should look like:

public class ConvertCurrency
{
    private final double USdollars_Rate = 1.0
    private final double Euro_Rate = 1.24
    private final double Yen_Rate = .0091

   public ConvertCurrency()
   {
       super();
   }
    
   public void convertToUS(double amount)
   {
         //conversion
   }
}

Second class

class Gift
{
   private ConvertCurrency  cc;
  
   public Gift()
   {
      super();
      cc = new ConvertCurrency();
   }
   public void getAmount()
   {
      System.out.print("Enter an amount --> ");
     //get the input
    cc.convertToUS(input);
   }
}

There may be better options of combining the classes, but I'm not sure the exact functionality you expect out of this.

Something working doesn't mean it's good (especially in an academic environment) ;)
Proper OO design is more important when you're a student than just producing working code, it should become so automatic that you don't even consider writing something that's not properly designed and start to gag on seeing poorly written code.

And yes, I've had teachers who rejected working solutions that weren't created according to the laid out specifications while accepting faulty solutions that did meet the specs.
This is not quite what happens in business (in business both would be rejected), but it's a start.

Thanks for the comments. What I meant to day (and didn't due to frustration) is that he is asking for something he has not taught. It is a introductory java class and none of us have ever program before. I have no problem meeting the requirements and turning in quality work but some guidance would be helpful. Again, thanks for your comments

Did the professor tell you what the Gift class is supposed to represent?

If this program is about converting currency, what does a gift have to do with converting currency?

You mentioned that the Gift class must hold the total. You could use the Gift class below and create a Gift object in the main method (as you did earlier) and call the updateTotal after converting the currency.

class Gift
{
    private int total;

    public void updateTotal(int amount)
    {
        total += amount;
    }

     public int getTotal()
     {
        return total;
     }
}

This class isn't necessary. You could just maintain an variable in the ConvertCurrency class.

Please give more information about the project so a more helpful response can be given

:?: For more help, www.NeedProgrammingHelp.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.