# Passing array problem

Page 1 of 1

## 2 Replies - 2494 Views - Last Post: 18 April 2010 - 01:31 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=168773&amp;s=e93c0af1acd68498ab4fba7aaaa1b4a5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 robjon68

Reputation: 0
• Posts: 2
• Joined: 18-April 10

# Passing array problem

Posted 18 April 2010 - 12:58 PM

I am stuck and need some guidance trying to complete this assignment:

1. Create a class named rates that has the following data members:
1. Income limit; use read-only accessor.
2. Low tax rate; use read-only accessor.
3. High tax rate; use read-only accessor.
4. A class constructor that assigns default values of limit=30000, low rate = .15 and high rate = .28.
5. A class constructor that takes three parameters to assign input values for limit, low rate and high rate.
6. A CalculateTax method that takes an income parameter and computes the tax as follows:
1. If income is less than the limit then return the tax as income times low rate.
2. If income is greater than or equal to the limit then return the tax as income times high rate.
2. Create a class named Taxpayer that has the following data members:
1. Social Security number (use type string, no dashes between groups). Use get and set accessors.
2. Yearly gross income. Use get and set accessors.
3. Tax owed. Use read-only accessor.
3. The Taxpayer class should be set up so that its objects are comparable to each other based on tax owed.
4. The tax should be calculated whenever the income is set.
5. The Taxpayer class should have a getRates class method that has the following:
1. Local method data members for income limit, low rate and high rate.
2. Prompt the user to enter a selection for either default settings or user input of settings.
3. If the user selects default the default values you will instantiate a rates object using the default constructor and set the Taxpayer class data member for tax equal to the value returned from calling the rates object CalculateTax method.
4. If the user selects to enter the rates data then prompt the user to enter values for income limit, low rate and high rate, instantiate a rates object using the three-argument constructor passing those three entries as the constructor arguments and set the Taxpayer class data member for tax equal to the value returned from calling the rates object CalculateTax method.
6. In Main:
1. instantiate an array of five (5) Taxpayer objects.
2. Implement a for-loop that will prompt the user to enter the Social Security Number and gross income.
3. Implement a for-loop that will display each object as formatted taxpayer SSN, income and calculated tax.
4. Implement a for-loop that will sort the five objects in order by the amount of tax owed and then display each object as formatted taxpayer SSN, income and calculated tax.
7. Internal documentation.

Possible output for the program would look like this:

Enter Social Security Number for taxpayer 1 555555555
Enter gross income for taxpayer 1 35000
Do you want default values (enter D) or enter your own (enter O)? d
Enter Social Security Number for taxpayer 2 111111111
Enter gross income for taxpayer 2 80000
Do you want default values (enter D) or enter your own (enter O)? o
Enter the dollar limit 50000
Enter the low rate .15
Enter the high rate .25
Enter Social Security Number for taxpayer 3 333333333
Enter gross income for taxpayer 3 45000
Do you want default values (enter D) or enter your own (enter O)? d
Enter Social Security Number for taxpayer 4 444444444
Enter gross income for taxpayer 4 65000
Do you want default values (enter D) or enter your own (enter O)? o
Enter the dollar limit 70000
Enter the low rate .10
Enter the high rate .20
Enter Social Security Number for taxpayer 5 222222222
Enter gross income for taxpayer 5 70000

Do you want default values (enter D) or enter your own (enter O)? d
Taxpayer # 1 SSN: 555555555 income \$35,000.00 Tax is \$9,800.00
Taxpayer # 2 SSN: 111111111 income \$80,000.00 Tax is \$20,000.00
Taxpayer # 3 SSN: 333333333 income \$45,000.00 Tax is \$12,600.00
Taxpayer # 4 SSN: 444444444 income \$65,000.00 Tax is \$6,500.00
Taxpayer # 5 SSN: 222222222 income \$70,000.00 Tax is \$19,600.00

--------------------------------

Taxpayer # 1 SSN: 444444444 income \$65,000.00 Tax is \$6,500.00
Taxpayer # 2 SSN: 555555555 income \$35,000.00 Tax is \$9,800.00
Taxpayer # 3 SSN: 333333333 income \$45,000.00 Tax is \$12,600.00
Taxpayer # 4 SSN: 222222222 income \$70,000.00 Tax is \$19,600.00
Taxpayer # 5 SSN: 111111111 income \$80,000.00 Tax is \$20,000.00
Press any key to continue . . .

Here is my code so far,

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignment5_Koch
{
class Rates
{

public Rates()
{
incomeLimit = 30000;
lowTaxRate = .15;
highTaxRate = .28;

}

public Rates(int limit, double lowRate, double highRate)
{
incomeLimit = limit;
lowTaxRate = lowRate;
highTaxRate = highRate;
}
public void CalculateTax(double income)
{
double tax;

if ( income < incomeLimit)
{
tax = income * lowTaxRate;
}
if (income > incomeLimit)
{
tax = income * highTaxRate;
}
Taxpayer tt = new Taxpayer();
tt.taxOwed = tax;
}
}

class Taxpayer : IComparable
{
public string socialSecurityNumber { get; set; }
public int yearlyGrossIncome { get; set; }

public void getRates()
{
int incomeLimit;
double lowRate;
double highRate;

Console.WriteLine("Do you want default values (enter D) or enter your own (enter O)?");
if (values == 'd' || values == 'D')
{
Rates deval = new Rates();
incomeLimit = deval.incomeLimit;
lowRate = deval.lowTaxRate;
highRate = deval.highTaxRate;
deval.CalculateTax(yearlyGrossIncome);

}
if (values == 'o' || values == 'O')
{
Console.WriteLine("Enter the dollar limit:");
Console.WriteLine("Enter the low rate:");
Console.WriteLine("Enter the high rate:");

}

}
}
class assignment5_Koch
{
public static void Main(string[] args)
{
string[] socialSecurityNumber = new string[5]; //array for SSNs
int[] grossIncome = new int[5];           //array for gross Incomes
double[] taxArray = new double[5];
string inputstring;

for (int x = 0; x < socialSecurityNumber.Length; ++x)
{
Console.WriteLine("Enter Social Security Number for taxpayer 1:");
socialSecurityNumber[0] = inputstring;
Console.WriteLine("Enter gross income for taxpayer 1:");
grossIncome[0] = Convert.ToInt32(inputstring);
Taxpayer own = new Taxpayer();
own.yearlyGrossIncome = grossIncome[0];
Rates tp1 = new Rates();
tp1.CalculateTax(own.yearlyGrossIncome);

own.getRates();
taxArray[0] = ;
}
for (int x = 0; x < socialSecurityNumber.Length; ++x)
{
Console.WriteLine("Taxpayer #1 SSN: {0} income \${1} Tax is \${2}",
}
}
}
}
```

Is This A Good Question/Topic? 0

## Replies To: Passing array problem

• Saucy!

Reputation: 6208
• Posts: 23,953
• Joined: 23-August 08

## Re: Passing array problem

Posted 18 April 2010 - 01:11 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
• Post the code you're having problems with
• Post the exact error you're receiving, if you are receiving one
• If no error explain what the code is doing versus what you want it to do
• Post your question in the body of your post, not the description field

### #3 robjon68

Reputation: 0
• Posts: 2
• Joined: 18-April 10

## Re: Passing array problem

Posted 18 April 2010 - 01:31 PM

This is my problem with this I do not know how to get a value that should be stored in an array and is input from a method transferred to another method?