Write a c# console program called “ArrayOfThings” where you create a class called Staff with private fields for StaffID and StaffName. Create Properties that can write data and retrieve data from these private fields. Create a Staff array that can hold up to ten Staff objects. Create ten objects using a for loop that automatically creates a new (empty) Staff object at each iteration of the loop and adds that object into the Staff array. Write data into the first two objects in the Staff array and display their content.
code in c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ArrayOfThings
{
class Staff//calss staff
{
private int staffId;//private field id
private string staffName;//private field name
public Staff() { }//default constructor
public void setStaffId(int id)//method that set then id of the
staff
{
this.staffId = id;
}
public void setStafName(string name)//method that set the name of
the staff
{
this.staffName = name;
}
public string getStaffName()//method that return the name of the
staff
{
return this.staffName;
}
public int getStaffId()//method that return the id of the
staff
{
return this.staffId;
}
static void Main(string[] args)
{
Staff []s=new Staff[10];//creates the array of 10 Staff
objects
for (int i = 0; i < 10; i++)// loop that automatically creates a
new (empty) Staff object
{
s[i] = new Staff();
}
s[0].setStaffId(1001);//set the first staff id
s[0].setStafName("Jay");//set the first staff name
s[1].setStaffId(1002);//set the second staff id
s[1].setStafName("Viral");//set the second staff name
//prints the first two object of the staff object array
Console.WriteLine("Id of the first staff is :" + s[0].getStaffId()
+ " Name of first the staff :" + s[0].getStaffName());
Console.WriteLine("Id of the second staff is :" + s[1].getStaffId()
+ " Name of second the staff :" + s[1].getStaffName());
}
}
}
output
if you have any query
regarding the code please ask me in the comment i am here for the
help thank you. Please do thumbs up for me.
Write a c# console program called “ArrayOfThings” where you create a class called Staff with private...
Create a C# Console program. Add a class named Employee that has the following public fields: • Name. The name field references a String object that holds the employee’s name. • IDNumber. The IDNumber is an int that holds the employee’s ID number. • Department. The department field is a String that holds the name of the department where the employee works. • Position. The position field is a String that holds the employee’s job title. Once you have written...
In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....
In c++ Write a program that contains a class called Player. This class should contain two member variables: name, score. Here are the specifications: You should write get/set methods for all member variables. You should write a default constructor initializes the member variables to appropriate default values. Create an instance of Player in main. You should set the values on the instance and then print them out on the console. In Main Declare a variable that can hold a dynamcially...
7.2 Write a Java program called to create an Excel spreadsheet Create a class called Food to represent a Lunch food item. Fields include name, calories, carbs In a main method (of a different class), ask the user "How many things are you going to eat for lunch?". Loop through each food item and prompt the user to enter the name, calories, and grams of carbs for that food item. Create a Food object with this data, and store each...
Writing a code in C# console app Create class TicTacToe that will enable you to write a complete app to play the game of Tic-Tac-Toe. The class contains a private 3-by-3 rectangular array of integers. The constructor should initialize the empty board to all 0s. Allow two human players. Wherever the first player moves, place a 1 in the specified square, and place a 2 wherever the second player moves. Each move must be to an empty square. After each...
JAVA
1. Write a class called Rectangle that represents a rectangular two-dimensional region. Your Rectangle objects should have the following fields and methods: int width, int height Where width and height are the dimensions of the rectangle. Write accessor methods (i.e. getWidth(), getHeight()) that retrieve the values stored in the fields above. And mutator methods (i.e. setWidthl), setHeight() ) that change the field's values. Finally create a method called getAreal) that returns the area of the rectangle. Like we did...
PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property 1 constructor that takes 3 arguments pass each argument to the appropriate property Task 2 In a new file import the Window class Instantiate the Window object Output the two public properties Task 3 Alter the Window class in Task 1 Add an accessor and mutator (the ability to access and change) to the private property Task 4 Create a class named Instrument Give...
In Java
a. Create a class called StudentRecord that has the following private variables: year, GPA Implement 2 constructors: default constructor (doesn't take any parameters, has b. an empty body) and a constructor, that initializes all variables. according to the following template: Implement Comparable interface, so that StudentRecord class has ĢompareTo c. Implement a toString() method that returns text representation of an object First name: Benoit, last name: Mandelbrot, year: 3, GPA: 3.68 d. method, that performs comparison as the...
( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...
Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able to store information regarding the name, age, gpa, and phone number of a Student object. Please write all the setter and getter methods. Finally, write a Demo class to demonstrate the use of the class by creating two different objects. 2.Use the same Student class from the previous problem. This time,you will write a different Demo class, in which you will create three Student...