Question

In: Computer Science

C# using MindTap How do I round this up to 2 decimals: I need the total...

C# using MindTap How do I round this up to 2 decimals: I need the total to round to two decimals example instead of the output to be 119.625 it needs to be 119.63

using System;
using static System.Console;
using System.Globalization;
class DemoJobs
{
static void Main()
{
Job job1 = new Job();
Job job2 = new Job();
Job job3 = new Job();
job1.Description = "wash windows";
job1.Time = 3.5;
job1.Hourly = 25.00;
job2.Description = "clean garden";
job2.Time = 2;
job2.Hourly = 18.50;
job3 = job1 + job2;
Display(job1);
Display(job2);
Display(job3);
}
internal static void Display(Job j)
{
WriteLine("Job : {0} is {1} per hour for {2} hours.\n Total = {3}", j.Description, j.Hourly.ToString("C", CultureInfo.GetCultureInfo("en-US")), j.Time, j.Total.ToString("C", CultureInfo.GetCultureInfo("en-US")));
}
}

class Job
{
private string description;
private double time;
private double hourly;
private double total;
public string Description
{
get
{
return description;
}
set
       {
description = value;
}
}
public double Time
{
get
{
return time;
}
set
{
time = value;
CalcTotal();
}
}
public double Hourly
{
get
{
return hourly;
}
set
{
hourly = value;
CalcTotal();
}
}

public double Total
{
get
{
       return total;
}
}

private void CalcTotal()
{
total = Time * Hourly;
}

public static Job operator +(Job j1,
Job j2)
{
Job temp = new Job();
temp.Description = j1.Description + " and " + j2.Description;
temp.Time = j1.Time + j2.Time;
temp.Hourly = (j1.Hourly + j2.Hourly) / 2;
return temp;
}
}

Solutions

Expert Solution

You can use Math.Round(doublevalue,n) where n=no of digits


using System;
using static System.Console;
class DemoJobs
{
static void Main()
{
Job job1 = new Job();
Job job2 = new Job();
Job job3 = new Job();
job1.Description = "wash windows";
job1.Time = 5.26;
job1.Hourly = 25.5641;
job2.Description = "clean garden";
job2.Time = 2;
job2.Hourly = 18.50;
job3 = job1 + job2;
Display(job1);
Display(job2);
Display(job3);
}
internal static void Display(Job j)
{
WriteLine("Job : {0} is {1} per hour for {2} hours.\n Total = {3}", j.Description, Math.Round(j.Hourly,2), Math.Round(j.Time,2), Math.Round(j.Total,2));
}
}

class Job
{
private string description;
private double time;
private double hourly;
private double total;
public string Description
{
get
{
return description;
}
set
{
description = value;
}
}
public double Time
{
get
{
return time;
}
set
{
time = value;
CalcTotal();
}
}
public double Hourly
{
get
{
return hourly;
}
set
{
hourly = value;
CalcTotal();
}
}

public double Total
{
get
{
return total;
}
}

private void CalcTotal()
{
total = Time * Hourly;
}

public static Job operator +(Job j1,
Job j2)
{
Job temp = new Job();
temp.Description = j1.Description + " and " + j2.Description;
temp.Time = j1.Time + j2.Time;
temp.Hourly = (j1.Hourly + j2.Hourly) / 2;
return temp;
}
}

Expected output:


Related Solutions

Question 2 of 4 Use decimals if needed, not fractions. Do not round at all (without...
Question 2 of 4 Use decimals if needed, not fractions. Do not round at all (without rounding, truncate final answer after three decimal places if needed). Suppose the demand for union representation is given by RD=240-4p and the supply of union representation is LS=2p. A. Graph the supply and demand for union representation. If union membership is free, the maximum number of workers who would want a union is _______ . If union fees are above $ _______ , zero...
Enter answers only as numbers, and round decimals to 2 decimal places. Suppose that there is...
Enter answers only as numbers, and round decimals to 2 decimal places. Suppose that there is natural monopoly that faces a demand curve Q=100-P with total cost function C(Q)=400+15Q. The profit maximizing quantity for the natural monopolist, in the presence of a marginal cost pricing rule is ________ units. The profit maximizing price that will set by the monopolist that will be set in the presence of a marginal cost pricing rule is $_________. The average total cost per unit...
Round any decimals to 2 decimal places. Suppose that there is natural monopoly that faces a...
Round any decimals to 2 decimal places. Suppose that there is natural monopoly that faces a demand curve Q=100-P with total cost function C(Q)=400+15Q. The profit maximizing quantity for the natural monopolist, in the presence of an average cost pricing rule is _______ units. The profit maximizing price that will set by the monopolist that will be set in the presence of an average cost pricing rule is $______ The average total cost per unit at the profit maximizing level...
Find the values requested in the problems. Round all answers to 2 decimals and please identify...
Find the values requested in the problems. Round all answers to 2 decimals and please identify the parts for your responses You decide after a few successful years in the field, you decided that it's time to buy a house. you speak to the bank and the take out mortgage for $175,000 for 30 years ( that is the price of a home today is $175,000) a) IF YOU PAY 1% PER MONTH WHAT IS YOUR MONTHLY PAYMENT b) Assume...
How do I convert the integers in my 2D array list to output decimals numbers? My...
How do I convert the integers in my 2D array list to output decimals numbers? My program works accepting regular integers, but crashes when decimals are entered into my 2D array list. Can someone improve it so it accepts decimal numbers? Here is my code: import javax.swing.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class TwoDimArray { private int numbers[][]; public TwoDimArray() { loadArray(); } public void loadArray() { /* //loadArray() method loads the users defined filename //@return returns the...
I need to write a C++ program that appends "not" into the string without using the...
I need to write a C++ program that appends "not" into the string without using the append method or any standard libraries. It should return the string if there isn't an "is" in it. Examples: is is = is not is not This is me = This is not me What is yellow? = What is not yellow? The sky is pink = The sky is not pink isis = isis What happened to you? = What happened to you?
how do i find the percentage of total value
how do i find the percentage of total value
I have to do this "interview", I just need truthful/made-up answers to these questions (Include the...
I have to do this "interview", I just need truthful/made-up answers to these questions (Include the position you hold and why someone in that position can give a better feel for how someone might use accounting someday) 1. I would like to understand if and how financial reporting affects you and your work. Can you give me any examples of how accounting affects your day-to-day responsibilities or decisions? 2. What do other managers and leaders in your company use your...
I have to do this "interview", I just need truthful/made-up answers to these questions (Include the...
I have to do this "interview", I just need truthful/made-up answers to these questions (Include the position you hold and why someone in that position can give a better feel for how someone might use accounting someday) 1.      I would like to understand if and how financial reporting affects you and your work. Can you give me any examples of how accounting affects your day-to-day responsibilities or decisions? 2.      What do other managers and leaders in your company use your...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not against it being included in the answer* I must read off of an excel file (comma separated) to input five different things for a book, all comma separated, there are 360 books in the file. The book title, author, ISBN number, number of pages, and finally the year it was published. Now some of the ISBN or Pg numbers may be missing and will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT