Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class LightRoom {
- private List<Integer> getHouseInfo() {
- List<Integer> bulpsOnList = new ArrayList<Integer>();
- int totalRooms, totalBulbs, bulpsSwitchedOn = 0;
- String windowOption, shadyOption;
- boolean isWindowAttached, isShadyOutside;
- Scanner in = new Scanner(System.in);
- System.out.print("Total Rooms in the House: ");
- totalRooms = in.nextInt();
- in.nextLine();
- for (int i = 0; i < totalRooms; i++) {
- System.out.print("\nEnter Total Bulbs In The Room "+(i+1)+": ");
- totalBulbs = in.nextInt();
- in.nextLine();
- do{
- System.out.print("Does The Room Attached With Window (y/n)? ");
- windowOption = in.nextLine();
- isWindowAttached = ("yY".contains(windowOption));
- }
- while(windowOption.length() != 1 || !("yYnN".contains(windowOption)));
- do{
- System.out.print("Does The Outside Of The Room Is Shady (y/n)? ");
- shadyOption = in.nextLine();
- isShadyOutside = ("yY".contains(shadyOption));
- }
- while(shadyOption.length() != 1 || !("yYnN".contains(shadyOption)));
- if (!isWindowAttached) {
- bulpsSwitchedOn = totalBulbs;
- } else if (isWindowAttached && !isShadyOutside) {
- bulpsSwitchedOn = 0;
- } else if (isWindowAttached && isShadyOutside) {
- bulpsSwitchedOn = totalBulbs / 2;
- }
- bulpsOnList.add(bulpsSwitchedOn);
- }
- return bulpsOnList;
- }
- private void displayResult(List<Integer> list) {
- int totalRoom = 0, totalBulbs = 0;
- for (Integer number : list) {
- totalRoom = number > 0 ? ++totalRoom : totalRoom;
- totalBulbs = number > 0 ? totalBulbs+=number : totalBulbs;
- }
- System.out.println("\nTotal Rooms Which Have Lights On = "+totalRoom);
- System.out.println("Total Number of Light Bulps Switched On = "+totalBulbs);
- }
- public static void main(String args[]) {
- LightRoom house = new LightRoom();
- List<Integer> list = house.getHouseInfo();
- house.displayResult(list);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment