I'm in a beginner's Java class that I take online, so I miss out on a lot of valuable hands on instruction. I have a project to do, which I will post below. I dont want someone to do the project for me or anything of that nature. What I need is help on what I need to use in the project and why. I'd really like to understand what I'm writing and how to do it.
I've read tutorials and my text but I feel that some explinations directly related to my assignment would be helpful. Project as follows.
You are receiving graduation gifts from relatives and you want to keep track of how much money you have received. The wrinkle is that your relatives do not all live in the United States, and they give you gifts in their own local currancies. In fact, you receive gifts in US Dollars, Euros, and Japanese Yen.
Your project will consist of two classes. The first is a driver that andles all of the interaction with the user. It will essentially be a loog that prints a menu, prompts for the amount of the gift, and adds that gift to the bank. (Don't forget to provide a way to display the current balance and to exit from the program.
The second class is the Bank class. It will have a single instance variable that holds the current balance, and two static final variables that hold the conversion rates from Euros to US Dollars and from Yen to US Dollars. It will have the following methods:
Default constructor
void AddDollars ( float amount )
void AddEuros ( float amount )
void AddYen ( float amount )
float GetBalance ( void )
Where to startNeed assistance on where to start
Page 1 of 1
4 Replies - 779 Views - Last Post: 09 April 2008 - 07:04 AM
Replies To: Where to start
#2
Re: Where to start
Posted 08 April 2008 - 09:08 AM
tami3113, on 8 Apr, 2008 - 07:20 AM, said:
I'm in a beginner's Java class that I take online, so I miss out on a lot of valuable hands on instruction. I have a project to do, which I will post below. I dont want someone to do the project for me or anything of that nature. What I need is help on what I need to use in the project and why. I'd really like to understand what I'm writing and how to do it.
I've read tutorials and my text but I feel that some explinations directly related to my assignment would be helpful. Project as follows.
You are receiving graduation gifts from relatives and you want to keep track of how much money you have received. The wrinkle is that your relatives do not all live in the United States, and they give you gifts in their own local currancies. In fact, you receive gifts in US Dollars, Euros, and Japanese Yen.
Your project will consist of two classes. The first is a driver that andles all of the interaction with the user. It will essentially be a loog that prints a menu, prompts for the amount of the gift, and adds that gift to the bank. (Don't forget to provide a way to display the current balance and to exit from the program.
The second class is the Bank class. It will have a single instance variable that holds the current balance, and two static final variables that hold the conversion rates from Euros to US Dollars and from Yen to US Dollars. It will have the following methods:
Default constructor
void AddDollars ( float amount )
void AddEuros ( float amount )
void AddYen ( float amount )
float GetBalance ( void )
I've read tutorials and my text but I feel that some explinations directly related to my assignment would be helpful. Project as follows.
You are receiving graduation gifts from relatives and you want to keep track of how much money you have received. The wrinkle is that your relatives do not all live in the United States, and they give you gifts in their own local currancies. In fact, you receive gifts in US Dollars, Euros, and Japanese Yen.
Your project will consist of two classes. The first is a driver that andles all of the interaction with the user. It will essentially be a loog that prints a menu, prompts for the amount of the gift, and adds that gift to the bank. (Don't forget to provide a way to display the current balance and to exit from the program.
The second class is the Bank class. It will have a single instance variable that holds the current balance, and two static final variables that hold the conversion rates from Euros to US Dollars and from Yen to US Dollars. It will have the following methods:
Default constructor
void AddDollars ( float amount )
void AddEuros ( float amount )
void AddYen ( float amount )
float GetBalance ( void )
OK just to start... but don't count on us for more help if you don't write your own code
/** Just a start as you requested */
public class Bank {
private final static double EuroToUS = 1.5683;
private final static double YenToUS = 0.0097;
// suggest that you work with double, with float we will have rounding errors
private double balance;
// constructor
public Bank() {
balance = 0.0;
}
// constructor with initial balance
public Bank(double balance) {
this.balance = balance;
}
public double getBalance() {
return balance;
}
public void addDollars(double dollars) {
balance += dollars;
}
public void addYens(double yens) {
balance += (yens * YenToUS);
}
public void addEuros(double euros) {
balance += (euros * EuroToUS);
}
// and now to test everything
static public void main(String arg[]) {
// create a Bank account with an initial balance
Bank bank = new Bank(25.00);
System.out.println("Bank Balance after creration: $ " + bank.getBalance());
// add 10 Euros
bank.addEuros(10.00);
System.out.println("Bank Balance after adding 10 Euros: $ " + bank.getBalance());
}
}
#3
Re: Where to start
Posted 09 April 2008 - 06:17 AM
Thank you for the help. I spent a great deal of time on this yesterday.
My code isnt running smoothly yet though. I'm going to try to work out the kinks this morning.
I have a question about something used in your code:
private final static double
Why was this what was needed in this instance? I havent seen that yet except in a few of my book examples. My text says "private makes methods and data fields accessible only from within its own class."
Does that basically mean that you arent using that anywhere else in the code?
My code isnt running smoothly yet though. I'm going to try to work out the kinks this morning.
I have a question about something used in your code:
private final static double
Why was this what was needed in this instance? I havent seen that yet except in a few of my book examples. My text says "private makes methods and data fields accessible only from within its own class."
Does that basically mean that you arent using that anywhere else in the code?
#4
Re: Where to start
Posted 09 April 2008 - 06:37 AM
tami3113, on 9 Apr, 2008 - 06:17 AM, said:
Why was this what was needed in this instance? I havent seen that yet except in a few of my book examples. My text says "private makes methods and data fields accessible only from within its own class."
Does that basically mean that you arent using that anywhere else in the code?
Does that basically mean that you arent using that anywhere else in the code?
private means that it is only accessible in Bank... so if you write another class it wont be able to access EuroToUs or YenToUS unless you write a method like
public double getEuroRate() {
return EuroToUS;
}
static means that there is only one instance of these two variables. If you create 1000 Bank objects there is no need to have 1000 instance of EuroToUS and 1000 instance of YenToUS the 1000 Bank objects can share the same instance of EuroToUS and YenToUS
final means that the value of these two variables are constant and therefore cannot be changed.
First it's a good indication for the programmer reading back your code it tells him immediatly that no where in the code he should expect to see EuroToUS = 1.11111 somewhere
However, if ever your user interface allows you to change the currency like if you where writting a method like this one:
public void setEuroCurrency(double newCurrency) {
EuroToUS = newCurrency;
}
you would have to remove the final in front of the variable declaration
Hope it helps
This post has been edited by pbl: 09 April 2008 - 06:41 AM
#5
Re: Where to start
Posted 09 April 2008 - 07:04 AM
Okay, I understand. Thank you for the explination. That little excerpt is all my book has regarding private, and I really didnt pick up too much from it. But your explination with the example was awesome!
Got to finish working on my printmenu, ect.
Got to finish working on my printmenu, ect.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|