Question

Problem3 (1.5 points). Write a Java program to input electricity unit charges and calculate total electricity bill accordingjava programming language

2 0
Add a comment Improve this question Transcribed image text
Answer #1

The Java programs for your requirement given below,

Problem3 Java code:

import java.util.Scanner;

public class ElectricityCharge {
   public static void main(String aa[]) {
       double units, charge = 0, additional, total;
       Scanner ss = new Scanner(System.in);
       System.out.println("Enter Electricity unit");
       units = ss.nextDouble(); // get units from user
       if (units > 0 && units <= 50) {
           charge = units * 0.50; // calculate charge
       } else if (units > 50 && units <= 150) {
           charge = units * 0.75;
       } else if (units > 150 && units <= 250) {
           charge = units * 1.20;
       } else if (units > 250) {
           charge = units * 1.50;
       }
       additional = charge * 0.2; // calculate additional charge
       total = charge + additional; // calculate total amount
       System.out.println("total electricity bill=" + total);

   }

}
Sample output:

Enter Electricity unit 100 total electricity bill=90.0

Note: Read comments for better understanding of the Java code

Problem4 Java code:

import java.util.Scanner;

class WeekDays {
   public static void main(String s[]) {
       int day;
       Scanner ss = new Scanner(System.in);
       System.out.println("Enter weekday number"); // get weekday number from user
       day = ss.nextInt();
       switch (day) {
       case 1:
           System.out.println("Sunday");
           break;
       case 2:
           System.out.println("Monday");
           break;
       case 3:
           System.out.println("Tuesday");
           break;
       case 4:
           System.out.println("Wednesday");
           break;
       case 5:
           System.out.println("Thursday");
           break;
       case 6:
           System.out.println("Friday");
           break;
       case 7:
           System.out.println("Saturday");
           break;
       default:
           System.out.println("Enter valid week day number");
           break;
       }
   }
}

Sample output:

Enter weekday number 7 Saturday

Note : I considered sunday as a day 1 and Saturday as day 7.

Add a comment
Know the answer?
Add Answer to:
java programming language Problem3 (1.5 points). Write a Java program to input electricity unit charges and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programming help! Write a program that reads the electricity consumption (in kWh) and computes the...

    C programming help! Write a program that reads the electricity consumption (in kWh) and computes the electricity bill based on the following information: • The first 50 kWh costs 8.5 cents/kWh • Next 100 kWh costs 9.5 cents/kWh • Next 100 kWh costs 9.8 cents/kWh • The consumption above 250 kWh costs 10.25 cents/kWh Additional surcharge 20% is added to the bill. The input of the program is one integer and the output will be “The total bill is $?.”,...

  • JAVA PROGRAMMING LANGUAGE!!!! Pig Latin Write a program that reads a sentence as input and converts...

    JAVA PROGRAMMING LANGUAGE!!!! Pig Latin Write a program that reads a sentence as input and converts each word to "Pig Latin". In one version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end of the word, and then appending "ay" to the word. Here is an example: English:                       I SLEPT MOST OF THE NIGHT Pig Latin :                   TAY LEPTSAY OSTMAY FOÀY HETAY 1GHTNAY make sure that there are two...

  • Write a Java program that implements the number guessing game where the computer tries to guess...

    Write a Java program that implements the number guessing game where the computer tries to guess a number in your head. You pick a number between 0 and 100, and the computer generates a guess. You then type 1 if your number is larger than the computer’s guess, -1 if your number is smaller, and 0 if the number is correct. The computer should keep trying to guess the number by adjusting the guess based on your feedback (so if...

  • Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an...

    Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be...

  • *Java* Given the attached Question class and quiz text, write a driver program to input the...

    *Java* Given the attached Question class and quiz text, write a driver program to input the questions from the text file, print each quiz question, input the character for the answer, and, after all questions, report the results. Write a Quiz class for the driver, with a main method. There should be a Scanner field for the input file, a field for the array of Questions (initialized to 100 possible questions), and an int field for the actual number of...

  • computer programming Write a C program that will calculate and print monthly water bills. The total...

    computer programming Write a C program that will calculate and print monthly water bills. The total units consumed per month are derived from subtracting the previous meter readings with the current meter reading. The charges are calculated based on the rates stated in Table 2. The sample output is shown in Figure 16 Tulis aturcara Cyang akan mengira dan mencetak bil air bulanan Jumlah unit yang diguna sebulan dikira dengan menolak bacaan meter sebelum dengan bacaan meter terkinl. Caj dikira...

  • Plz help!! The programming language is C and could you write comments as well? Problem 2....

    Plz help!! The programming language is C and could you write comments as well? Problem 2. Calculate Grades (35 points) Arrays can be used for any data type, such as int and char. But they can also be used for complex data types like structs. Structs can be simple, containing simple data types, but they can also contain more complex data types, such as another struct. So you could have a struct inside of a struct. This problem deals with...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

  • C++ The programming language is c++ our program using the following data Mary Smith Green walley...

    C++ The programming language is c++ our program using the following data Mary Smith Green walley Thul Bool Gauteng ) Please key is the n ot your Ter in your mark for Mathematics Ey in your mark for use orientation Key in your mark for watory Wer in your work for Computer literacy Te in r for at e Jobs Africa School: King College 9/11 - Average Year Wark53.67 with label and code The T a QUESTION 2: (40) Suppose...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT