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
John would like to move from the suburbs into the city, but the rent in the city is very high. John has found an apartment he re
maxonik [38]

A list of multiple choices is given;

<span>a)      </span>Purchase a home in the city center instead.

<span>b)      </span>Rent the apartment anyway.

<span>c)       </span>Rent the apartment with a roommate.

<span>d)      </span>Purchase a home in the suburbs instead.


The answer is (C)


John should look for an apartment and share it with a roommate. This will bring down rent expenses to 50% as both John and the roommate will be cost sharing the rent. If the rent expenses go down by 50%, he’ll be able to save an additional 10% and use it for other expenses.

4 0
3 years ago
Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
oksano4ka [1.4K]

Answer:

The program in Python is as follows:

def get_user_values():

   user_values = []

   n = int(input())

   for i in range(n+1):

       inp = int(input())

       user_values.append(inp)

   output_ints_less_than_or_equal_to_threshold(user_values,user_values[n])

def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold):

   for i in user_values:

       if i <= upper_threshold:

           print(i,end=" ")

           

get_user_values()

Explanation:

This defins the get_user_values() method; it receives no parameter

def get_user_values():

This initializes user_values list

   user_values = []

This gets the number of inputs

   n = int(input())

This loop is repeated n+1 times to get all inputs and the upper threshold

<em>    for i in range(n+1):</em>

<em>        inp = int(input())</em>

<em>        user_values.append(inp)</em>

This passes the list and the upper threshold to the output..... list  output_ints_less_than_or_equal_to_threshold(user_values,user_values[n])

This defines the output.... list

def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold):

This iterates through the list

   for i in user_values:

If current element is less or equal to the upper threshold, the element is printed

<em>        if i <= upper_threshold:</em>

<em>            print(i,end=" ")</em>

The main method begins here where the get_user_values() method is called

get_user_values()

7 0
3 years ago
What is the definition of bug?​
salantis [7]
In what way is it used?
3 0
3 years ago
Briefly explain the following terms and concepts:
morpeh [17]

Answer:

Answer below

Explanation:

Maximum transmission unit (MTU)

A maximum transmission unit (MTU) is the largest packet or frame size that is usually specified in Eight-bit bytes, which can be sent in a packet or frame-based network such as the internet.  

Longest Prefix Match

Longest prefix match is an algorithm used by routers in Internet Protocol to lookup the IP prefix that will likely be the terminal point of the next hop from the router.

CIDR and Subnet Mask

CIDR, known in full as Classless inter-domain routing, is a set of IP standards that is used to make customized identifiers for networks and individual devices.  

A subnet mask separates the internet protocol (IP) address into the network address and host address.

 

Switching Fabric

Switching fabric is simply an arrangement of the elements of a communication network also known as network topology, whereby the nodes of the network are seen to interconnect with one or more network switches.

7 0
3 years ago
Read 2 more answers
Which of these is an example of gathering secondary data?
Soloha48 [4]

Answer:

searching for a chart

Explanation:

:)

7 0
3 years ago
Other questions:
  • Questions 6 - 9 Refer to the following code: public class WhatsIt { private int[] values; private double average; public WhatsIt
    7·1 answer
  • 7.
    6·1 answer
  • Owning provides _________ flexibility but can lead to _________ costs in the long-term.
    7·2 answers
  • C++ CODE
    6·1 answer
  • How does technology make America great?​
    10·1 answer
  • When network cards are communicating, bits can occasionally be corrupted in transmission?
    5·1 answer
  • A ______ is an exact duplication of the hard drive, including data files, system files, and settings, application files, and the
    15·1 answer
  • Has anyone on here heard from lilkoadkmillines?
    10·1 answer
  • Which of the following is not a key way that a LAN shares
    15·1 answer
  • A digital designer might do computer animations for video games,<br> OA<br> True<br> OB<br> False
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!