Results 1 to 3 of 3
- 07-01-2007, 04:25 AM #1
Member
- Join Date
- Jun 2007
- Posts
- 91
- Rep Power
- 0
I do not know how to initialize the two variables
Hi, Your class will have an additional method that computes and returns the actual cost per month. This is defined as the total cost divided by the number of months.
I do not know how to initialize the two variables. help me please
this is my code:
Thanks.Java Code:public class LeaseEval { private String custName; // customer's name private double monthPay; // monthly payment private int termLease; // the term of the lease in months private double downPay; // down payment private int maxFreeMiles; // maximun amount of free miles private int overMaxMiles; // The charge per mile for all miles over the max private double milesDriven; // The number of miles actually driven // I create a constructor public LeaseEva(String theCustName, double theMonthPay, int theTermLease, double theDownPay, int theMaxFreeMiles, int theOverMaxMiles, double theMilesDriven) { custName = theCustName; monthPay = theMonthPay; termLease = theTermLease; downPay = theDownPay; maxFreeMiles = theMaxFreeMiles; overMaxMiles = theOverMaxMiles; milesDriven = theMilesDriven; } // Here are the "gets" for the variables public String getTheCustName() { return custName; } public double getTheMonthPay() { return monthPay; } public int getTheTermLease() { return termLease; } public double getTheDownPay() { return downPay; } public int getTheMaxFreeMiles() { return maxFreeMiles; } public int getTheOverMaxMiles() { return overMaxMiles; } public double getTheMilesDriven() { return milesDriven; } // the mathematical part of the program is here public double costperMonth() { double totalCost; double numMonths; double costMonth; // THESE TWO VARIABLES totalCost = numMonths = costMonth = totalCost/numMonths; return costMonth; } }
Daniel:oLast edited by Daniel; 07-01-2007 at 04:27 AM.
- 07-01-2007, 04:35 AM #2
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
It would help to see the math involved. That is, based on the variable names it is a bit tough to determine the algorithm to use. The biggest thing I don't know is the length of time in months. We need a start month and year if you want to compare it to, for example, today.
But totalCost might be something like:
Albert:rolleyes:Java Code:totalCost = downPay + monthPay * numMonths; // again, this has to be figured out if( milesDriven > maxFreeMiles ) totalCost += (milesDriven - maxFreeMiles ) * overMaxMiles;
- 07-01-2007, 04:42 AM #3
Member
- Join Date
- Jun 2007
- Posts
- 92
- Rep Power
- 0
This should be better:
Greetings.Java Code:public double getcostperMonth() { double totalCost; double numMonths; double costMonth; totalCost = downPay + (monthPay * termLease); totalCost += (milesDriven - maxFreeMiles ) * overMaxMiles; double costperMonth = totalCost / termLease; return costperMonth; }
Marcus:cool:
Similar Threads
-
How to initialize a two dimensional Array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:48 PM -
How to initialize an Array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:47 PM -
Initialize variables before use
By Java Tip in forum Java TipReplies: 0Last Post: 12-22-2007, 11:22 AM -
How to initialize array at runtime
By Java Tip in forum Java TipReplies: 0Last Post: 11-09-2007, 03:47 PM -
Initialize array at runtime
By javaplus in forum Java TipReplies: 2Last Post: 11-09-2007, 11:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks