Results 1 to 3 of 3
  1. #1
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Default 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:
    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;
     	}
     }
    Thanks.
    Daniel:o
    Last edited by Daniel; 07-01-2007 at 04:27 AM.

  2. #2
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default

    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:
    Java Code:
    totalCost = downPay + monthPay * numMonths;  // again, this has to be figured out
     
     if( milesDriven > maxFreeMiles )
         totalCost += (milesDriven - maxFreeMiles ) * overMaxMiles;
    Albert:rolleyes:

  3. #3
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default

    This should be better:
    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;
     		
     	}
    Greetings.

    Marcus:cool:

Similar Threads

  1. How to initialize a two dimensional Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:48 PM
  2. How to initialize an Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:47 PM
  3. Initialize variables before use
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 11:22 AM
  4. How to initialize array at runtime
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-09-2007, 03:47 PM
  5. Initialize array at runtime
    By javaplus in forum Java Tip
    Replies: 2
    Last Post: 11-09-2007, 11:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •