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
A A
NA
21
11.9k
How to print all user input in Main through set and get?
Oct 22 2013 11:01 PM
Hello to all, my code almost does everything i want it just does not do it how i want. for example in my EMPLOYEE class i used properties (set and get) to ask the user questions and then i want MAIN to print the results, BUT my program DOES NOT do 2 things. 1st when it prints the results, it prints what the user input right after it asks the question for example:
"Please enter your name: JOHN DOE <<<USER INPUT.
"Name: JOHN DOE.
"Please enter your social security number: 123123123
"Social Security number: 123123123
etc.... I want my program to ask all the questions first then print the results after but i dont know how.
The 2nd thing my program does not do is calculate the pay and print if there was overtime pay it just shows 0.
class Person
{
protected string name, segsoc;//i CANNOT change anything in this class
//Constructor
//Does not recieve data to create the person
//puts default data
public Person()
{
name = "";
segsoc = "";
Console.WriteLine("Person constructed.");
}
//Destroyer
~Person()
{
Console.WriteLine("Person destroyed.");
}
class Employee : Person//In this class i can ONLY have 2 METHODS, a constructor and //destroyer, the rest im trying to achieve through properties.
//all the propeties and variables i need.
{
private double p, hrs, final;
private string theName, segs;
public Employee()
{
Console.Write("Employee constructed.");
}
public string name
{
set
{
theName = value;
}
get
{
Console.Write("Please Enter your name: ");//would i have to put all the //questions in one property?
theName = Console.ReadLine();
return theName;
}
}
public string segsoc
{
set
{
segs = value;
}
get
{
Console.Write("Please Enter your Social Security: ");
segs = Console.ReadLine();
return segs;
}
}
public double pay
{
set
{
p = value;
}
get
{
Console.Write("Please Enter your payrate: ");// this question does not get //asked, i dont understand why?
p = double.Parse(Console.ReadLine());
return p;
}
}
public double hours
{
set
{
hrs = value;
}
get
{
Console.Write("Please Enter the number of hours you worked: ");//This //question does not get asked, i dont understand why?
hrs = double.Parse(Console.ReadLine());
return hrs;
}
}
public double fin//this property does not calcualate what i want. The final result is 0 //when i execute the program
{
set
{
final = value;
}
get
{
if (hrs > 0 || hrs <= 40)
{
final = final * pay;
}
else if (hours > 40)
{
Console.WriteLine("You get payed double for overtime!");
final = final * (pay * 2.0);
}
else
{
do
{
Console.Write("Please valid hours!");
final = double.Parse(Console.ReadLine());
} while (hrs < 0);
}
return final;
}
}
~Employee()
{
Console.WriteLine("Employee destroyed.");
}
static void Main(string[] args)//i want main to print all the information the user input
{
Employee worker = new Employee();
Console.WriteLine("\n\n===Employee Information===");
Console.WriteLine("Name : " + worker.name);//this prints but it prints right after you enter it
Console.WriteLine("Social Security: " + worker.segsoc);//this prints but right after you enter it.
Console.WriteLine("Payrate : " + worker.p);//this prints 0
Console.WriteLine("Hours : " + worker.hrs);//this prints 0
Console.WriteLine("Pay : " + worker.fin);//this prints 0
Console.WriteLine("\n==========================");
}
}
}
}
Reply
Answers (
1
)
Please help with an array.
Category subcategory tree