Hi
In developing this code, I keep hitting setbacks and can't get past some of this. Any assistance would be greatly appreciated.
Develop a C# console application that implements two parallel int arrays in Main, one called apartment and the other called rent. Each array will hold 5 integer values. Use an initializer to fill the apartment array with the values{123, 204, 601, 609, 612}. Use an initializer to fill the rent array with the values {500, 750, 495, 800, 940}.
Create two static methods, one called getRent and one called printit. When the getRent method is called from Main you should pass the apartment array by reference, the rent array by reference and the apartment number console entry.
In the getRent method you should use a for loop to match apartment number passed to the method and match it to the apartment numbers in the apartment array that was passed to the getRent. When a match is found in the apartment number array call the printit method from the getRent method and pass by value the apartment number and the matching rent value from the rent array to the printit method.
In the printit method print the apartment number and the rent for that apartment to the console as shown in the output example below. When you print the output, instead of using a string concatenation (Console.WriteLine("Rent for apartment # " + choice + " is $" + rent);) use a StringBuilder object. The string parts of the message ("Rent for apartment #" and " is $") should be declared as separate strings. Using the StringBuilder object methods, you will append the two strings and two integer values together and write the final appended output to the console. The appends and output should all be done in the print method.
Enter the apartment number 601
Rent for apartment # 601 is $495
Press any key to continue . . .
Cheers & have a nice day
Loading

VulpesPosted Nov 6, 2013, 8:20 AM
SUNIL GUTTAPosted Nov 6, 2013, 11:50 AM
VulpesPosted Nov 6, 2013, 9:23 AM
However, the method parameters are not quite the same as what you're told to use in the instructions.
As far as getRent is concerned, you're told that the two arrays are to be passed by reference - I've no idea why as they're not being replaced within the method, though it does no harm.
printit is to be passed by value the apartment number and the matching rent value. You've done it instead by passing the arrays themselves and the index, i, of the match.
I don't know how closely they expect you to stick to the instructions though I thought I'd better point out these differences.
SUNIL GUTTAPosted Nov 6, 2013, 8:41 AM
So once can you check this and suggest me in-case gone hard or wrong way to get output .
Suggestions to improve the way things i am doing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Class4
{
public static void getrent(int x,int [] rent,int [] apartment)
{
for (int i = 0; i <= apartment.Length - 1; i++)
{
if (apartment[i] != x)
continue;
printit(i,rent,apartment);
}
}
public static void printit(int i,int [] rent,int [] apartment)
{
StringBuilder sb = new StringBuilder();
sb.Append(rent[i]);
Console.WriteLine("Rent for apartment # {0} is ${1}",apartment[i],rent[i].ToString());
}
static void Main()
{
int [] apartment = { 123, 204, 601, 605, 612 };
int [] rent = {500,750,455,800,540};
Console.Write("ENTER THE APARTMENT NO : ");
int y = Convert.ToInt32(Console.ReadLine());
Class4.getrent(y,rent,apartment);
Console.Write("Press any key to continue . . .");
Console.ReadKey();
}
}
}
Cheers ty mate
have a nice day