Advertisement
Valleri

C# Basics Exam 25 July 2014 Evening - Electricity

Jul 30th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Electricity {
  4.     private final static double LAMP_CONSUMPTION = 100.53;
  5.     private final static double COMP_CONSUMPTION = 125.90;
  6.    
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.        
  10.         int floors = input.nextInt();
  11.         int flats = input.nextInt();
  12.         input.nextLine();
  13.         String time = input.nextLine();
  14.        
  15.         int allFlats = floors * flats;
  16.         int lamps = 0;
  17.         int computers = 0;
  18.        
  19.         //get first 2 digits
  20.         String getHours = "";
  21.         if(time.length() == 5) {
  22.             getHours = time.substring(0, 2);
  23.         }
  24.         else {
  25.             getHours = time.substring(0, 1);
  26.         }
  27.         int hours = Integer.parseInt(getHours);
  28.        
  29.         if (hours >= 14 && hours < 19) {
  30.             lamps = 2;
  31.             computers = 2;
  32.         }
  33.         else if (hours >= 19 && hours < 24) {
  34.             lamps = 7;
  35.             computers = 6;
  36.         }
  37.         else if (hours >= 0 && hours < 9) {
  38.             lamps = 1;
  39.             computers = 8;
  40.         }
  41.        
  42.         System.out.printf("%d Watts", (int)((allFlats * lamps * LAMP_CONSUMPTION) + (allFlats * computers * COMP_CONSUMPTION)));
  43.     }
  44.    
  45.    
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement