I admit that I have struggled with ifthen statements and arr
I admit that I have struggled with if/then statements and arrays. I am trying to calculate fees for renting a television for a certain amount of weeks. Here is my code, when tested it does not return the correct values. Any help would be more than appreciated!
/**
* This class represents a television to be rented.
*
*/
public class Television implements Item
{
public static final double DELTA = 0.001;
private String Description;
private Money WeeklyRate;
private String Id;
private Money calculateFee;
private int size;
private String type;
private boolean rented;
private boolean returned;
private boolean isRented;
/**
* Constructor for objects of class Television.
*/
public Television()
{
this.Description = \"\";
this.WeeklyRate = new Dollar();
this.Id = \"\";
this.type = \"\";
this.size = 0;
this.calculateFee = null;
this.rented = false;
this.isRented = false;
this.returned = false;
}
/**
* Return the description of the Television.
* @return the description.
*/
public String getDescription()
{
return this.Description;
}
/**
* Change the description of the television to the
* given parameter.
* @param desc the new description.
*/
public void setDescription(String desc)
{
this.Description = desc;
}
/**
* Return the weekly rental rate for the television.
* @return the rate.
*/
public Money getWeeklyRate()
{
return WeeklyRate;
}
/**
* Change the weekly rental rate of the television
* to the given parameter.
* @param wklyRate the new weekly rate.
*/
public void setWeeklyRate(Money wklyRate)
{
this.WeeklyRate = wklyRate;
}
/**
* Return the ID of the television.
* @return the ID.
*/
public String getId()
{
return this.Id;
}
/**
* Change the ID of the television to the given
* parameter.
* @param idNum the new ID.
*/
public void setId(String idNum)
{
this.Id = idNum;
}
/**
* Calculate the fees for renting the television for a given
* number of weeks. The weekly rate must be set and the
* number of rental weeks must be valid in order for the fee
* to be calculated.
* @param weeks the number of rental weeks
* @return the fee or null if the fee could not be calculated
*/
public Money calculateFee(int weeks)
{
if (weeks == 0)
{
return null;
}
else if (weeks > 0 && weeks <= 4)
{
return WeeklyRate = WeeklyRate.mul(weeks);
}
return null;
}
/**
* Return the size of the television.
* @return the size.
*/
public int getSize()
{
return this.size;
}
/**
* Change the size of the television to the given
* parameter.
* @param screenSize the new size.
*/
public void setSize(int screenSize)
{
this.size = screenSize;
}
/**
* Return the type of the television.
* @return the type.
*/
public String getType()
{
return this.type;
}
/**
* Change the type of the television to the given
* parameter.
* @param screenType the new type.
*/
public void setType(String screenType)
{
this.type = screenType;
}
/**
* Indicate the television has been rented.
*/
public void rented()
{
this.rented = true ;
}
/**
* Indicate the television has been returned and is no
* longer rented.
*/
public void returned()
{
this.returned = false ;
}
/**
* Return the rental status of the television.
* @return true if the television is rented, otherwise false.
*/
public boolean isRented()
{
if (isRented == true)
{
return true;
}
else
return false ;
}
}
Solution
Please try this code:-
public Money calculateFee(int weeks)
{
if (weeks > 0 && weeks <= 4)
{
return WeeklyRate.mul(weeks);
}
return null;
}
If this also doesn\'t work, please send me the code for the mul() method of the WeeklyRate object.



