3 Replies - 983 Views - Last Post: 12 October 2009 - 04:04 PM Rate Topic: -----

#1 nelliegirl  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 147
  • Joined: 08-February 08

Inheritance Help

Post icon  Posted 12 October 2009 - 03:51 PM

I am so lost I need to create the OneDayLease as a subclass of Lease, implementing the LeaseInterface and the CompanyInterface. There are no attributes in addition to the Lease class attributes. The OneDayLease has the same end date as start date and the lease fee is a flat fee.
this is the lease class:
import java.util.*; // for Date and Calendar classes
public abstract class Lease
{
	// attributes
	private double amount=40;
	private Date startDate;
	private Date endDate;
	
	// constructor 
	public Lease(Date aStartDate)
				
	{
		setStartDate(aStartDate);
		setEndDate(null);
		setAmount(0);
	}

	// set accessor methods
	public void setAmount(double anAmount)
	{ amount = anAmount; }
	public void setStartDate(Date aStartDate)
	{ startDate = aStartDate; }
	public void setEndDate(Date anEndDate)
	{ endDate = anEndDate; }
		
	// get accessor methods
	public double getAmount()
	{ return amount; }
	public Date getStartDate()
	{ return startDate; }
	public Date getEndDate()
	{ return endDate; }
}



LeaseInterface:
public interface LeaseInterface
{
	// method all lease subclasses must include
	public abstract double calculateFee(int aWidth);
		
}


CompanyInterface:
public interface CompanyInterface
{
	// all classes must implement this method
	public abstract String tellAboutSelf();
	
	// constants with values all classes might need
	public static final String COMPANY_NAME = 
					"Bradshaw Marina"; 
	public static final String COMPANY_ADDRESS = 
					"PO Box 101 Lake Clinton"; 
	public static final String COMPANY_PHONE = 
					"(419) 555-8765"; 
}


This is what I have for OneDayLease but I am not sure I am doing this correctly. This is the part where I am lost.
I am not sure regarding lease fee.
import java.util.*;
public class OneDayLease extends Lease implements 
		LeaseInterface, CompanyInterface
{
	// constructor
	public OneDayLease(double anAmount, Date aStartDate)
	
	// invoke superclass constructor
		super(aStartDate);
		Calendar aCalendar = Calendar.getInstance();
		aCalendar.setTime(aStartDate);
		aCalendar.add(Calendar.DAY_OF_MONTH);
		setEndDate(aCalendar.getTime());
		setAmount
	
}



Is This A Good Question/Topic? 0
  • +

Replies To: Inheritance Help

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Inheritance Help

Posted 12 October 2009 - 03:58 PM

You are trying to implement/learn/master 2 concepts at a time:
- the inheritance
- the interface
try only one at a time... forget the interface for now
Was This Post Helpful? 1
  • +
  • -

#3 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Inheritance Help

Posted 12 October 2009 - 04:01 PM

in order to implement an interface you must override it's methods.
so your class OneDayLease must override the methods of the interfaces. which is not.

also, when declaring methods and variables inside an interface, the methods get by default "public abstract"
and variables get "public static final"
so you could declare CompanyInterface as
public interface CompanyInterface
{
	// all classes must implement this method
	String tellAboutSelf();
	
	// constants with values all classes might need
	String COMPANY_NAME = 
					"Bradshaw Marina"; 
	String COMPANY_ADDRESS = 
					"PO Box 101 Lake Clinton"; 
	String COMPANY_PHONE = 
					"(419) 555-8765"; 
}


Was This Post Helpful? 0
  • +
  • -

#4 nelliegirl  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 147
  • Joined: 08-February 08

Re: Inheritance Help

Posted 12 October 2009 - 04:04 PM

View Postjapanir, on 12 Oct, 2009 - 03:01 PM, said:

in order to implement an interface you must override it's methods.
so your class OneDayLease must override the methods of the interfaces. which is not.

also, when declaring methods and variables inside an interface, the methods get by default "public abstract"
and variables get "public static final"
so you could declare CompanyInterface as
public interface CompanyInterface
{
	// all classes must implement this method
	String tellAboutSelf();
	
	// constants with values all classes might need
	String COMPANY_NAME = 
					"Bradshaw Marina"; 
	String COMPANY_ADDRESS = 
					"PO Box 101 Lake Clinton"; 
	String COMPANY_PHONE = 
					"(419) 555-8765"; 
}



I get the interface for the company I am just having trouble codeing the OneDayLease.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1