Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,331 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,118 people online right now. Registration is fast and FREE... Join Now!




C# loan assignment terms not working

 
Reply to this topicStart new topic

C# loan assignment terms not working

deedee66
post 28 Sep, 2008 - 06:53 PM
Post #1


New D.I.C Head

*
Joined: 21 Sep, 2008
Posts: 16

hi,
I need help only the first two print out the third terms will not. Can someone tell me what I did wrong.

CODE
using System;
namespace CSharp.Ch4.Basics

{
public class Loan
{
    private float fLoanAmount;
    
public Loan(float fLoanAmount)
{
Console.WriteLine("Please enter an Loan Amount: ");
this.fLoanAmount = fLoanAmount;
}
public Loan()
{}
}
class Rate:Loan
{
private float referrerfLoanAmount;
//private double dPercentageRate;

public Rate(float fLoanAmount, float referrerfLoanAmount)
{
    Console.WriteLine("What is the Loan amount ");
    string LoanAmount;
    LoanAmount = Console.ReadLine();
    float a = float.Parse(LoanAmount);
    
    this.referrerfLoanAmount = referrerfLoanAmount;}
    public Rate(float fLoanAmount):this(fLoanAmount, 0)
{    
    Console.WriteLine("What is your Percentage Rate ");
    string PercentRate;
    PercentRate = Console.ReadLine();
    double a = double.Parse(PercentRate);
}
public Rate()
{}

class Terms : Loan
{
    //private float referrerfLoanAmount;
    private double referrerdPercentageRate;
    //private int iTermsYears;
    
    public Terms(double dPercentageRate, double referrerdPercentageRate)
    {
    Console.WriteLine("What is the Percentage rate of your Loan? ");
    this.referrerdPercentageRate = referrerdPercentageRate;}
    public Terms(double dPercentageRate):this(dPercentageRate, 0)
    {
        Console.WriteLine("What is are your Terms ");
        string Terms = Console.ReadLine();
        int a = int.Parse(Terms);
    }
    public Terms()
    {}
    }
    class MyLoan : Rate
    {
static void Main(string[] args)
{
Loan cust1 = new Rate(0);
}
}
}
}
User is offlineProfile CardPM

Go to the top of the page

vertizor
post 28 Sep, 2008 - 07:17 PM
Post #2


New D.I.C Head

*
Joined: 27 Sep, 2008
Posts: 9



Thanked 1 times
My Contributions


I'm not entirely sure what you want this bit of code to do. As it stands, you are instantiating a Rate object with one argument. Your constructor for Rate that takes one argument, first runs the constructor that takes two variables, and this causes a query and gets some input. Then when the 1-argument constructor continues execution, it again queries for some information and takes some input. That's all that happens - at this point cust1 is initialized, with private variable refferrerfLoanAmount set to 0, then your main function ends.
User is offlineProfile CardPM

Go to the top of the page

deedee66
post 28 Sep, 2008 - 07:28 PM
Post #3


New D.I.C Head

*
Joined: 21 Sep, 2008
Posts: 16

QUOTE(vertizor @ 28 Sep, 2008 - 08:17 PM) *

I'm not entirely sure what you want this bit of code to do. As it stands, you are instantiating a Rate object with one argument. Your constructor for Rate that takes one argument, first runs the constructor that takes two variables, and this causes a query and gets some input. Then when the 1-argument constructor continues execution, it again queries for some information and takes some input. That's all that happens - at this point cust1 is initialized, with private variable refferrerfLoanAmount set to 0, then your main function ends.



it is suppose to just get input for the loan amount, rate and terms and print out the input
it is suppose to be a exercise in abstract classes.
User is offlineProfile CardPM

Go to the top of the page

vertizor
post 29 Sep, 2008 - 08:13 PM
Post #4


New D.I.C Head

*
Joined: 27 Sep, 2008
Posts: 9



Thanked 1 times
My Contributions


QUOTE(deedee66 @ 28 Sep, 2008 - 08:28 PM) *

QUOTE(vertizor @ 28 Sep, 2008 - 08:17 PM) *

I'm not entirely sure what you want this bit of code to do. As it stands, you are instantiating a Rate object with one argument. Your constructor for Rate that takes one argument, first runs the constructor that takes two variables, and this causes a query and gets some input. Then when the 1-argument constructor continues execution, it again queries for some information and takes some input. That's all that happens - at this point cust1 is initialized, with private variable refferrerfLoanAmount set to 0, then your main function ends.



it is suppose to just get input for the loan amount, rate and terms and print out the input
it is suppose to be a exercise in abstract classes.



I'm afraid I still don't entirely understand, but maybe I do have some suggestions. First though - you are passing into your constructors values that look like what you then query the user for. If your passing them in, why query? If your going to query, make them constructors with no arguments. Following that, reasoning,

CODE

public class Loan
    {
        private float fLoanAmount;

        public Loan()
        {
            Console.WriteLine("Please enter an Loan Amount: ");
            //Note that Parse will throw an exception if the read-in value can't convert to a float
            this.fLoanAmount = float.Parse(Console.ReadLine());
        }
    }


If you change your Loan class to this, you will get the query for a Loan amount displayed. A more elegant way to get all 3 displayed would be

CODE

public class Loan
    {
        private float fLoanAmount;

        public Loan()
        {
            Console.WriteLine("Please enter an Loan Amount: ");
            //Note that Parse will throw an exception if the read-in value can't convert to a float
            fLoanAmount = float.Parse(Console.ReadLine());
        }
    }
    class Rate : Loan
    {
        private float referrerfLoanAmount;
        //private double dPercentageRate;

        public Rate()
        {
            Console.WriteLine("What is your Percentage Rate ");
            string PercentRate;
            PercentRate = Console.ReadLine();
            double a = double.Parse(PercentRate);
        }

        class Terms : Rate
        {
            private double referrerdPercentageRate;

            public Terms()
            {
                Console.WriteLine("What is are your Terms ");
                string Terms = Console.ReadLine();
                int a = int.Parse(Terms);
            }
        }
        class MyLoan : Rate
        {
            static void Main(string[] args)
            {
                Loan cust1 = new Terms();
            }
        }
    }


Note that I changed it so that Terms now extends Rate, as oppose to loan, so that when you make a Terms object it runs the constructors for both Loan and Rate. If this isn't what your assignment wants, you can of course do it however you need.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 02:57AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month