Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class candiesMain {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- String input;
- int amount;
- int small = 0;
- int big = 0;
- int unbalanced = 0;
- System.out.printf("How many bags of candies would you like to make? ");
- amount = in.nextInt();
- candies[] obj = new candies[amount];
- for(int i = 0; i < amount; i++)
- {
- input = in.next();
- obj[i] = new candies(input);
- small += obj[i].small();
- big += obj[i].big();
- unbalanced += obj[i].unbalanced();
- }
- System.out.printf("The amount of small bags you made is %d. The amount of big bags you made is %d. You have made %d unbalanced bags today.", small, big, unbalanced);
- in.close();
- }
- }
- // Next class
- public class candies
- {
- private String input;
- private int red;
- private int yellow;
- private int green;
- private int brown;
- private int size;
- public candies(String input)
- {
- this.input = input;
- ini();
- }
- private void ini()
- {
- for(int i = 0; i < input.length(); i++)
- {
- char current = input.charAt(0);
- if(current == 'r')
- red++;
- else if(current == 'y')
- yellow++;
- else if(current == 'g')
- green++;
- else if(current == 'b')
- brown++;
- }
- size = input.length();
- }
- public int small()
- {
- if(size == 20)
- return 1;
- else
- return 0;
- }
- public int big()
- {
- if(size == 28)
- return 1;
- else
- return 0;
- }
- public int unbalanced()
- {
- if(red == yellow && red == green && red == brown)
- return 0;
- else
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement