1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Volgvan
3 years ago
6

Energy consumption is measured in units of kilowatt hours (kWh). The more kWh a household use in a month, the higher the energy

bill. A power company charges customers $0.12 per kWh for the first 500 kWh. After the first 500 kWh, the rate is $0.15 per kWh. Write a program to calculate energy charge. You must write and use the following two functions. (a)A main function: Ask the user to enter number of kWh used. Call the bill_calculator function and pass number of kWh used to it as an argument.
Computers and Technology
1 answer:
3241004551 [841]3 years ago
7 0

Answer:

The c# program for the scenario is given below.

using System;

public class Program {

 double total = 0;

 static void Main() {

     Program ob = new Program();

   Console.WriteLine("Enter total energy used in kilo watts ");

   int p;

   p = Convert.ToInt32(Console.ReadLine());

   ob.bill_calculator(p);

   Console.WriteLine("Total charge for " + p + " kilo watts of energy is " + ob.total);

 }

 public void bill_calculator(int e)

 {

     int first=500;

     double chg_one = 0.12, chg_two=0.15;

     if(e <= 500)

     {      

         total = (e * chg_one);

     }

     else if(e > 500)

     {

         total = ( first * chg_one);

         total = total + ((e-first) * chg_two);

     }

 }

}

 

OUTPUT

Enter total energy used in kilo watts                                                                                                          

5555                                                                                                                                          

Total charge for 5555 kilo watts of energy is 818.25

Explanation:

The program is designed to take user input but does not implements validation for the user input.

The program works as follows.

1. Inside main(), the user enters the energy consumed in kilo watts.

2. This is stored in the integer variable, p.

3. The method bill_calculator() is called which accepts the value of p as a parameter.

4. If the energy used is 500 or less kilo watts, charges are different. While for the amount of energy consumption for more than 500, charges are different.

5. The charges for both, 500 and less and more than 500 are stored in double variables.

6. The if-else statements are used to calculate the total charge based on the amount of power used.

if(e <= 500)

     {      

         total = (e * chg_one);

     }

     else if(e > 500)

     {

         total = ( first * chg_one);

         total = total + ((e-first) * chg_two);

     }

7. Since c# is an object-oriented programming language, any method outside main() is called using the object of the class. All code is written inside the class.

8. Next, the total charge is displayed by calling the bill_calculator() method through the object of the Program class.

9. The main() function has only void return type and hence, no value is returned.

You might be interested in
A benefit of IPsec is __________.
Montano1993 [528]

Answer:

Option (4) is correct answer

Explanation:

IPsec stands for Internet protocol security. It is a protocol that works between two communication points. It provides integrity, confidentiality and data authentication for any network. It is used for Virtual private network.  There are two types of VPN, From which an organization needs to choose one.

IPsec and OpenSSl in which IPsec VPN uses IP security.

Benefits of this network are as follows--

  • Option 1 states that it works after the transport layer which is true.
  • Option 2 states that when any user leaves the organization they have no need to take back the martial which he had already provided to the organization which is also the benefit of IPsec.
  • Option 3 states that it provides security that is also correct because it is a protocol that is designed to provide security.

Hence option D (all of the above ) are correct.

3 0
3 years ago
WHHY AM I GIVING POINTS AWAY
Ber [7]

Answer:

Oop thx for the points -w-

6 0
3 years ago
The intended purpose of the following module is to determine whether the value parameter is within a specified range. The module
BARSIC [14]

The program does not consists of any syntax error but the module contains error in logic especially while placing the condition inside if statement.

Here we are actually planning to check whether the number passed in the “value” variable is within the given lower and upper range which is passed in second and third parameter.

Solution 1:

if value<=lower AND value>=upper Then

Display “The given number is outside the specified range.”

else

Display “The given number is within the specified range.”

End if

Alternate solution:

So for that the condition needs to be value>=lower and value <=lower. so  

if value > lower AND value <upper Then

Display “The given number is within the specified range.”

else  

Display “The given number is within the specified range.”

7 0
4 years ago
When entering data into a cell, which keyboard key is used to remove characters to the left of the insertion point?
deff fn [24]
The backspace key is used for that
3 0
3 years ago
The only type of donation you can make to a not for profit is to donate money
amm1812
The correct answer is true
5 0
3 years ago
Read 2 more answers
Other questions:
  • Excel contains ____ tools not available in access.
    12·1 answer
  • Which class of fire extinguisher is appropriate for a fire involving electrical/energized electrical equipment?
    13·2 answers
  • Is a network where connected devices are located within the same building.
    5·2 answers
  • Which device in a wireless local area network determines the next network to which a packet should be forwarded??
    5·1 answer
  • Some have argued that Unix/Linux systems reuse a small number of security features in many contexts across the system, while Win
    12·1 answer
  • Application servers are usually grouped into two types: page-based and _____ systems.
    6·1 answer
  • What does the following if statement do?<br><br> if (num1 == Math.abs(num1))
    12·1 answer
  • Which of the following factors will have the greatest impact on your credit score? I. Length of Credit History II. Payment Histo
    6·2 answers
  • Anyone want to talk? it can honestly be about any subject :)
    5·1 answer
  • Which tools do meteorologists use to collect data about the weather?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!