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

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++ 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...
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
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor...
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor should take the name of a file as an argument A method save (String line): This method should open the file defined by the constructor, save the string value of line at the end of the file, and then close the file. - In the same package create a new Java class and it DisplayFile in which write the following: Constructor: The class's constructor...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT