Question

In: Computer Science

Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions:...

Visual Studio C#

Create an application illustrating the following:

  • Class definition
  • Encapsulation
  • Constructor
  • Instantiation
  • Inheritance

Suggestions:

  • Simulation
  • Calculation
  • Interface apps

Solutions

Expert Solution

using System;
class Employee // class definition
{
//Encapsulation of variables and methods in class
private String name;
private int empNum;
  
//properties
public string Name
{

get
{
return name;
}
set
{
name = value;
}
}
  
public int EmpNum
{

get
{
return empNum;
}
set
{
empNum = value;
}
}

//constructor
public Employee(string name,int empNum)
{
  this.name = name;
this.empNum = empNum;

}

public string toString()
{
return "\nEmployee Number : "+empNum +" Name : "+name;
}
}
class ProductionWorker : Employee // derived class , inheritance
{
private int shift;
private double hourlyPayRate;
  
//properties
public int Shift
{
   get
   {
       return shift;
   }
   set
   {
       shift = value;
   }
}
public double HourlyPayRate
{
   get
   {
       return hourlyPayRate;
   }
   set
   {
       hourlyPayRate = value;
   }
}

//passing parameters to base class Employee from derived class ProductionWorker
public ProductionWorker(String name,int empNum,int shift,double hourlyPayRate): base(name,empNum)
{
this.shift = shift;
this.hourlyPayRate = hourlyPayRate;
}


public string toString()
{
return base.toString() + "\nShift : "+shift + " Hourly Pay Rate : $"+hourlyPayRate;
}
}

  
public class Test
{
   public static void Main()
   {
   Console.WriteLine("Enter the name of Employee : ");
string name = Console.ReadLine();
Console.WriteLine("Enter the Employee number : ");
int empNum = Convert.ToInt32(Console.ReadLine());
  
Console.WriteLine("Enter the shift : ");
int shift = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the hourly Pay rate : ");
double hpr = Convert.ToDouble(Console.ReadLine());
  
ProductionWorker pc = new ProductionWorker(name,empNum,shift,hpr); // instantiation
  
  
Console.WriteLine("Employee Number : "+pc.EmpNum);
Console.WriteLine("Employee Name : "+pc.Name);
Console.WriteLine("Employee Shift : "+pc.Shift);
Console.WriteLine("Employee Hourly Pay rate : $"+pc.HourlyPayRate);
  
  
  
   }
}

Output:

Enter the name of Employee : James Clark Enter the Employee number : 6670 Enter the shift : 1 Enter the hourly Pay rate : 50.78 Employee Number : 6670 Employee Name : James Clark Employee Shift : 1 Employee Hourly Pay rate : $50.78

Do ask if any doubt. Please up-vote.



Related Solutions

Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
The solution has to be written on C++ Visual Studio Thank you (Package Inheritance Hierarchy) Package-delivery...
The solution has to be written on C++ Visual Studio Thank you (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use class Package as the base class of the hierarchy, then include classes TwoDayPackage and OvernightPackage that derive from Package. Base class Package should include data members representing the name, address, city, state and ZIP...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT