TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
SUNIL GUTTA
NA
1k
394k
get & set accessor issue ?
Nov 13 2013 4:03 PM
Hi
this the sample code
class Class12
{
public static string last_name;
public static string first_name;
public static double gross_pay;
public void adjustPay(double gross_pay)
{
//adjust the pay by multiplying it by a factor of 1.2
gross_pay = gross_pay * 1.2;
Console.WriteLine("The adjusted pay is {0} for {1} {2}", gross_pay,first_name,last_name);
}
static void Main()
{
Console.Write("Enter the first name : ");
first_name = Console.ReadLine();
Console.Write("Enter the last name : ");
last_name = Console.ReadLine();
Console.Write("Enter the raw pay : ");
gross_pay = Convert.ToDouble(Console.ReadLine());
Class12 obj = new Class12();
obj.adjustPay(gross_pay);
Console.WriteLine("Press any key to continue . . .");
Console.ReadKey();
}
}
The issue here is code works cool but i want the same code implemented using get & set block i tried so like but issue is I
TS SHOWING ME 3 errors i.e you already have first_name , last_name ,gross_salary ..
I am confused donno what to do ?? any ideas
MY CODE : USING GET & SET
class Class12
{
string last_name;
string first_name;
double gross_pay;
public double gross_pay
{
get
{
return gross_pay;
}
set
{
value = gross_pay;
}
}
public string last_name
{
get
{
return last_name;
}
set
{
value = last_name;
}
}
public string first_name
{
get
{
return first_name;
}
set
{
value = first_name;
}
}
public Class12(string first_name, string last_name, double gross_pay)
{
this.first_name = first_name;
this.last_name = last_name;
this.gross_pay = gross_pay;
}
public void adjustPay()
{
//adjust the pay by multiplying it by a factor of 1.2
gross_pay = gross_pay * 1.2;
Console.WriteLine("The adjusted pay is {0} for {1} {2}", gross_pay,first_name,last_name);
}
static void Main()
{
Class12 obj = new Class12(first_name, last_name, gross_pay);
Console.Write("Enter the first name ");
obj.first_name = Console.ReadLine();
Console.Write("Enter the last name ");
obj.last_name = Console.ReadLine();
Console.Write("Enter the raw pay ");
obj.gross_pay = Convert.ToDouble(Console.ReadLine());
obj.adjustPay();
Console.WriteLine("Press any key to continue . . .");
Console.ReadKey();
}
}
Cheers TY
Reply
Answers (
5
)
constructor @ values passing ?
About Interview