C
C#2y ago
ShadowX

❔ pls help

well im trying to figure out how to receive as an input a large number of workers in void main. can someone help?
using System;
public class Program
{
public class Worker
{
private int id;
private bool senior;
private int numHours;
public Worker(int id, int years)
{
this.numHours = 0;
if (years > 5)
{
this.senior = true;
}
else
this.senior = false;
}
public int Salary()
{
if (this.senior == true)
return (55 * this.numHours);
else
return (45 * this.numHours);
}
public void print()
{
if (this.senior == true)
Console.WriteLine("monyanyo"+55*this.numHours);
else
Console.WriteLine("monyanyo"+45*this.numHours);
}
}
public static void Main(string[] args)
{

}
}
using System;
public class Program
{
public class Worker
{
private int id;
private bool senior;
private int numHours;
public Worker(int id, int years)
{
this.numHours = 0;
if (years > 5)
{
this.senior = true;
}
else
this.senior = false;
}
public int Salary()
{
if (this.senior == true)
return (55 * this.numHours);
else
return (45 * this.numHours);
}
public void print()
{
if (this.senior == true)
Console.WriteLine("monyanyo"+55*this.numHours);
else
Console.WriteLine("monyanyo"+45*this.numHours);
}
}
public static void Main(string[] args)
{

}
}
4 Replies
rick_o_max
rick_o_max2y ago
Where u want to receive it from? You can receive it as your command-line arguments (which will be stored in args) You can receive it from an external connection, like pipes, etc
Angius
Angius2y ago
"receive a large amount of workers in void main"...? Could you elaborate?
Lexaro
Lexaro2y ago
To receive a large number of workers in void Main, you can use a loop to read the input and create the worker objects.
public static void Main(string[] args)
{
Console.WriteLine("Enter the number of workers:");
int numWorkers = int.Parse(Console.ReadLine());

Worker[] workers = new Worker[numWorkers];

for (int i = 0; i < numWorkers; i++)
{
Console.WriteLine("Enter the worker id:");
int id = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the worker years of experience:");
int years = int.Parse(Console.ReadLine());
workers[i] = new Worker(id, years);
}

Console.WriteLine("Workers Details:");
for (int i = 0; i < numWorkers; i++)
{
Console.WriteLine("Worker " + (i + 1) + ":");
workers[i].print();
}
}
public static void Main(string[] args)
{
Console.WriteLine("Enter the number of workers:");
int numWorkers = int.Parse(Console.ReadLine());

Worker[] workers = new Worker[numWorkers];

for (int i = 0; i < numWorkers; i++)
{
Console.WriteLine("Enter the worker id:");
int id = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the worker years of experience:");
int years = int.Parse(Console.ReadLine());
workers[i] = new Worker(id, years);
}

Console.WriteLine("Workers Details:");
for (int i = 0; i < numWorkers; i++)
{
Console.WriteLine("Worker " + (i + 1) + ":");
workers[i].print();
}
}
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts