Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Electricity {
- private final static double LAMP_CONSUMPTION = 100.53;
- private final static double COMP_CONSUMPTION = 125.90;
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int floors = input.nextInt();
- int flats = input.nextInt();
- input.nextLine();
- String time = input.nextLine();
- int allFlats = floors * flats;
- int lamps = 0;
- int computers = 0;
- //get first 2 digits
- String getHours = "";
- if(time.length() == 5) {
- getHours = time.substring(0, 2);
- }
- else {
- getHours = time.substring(0, 1);
- }
- int hours = Integer.parseInt(getHours);
- if (hours >= 14 && hours < 19) {
- lamps = 2;
- computers = 2;
- }
- else if (hours >= 19 && hours < 24) {
- lamps = 7;
- computers = 6;
- }
- else if (hours >= 0 && hours < 9) {
- lamps = 1;
- computers = 8;
- }
- System.out.printf("%d Watts", (int)((allFlats * lamps * LAMP_CONSUMPTION) + (allFlats * computers * COMP_CONSUMPTION)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement