Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
The abstract superclass Funds should have 2 methods - a set and get method to store the principleAmount.

Two methods are needed for sub class Guarantee- a set and get method to calculate the interest earned. Use the formula: principleAmount * rate * years (rate and years are arguments passed to the method).

Two methods are needed for sub class CompoundInterest - a set and get method to calculate the compoundInterest. Use the formula: principleAmount * Math.pow((1 + rate),years). Again, rate and years are arguments passed to the method.

Two methods are needed for sub class Loan - a set and get method to calculate the totalLoanAmount. Use the formula: (principleAmount * Rate * Years) + principleAmount. Again, rate and years are arguments passed to the method.

In the main method, you should ask the user for three pieces of information - enter the principle amount, rate, and years. Set the principle amount in the superclass Funds method, and use the rate and years as parameters to the other methods. Once you do the calculations for the 3 sub classes, display your result. Here is a sample result:

Input principle amount: 1000
Input rate: 0.05
Number of years: 5

With a principle amount of 1000.00 , an interest rate of 0.05, and 5 years, you would have earned 250.00

With a principle amount of 1000.00 , an interest rate of 0.05, and 5 years, you would have compound interest of 1276.28

With a principle amount of 1000.00 , an interest rate of 0.05, and 5 years, you would have a total loan payment of 1250.00
Posted
Updated 10-May-11 5:34am
v2
Comments
Marc A. Brown 10-May-11 11:35am    
What's your question? What have you tried? What specific issues have you encountered?
Dylan Morley 10-May-11 11:38am    
PLZ DO MY HOMEWORKZ
Fredrik Bornander 10-May-11 11:40am    
You should find a new teacher, this assignment is rubbish.
Member 7912316 10-May-11 12:21pm    
Why is that?
Fredrik Bornander 10-May-11 12:30pm    
The inheritance suggested in this assignment doesn't make sense. A CompoundInterest isn't a Fund so there's not a Is-A relationship here.
Composition is probably a better way of solving it.

Read the posting guidelines[^] - no-one is going to do your work for you.
 
Share this answer
 
It does not work like this here. I am sorry but there is no quick question here. This sounds like your college project/assignment, you should put some effort.

We expect you to put some time in trying the issue that you are facing and then some time in formulating the question while posting here.

Here is what is expected by enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.
 
Share this answer
 
Is Google down again? damn, one cannot depend on those "New Economy" companies!

If you where just half as smart as you think you are you'd find the answer.
But remember - your teacher knows those sites too and is able to see if you've written it yourself.
 
Share this answer
 
I got this so far. What am I doing wrong?

public class Polymorphism 
{
	/**
	 * 
	 */
	public static void main(String[] args) 
	{
		// TODO Auto-generated method stub
		Guarantee guarantee1= new Guarantee();
		CompoundInterest compoundInterest1= new CompoundInterest();
		Loan loan1=new Loan();
		
		Scanner input= new Scanner( System.in);
		
		
		// get numbers of screen
		double principle;// 
		double rate;// 
		int years;
		
		System.out.print("Enter principle:");//
		principle= input.nextDouble();// 
		System.out.print("Enter rate:");// 
		rate= input.nextDouble();// 
		System.out.print("Enter years:");//
		years= input.nextInt();// 

		guarantee1.setPrincipleAmount(principle);
		guarantee1.setInterestEarned(rate, years);
	
		
		
		//System.out.printf("Total earned money is\n" +"principleAmount\n" +"InterestEarned\n" +"CompoundInterest\n" + "totalLoanAmount");
		System.out.printf("principle amount of %.2f, An interest rate of %f, you would have earned %.2f",principle, rate, guarantee1.getInterestEarned() );
		
		System.out.print("Enter principle:");//
		principle= input.nextDouble();// 
		System.out.print("Enter rate:");// 
		rate= input.nextDouble();// 
		System.out.print("Enter years:");//
		years= input.nextInt();// 
		
		//
		compoundInterest1.setCompoundInterest(rate,years); 
		
		System.out.printf("Principle amount of %.2f, An interest rate of %.2f, you would have earned %.2f", principle, rate, compoundInterest1.getCompoundInterest());
	
	}
} 
abstract class Funds
{
	
	public double principleAmount;	
	public void setPrincipleAmount(double principle)
	
		{  
			principleAmount =principle;
		
		}
	public double setPrincipleAmount()
	{
		return principleAmount;
	}
		
				
	}


class Guarantee extends Funds

{
	public double InterestEarned;
	public void setInterestEarned(double rate,int years)
	 
	{
		InterestEarned= principleAmount*rate*years;
	}
	
	public double getInterestEarned()
	{
		return InterestEarned;
	}
}

class CompoundInterest extends Funds

{	
	public double CompoundInterest;
	public void setCompoundInterest(double rate,int years)
	{
		CompoundInterest = principleAmount * Math.pow((1+rate),years);
	}
	
		public double getCompoundInterest()
		
		{ 
			return CompoundInterest;
		}
	}


class Loan extends Funds

{
	public double totalLoanAmount;
	
	public void setTotalLoanAmount(double rate, int years)
	{ 
		totalLoanAmount = principleAmount*rate*years +principleAmount;
	}
	
	public double getTotalLoanAmount()
	{
		return totalLoanAmount; 
	}
}
 
Share this answer
 
v2
Comments
Richard MacCutchan 11-May-11 16:10pm    
For a start you did not read the guidelines properly. Use <pre> tags around your code so that we can at the very least read it.
Member 7912316 11-May-11 17:14pm    
That better?
Nagy Vilmos 12-May-11 6:46am    
Answering someone's post is best done with the 'Reply' button.
Nagy Vilmos 13-May-11 7:10am    
See my answer
If you want someone to write your code for you, try vWorker.
 
Share this answer
 
Use constructors:
Java
abstract class Funds
{

    private double principleAmount;
    public Funds(double principle) {
        this.principleAmount = principle;
    }

    public double getPrincipleAmount()
    {
        return this.principleAmount;
    }
}


Inheritence:
Java
class Guarantee extends Funds

{
    private double InterestEarned;

    public Guarantee(double principleAmount, double rate,int years)

    {
        super(principleAmount);
        InterestEarned = principleAmount * rate * years;
    }

    public double getInterestEarned()
    {
        return InterestEarned;
    }
}


Note member variables are private, you're asking for trouble otherwise.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900