In C# using System; using static System.Console; using System.Globalization; class JobDemo4 { static void Main() { RushJob[] jobs = new RushJob[5]; int x, y; double grandTotal = 0; bool goodNum; for(x = 0 ; x < jobs.Length; ++x) { jobs[x] = new RushJob(); Write("Enter job number "); jobs[x].JobNumber = Convert.ToInt32(ReadLine()); goodNum = true; for(y = 0; y < x; ++y) { if(jobs[x].Equals(jobs[y])) goodNum = false; } while(!goodNum) { Write("Sorry, the job number " + jobs[x].JobNumber + " is a duplicate. " + "\nPlease reenter "); jobs[x].JobNumber = Convert.ToInt32(ReadLine()); goodNum = true; for(y = 0; y < x; ++y) { if(jobs[x].Equals(jobs[y])) goodNum = false; } } Write("Enter customer name "); jobs[x].Customer = ReadLine(); Write("Enter description "); jobs[x].Description = ReadLine(); Write("Enter estimated hours "); jobs[x].Hours = Convert.ToDouble(ReadLine()); } WriteLine("\nSummary:\n"); for(x = 0; x < jobs.Length; ++x) { WriteLine(jobs[x].ToString()); grandTotal += jobs[x].Price; } WriteLine("\nTotal for all jobs is " + grandTotal.ToString("C", CultureInfo.GetCultureInfo("en-US"))); } } class Job { protected double hours; protected double price; public const double RATE = 45.00; public Job(int num, string cust, string desc, double hrs) { JobNumber = num; Customer = cust; Description = desc; Hours = hrs; } public int JobNumber {get; set;} public string Customer {get; set;} public string Description {get; set;} public double Hours { get { return hours; } set { hours = value; price = hours * RATE; } } public double Price { get { return price; } } public override string ToString() { return(GetType() + " " + JobNumber + " " + Customer + " " + Description + " " + Hours + " hours @" + RATE.ToString("C") + " per hour. Total price is " + Price.ToString("C", CultureInfo.GetCultureInfo("en-US"))); } public override bool Equals(Object e) { bool equal; Job temp = (Job)e; if(JobNumber == temp.JobNumber) equal = true; else equal = false; return equal; } public override int GetHashCode() { return JobNumber; } } class RushJob : Job { public const double PREMIUM = 150.00; public RushJob() :base(0, "", "", 0) { } public override string ToString() { return(GetType() + " " + JobNumber + " " + Customer + " " + Description + " " + Hours + " hours @" + RATE.ToString("C") + " per hour. Rush job adds " + PREMIUM + " premium. Total price is " + Price.ToString("C", CultureInfo.GetCultureInfo("en-US"))); } public new double Hours { get { return hours; } set { hours = value; price = hours * RATE + PREMIUM; } } }
In C# using System; using static System.Console; using System.Globalization; class JobDemo4 { static void Main() { RushJob[] jobs = new RushJob[5]; int x, y; double grandTotal = 0; bool goodNum; for(x = 0 ; x < jobs.Length; ++x) { jobs[x] = new RushJob(); Write("Enter job number "); jobs[x].JobNumber = Convert.ToInt32(ReadLine()); goodNum = true; for(y = 0; y < x; ++y) { if(jobs[x].Equals(jobs[y])) goodNum = false; } while(!goodNum) { Write("Sorry, the job number " + jobs[x].JobNumber + " is a duplicate. " + "\nPlease reenter "); jobs[x].JobNumber = Convert.ToInt32(ReadLine()); goodNum = true; for(y = 0; y < x; ++y) { if(jobs[x].Equals(jobs[y])) goodNum = false; } } Write("Enter customer name "); jobs[x].Customer = ReadLine(); Write("Enter description "); jobs[x].Description = ReadLine(); Write("Enter estimated hours "); jobs[x].Hours = Convert.ToDouble(ReadLine()); } WriteLine("\nSummary:\n"); for(x = 0; x < jobs.Length; ++x) { WriteLine(jobs[x].ToString()); grandTotal += jobs[x].Price; } WriteLine("\nTotal for all jobs is " + grandTotal.ToString("C", CultureInfo.GetCultureInfo("en-US"))); } } class Job { protected double hours; protected double price; public const double RATE = 45.00; public Job(int num, string cust, string desc, double hrs) { JobNumber = num; Customer = cust; Description = desc; Hours = hrs; } public int JobNumber {get; set;} public string Customer {get; set;} public string Description {get; set;} public double Hours { get { return hours; } set { hours = value; price = hours * RATE; } } public double Price { get { return price; } } public override string ToString() { return(GetType() + " " + JobNumber + " " + Customer + " " + Description + " " + Hours + " hours @" + RATE.ToString("C") + " per hour. Total price is " + Price.ToString("C", CultureInfo.GetCultureInfo("en-US"))); } public override bool Equals(Object e) { bool equal; Job temp = (Job)e; if(JobNumber == temp.JobNumber) equal = true; else equal = false; return equal; } public override int GetHashCode() { return JobNumber; } } class RushJob : Job { public const double PREMIUM = 150.00; public RushJob() :base(0, "", "", 0) { } public override string ToString() { return(GetType() + " " + JobNumber + " " + Customer + " " + Description + " " + Hours + " hours @" + RATE.ToString("C") + " per hour. Rush job adds " + PREMIUM + " premium. Total price is " + Price.ToString("C", CultureInfo.GetCultureInfo("en-US"))); } public new double Hours { get { return hours; } set { hours = value; price = hours * RATE + PREMIUM; } } }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
In C#
using System;
using static System.Console;
using System.Globalization;
class JobDemo4
{
static void Main()
{
RushJob[] jobs = new RushJob[5];
int x, y;
double grandTotal = 0;
bool goodNum;
for(x = 0 ; x < jobs.Length; ++x)
{
jobs[x] = new RushJob();
Write("Enter job number ");
jobs[x].JobNumber = Convert.ToInt32(ReadLine());
goodNum = true;
for(y = 0; y < x; ++y)
{
if(jobs[x].Equals(jobs[y]))
goodNum = false;
}
while(!goodNum)
{
Write("Sorry, the job number " +
jobs[x].JobNumber + " is a duplicate. " +
"\nPlease reenter ");
jobs[x].JobNumber = Convert.ToInt32(ReadLine());
goodNum = true;
for(y = 0; y < x; ++y)
{
if(jobs[x].Equals(jobs[y]))
goodNum = false;
}
}
Write("Enter customer name ");
jobs[x].Customer = ReadLine();
Write("Enter description ");
jobs[x].Description = ReadLine();
Write("Enter estimated hours ");
jobs[x].Hours = Convert.ToDouble(ReadLine());
}
WriteLine("\nSummary:\n");
for(x = 0; x < jobs.Length; ++x)
{
WriteLine(jobs[x].ToString());
grandTotal += jobs[x].Price;
}
WriteLine("\nTotal for all jobs is " + grandTotal.ToString("C", CultureInfo.GetCultureInfo("en-US")));
}
}
class Job
{
protected double hours;
protected double price;
public const double RATE = 45.00;
public Job(int num, string cust, string desc, double hrs)
{
JobNumber = num;
Customer = cust;
Description = desc;
Hours = hrs;
}
public int JobNumber {get; set;}
public string Customer {get; set;}
public string Description {get; set;}
public double Hours
{
get
{
return hours;
}
set
{
hours = value;
price = hours * RATE;
}
}
public double Price
{
get
{
return price;
}
}
public override string ToString()
{
return(GetType() + " " + JobNumber + " " + Customer + " " +
Description + " " + Hours + " hours @" + RATE.ToString("C") +
" per hour. Total price is " + Price.ToString("C", CultureInfo.GetCultureInfo("en-US")));
}
public override bool Equals(Object e)
{
bool equal;
Job temp = (Job)e;
if(JobNumber == temp.JobNumber)
equal = true;
else
equal = false;
return equal;
}
public override int GetHashCode()
{
return JobNumber;
}
}
class RushJob : Job
{
public const double PREMIUM = 150.00;
public RushJob() :base(0, "", "", 0)
{
}
public override string ToString()
{
return(GetType() + " " + JobNumber + " " + Customer + " " +
Description + " " + Hours + " hours @" + RATE.ToString("C") +
" per hour. Rush job adds " + PREMIUM +
" premium. Total price is " + Price.ToString("C", CultureInfo.GetCultureInfo("en-US")));
}
public new double Hours
{
get
{
return hours;
}
set
{
hours = value;
price = hours * RATE + PREMIUM;
}
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 11 images