itortu
asked on
Help creating a method that obtains payments interactively.
Hi, I am new in java. this is my first semester taking it, and it is starting to get a little confusing for me.
I have created two classes: Lawn, and LawnService.The following code are the methods that
corresponds to the LawnService class.
public void processLawn() {
Lawn myLawn = new Lawn();
getLawnSizes(myLawn);
getNumberOfPayments(myLawn );
displayPaymentSummary(myLa wn);
System.exit(0);
}
I can figure out how to code the second method (getNumberOfPayments) This is what i coded: - the instructions, or what I am being asked to do, is also pasted -
Create a method, public void getNumberOfPayments(), with the Lawn object reference as an argument
* The payment option will be obtained from the user interactively with the following options.
This should use the input dialog box of the jOptionPane class.
A) One Payment, B) Two Payments, C) Twenty Payments.
code:
public void getNumberOfPayments(Lawn myLawn) {
String userInput;
char selection;
int number = 0;
userInput = JOptionPane.showInputDialo g(null, "\tOne Payment (A)\n\tTwo Payments (B)\n\tTwenty Payments (C)");
selection = userInput.charAt(0);
if (selection == 'A') {
number = 1;
} else if (selection == 'B') {
number = 2;
} else if (selection == 'C') {
number = 20;
}
myLawn.setPayment(number);
Then, I have to display the payment Information with the Lawn object reference as an argument displayPaymentSummary(myLa wn);
Display a jOptionPane message dialog box that tells the user the size of the lot and the number of payments and the amount of the payment. Here are some sample outputs:
"Your lot is 425 sq. ft. and you will be making one payment of $700.00"
"Your lot is 800 sq. ft. and you will be making twenty payments of $53.50"
All dollar amounts must be properly formatted, using an appropriate class from the java.text package
Use a StringBuffer to format display String.
This is what I have done so far, but eventhough is not complete, is not working, I was doing it on phases:
public void displayPaymentSummary(Lawn myLawn) {
double area = myLawn.obtainArea();
double payment = myLawn.obtainPaymentAmount ();
JOptionPane.showMessageDia log(null, "Your lot is " +
area + "sq. ft. and you will be making twenty payments of " + payment);
If you can offer me any help on this, it will be great. I know this is a long question, but any help is very much appretiated it.
Thank you so much in advance.
}
I have created two classes: Lawn, and LawnService.The following code are the methods that
corresponds to the LawnService class.
public void processLawn() {
Lawn myLawn = new Lawn();
getLawnSizes(myLawn);
getNumberOfPayments(myLawn
displayPaymentSummary(myLa
System.exit(0);
}
I can figure out how to code the second method (getNumberOfPayments) This is what i coded: - the instructions, or what I am being asked to do, is also pasted -
Create a method, public void getNumberOfPayments(), with the Lawn object reference as an argument
* The payment option will be obtained from the user interactively with the following options.
This should use the input dialog box of the jOptionPane class.
A) One Payment, B) Two Payments, C) Twenty Payments.
code:
public void getNumberOfPayments(Lawn myLawn) {
String userInput;
char selection;
int number = 0;
userInput = JOptionPane.showInputDialo
selection = userInput.charAt(0);
if (selection == 'A') {
number = 1;
} else if (selection == 'B') {
number = 2;
} else if (selection == 'C') {
number = 20;
}
myLawn.setPayment(number);
Then, I have to display the payment Information with the Lawn object reference as an argument displayPaymentSummary(myLa
Display a jOptionPane message dialog box that tells the user the size of the lot and the number of payments and the amount of the payment. Here are some sample outputs:
"Your lot is 425 sq. ft. and you will be making one payment of $700.00"
"Your lot is 800 sq. ft. and you will be making twenty payments of $53.50"
All dollar amounts must be properly formatted, using an appropriate class from the java.text package
Use a StringBuffer to format display String.
This is what I have done so far, but eventhough is not complete, is not working, I was doing it on phases:
public void displayPaymentSummary(Lawn
double area = myLawn.obtainArea();
double payment = myLawn.obtainPaymentAmount
JOptionPane.showMessageDia
area + "sq. ft. and you will be making twenty payments of " + payment);
If you can offer me any help on this, it will be great. I know this is a long question, but any help is very much appretiated it.
Thank you so much in advance.
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.javaalmanac.com/egs/java.text/FormatNum.html
getLawnSizes(myLawn); this method u can do as you have done for getNumberOfPayments method
for displaying the summary u just need to format the paymentamount
you can check out this for formatting the payment
http://www.iro.umontreal.ca/~vaucher/Java/tutorials/Formatting.html
for displaying the summary u just need to format the paymentamount
you can check out this for formatting the payment
http://www.iro.umontreal.ca/~vaucher/Java/tutorials/Formatting.html
ASKER
The parts of code that I pasted, are not working. I forgot to mention that. Sorry.