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.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
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.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
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
NPH
Junior Poster in Training
55 posts since May 2005
Reputation Points: 10
Solved Threads: 1