© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
133 replies
strikeouts27

I need help declaring an array of objects where the attributes of the properties are user inputted.

I have been tasked with creating an array of objects.

The Application for my assignment says that I need to create a job array in which the user is prompted for details to fill out the form. A job number, a name of the business, the hours it takes for the job to be completed.....

The first thing that I do is create a job class.

        // Job Class 
        public class Job()
        {
            private int jobNumber = 0;
            private string customerName;
            private string businessName;
            private int jobHours;
            private double price;
            public int CreateJobNumber(int jobNumber)
            {
                this.jobNumber++;

                return jobNumber;
            }

                        public int jobNumber { get; set; }
            public string customerName { get; set; }
            public string businessName { get; set; }
            public int jobHours { get; set; }
            public double price { get; set; }
        // Job Class 
        public class Job()
        {
            private int jobNumber = 0;
            private string customerName;
            private string businessName;
            private int jobHours;
            private double price;
            public int CreateJobNumber(int jobNumber)
            {
                this.jobNumber++;

                return jobNumber;
            }

                        public int jobNumber { get; set; }
            public string customerName { get; set; }
            public string businessName { get; set; }
            public int jobHours { get; set; }
            public double price { get; set; }


Easy peasy, than I deciare the job object


// job order array initialization 
jobOrders[] jobOrder = new jobOrder[4]; 
// job order array initialization 
jobOrders[] jobOrder = new jobOrder[4]; 


So I have to activate the class and create the objects.
jobOrder[0] = new jobOrder;
I say to myself what can I use to loop through this array and assign objects to each slot in the array. And when I do so I require the user to be prompted to input data.

So my question is, do I use a for loop and prompt the user for each attribute and than somehow assign it to an object?

Or do I use a constructor and make the object?

I am a little lost because this requires user input.

public CreateJob()
{
jobOrders[] jobOrder = new jobOrder[4];

for (int i = 0; i < jobOrders.Length; ++i)
Console.WriteLine($"Enter job number {i}");
Console.WriteLine($"Enter customer name {customerName}");
jobOrders[i].customerName = Console.ReadLine();

}
```
Solution Output

An example of the expected program is shown below:

Enter job number 1
Enter customer name Bobbi
Enter description Carpet Cleaning
Enter estimated hours 4
Enter job number 2
Enter customer name Sarah
Enter description Flooding
Enter estimated hours 12
Enter job number 3
Enter customer name Taylor
Enter description Flooring
Enter estimated hours 12
Enter job number 4
Enter customer name Sam
Enter description Gardening
Enter estimated hours 6
Enter job number 5
Enter customer name Alex
Enter description Renovations
Enter estimated hours 60

Summary:

RushJob 1 Bobbi Carpet Cleaning 4 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $330.00
RushJob 2 Sarah Flooding 12 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $690.00
RushJob 3 Taylor Flooring 12 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $690.00
RushJob 4 Sam Gardening 6 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $420.00
RushJob 5 Alex Renovations 60 hours @$45.00 per hour. Rush job adds 150 premium. Total price is $2,850.00

Total for all jobs is $4,980.00
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Next page

Similar Threads

❔ Where are my properties?
C#CC# / help
3y ago
✅ I need help with explanation of given entity attributes
C#CC# / help
6mo ago