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
Febe
NA
4
1.4k
C# constructor and methods
Jul 24 2014 2:01 PM
Consider this example code illustrating how to use the constructor and methods of the class
WorkRecord
that stores a name and a number of hours worked:
WorkRecord wA = new WorkRecord("Andy");
//
hours
== 0
WorkRecord wG = new WorkRecord("George");
//
hours
== 0
wG.AddHours(3); //
update
hours
: 0+3=3
Console.WriteLine(wG.GetHours());
//
prints
3
wG.AddHours(2); //
update
hours
: 3+2=5
Console.WriteLine(wG);
//
prints
George: 5 hours
Console.WriteLine(wA);
//
prints
Andy: 0 hours
How do you complete the code for the constructor and the three methods in the class
WorkRecord
below?
public class WorkRecord
{
private String name;
// private instance variables for WorkRecord
private int hours;
/**
Construct
a WorkRecord
for the specified
name
,
with initial
hours
0
.
public WorkRecord(string name)
// the constructor β code it!
{
}
/** Return the number of hours in this WorkRecord. */
public int GetHours()
// a getter method β code it!
{
}
/** Update the number of hours when
moreHours
further hours are worked. */
public void AddHours(int moreHours)
// an instance method β code it!
{
}
/** Return a string in the form like the example:
Andy: 15 hours
*/
public override string ToString()
// the overridden ToString β code it!
{
}
}
Reply
Answers (
1
)
Semantic Zooming
clear variable value of edit employee after pass the value