Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class pencilCaseEvents {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- pencilCase current;
- int pens;
- int pencils;
- int eventsNum;
- System.out.printf("Enter the number of pens you have in your pencil case: ");
- pens = in.nextInt();
- System.out.printf("Enter the number of pencils you have in your pencil case: ");
- pencils = in.nextInt();
- current = new pencilCase(pens, pencils);
- System.out.printf("How many events happened to your pencil case? ");
- eventsNum = in.nextInt();
- int[] events = new int[2];
- System.out.printf("Enter the numbers of the events: ");
- for(int i = 0; i < eventsNum; i++)
- {
- events[0] = in.nextInt();
- events[1] = in.nextInt();
- if(events[0] == 1)
- {
- if(events[1] == 1)
- current.addPen();
- else
- current.addPencil();
- }
- else
- {
- if(events[1] == 1)
- current.subPen();
- else
- current.subPencil();
- }
- }
- System.out.printf("Your pencil case has %d pens and %d pencils", current.pens(), current.pencils());
- in.close();
- }
- }
- // Next class
- public class pencilCase
- {
- private int pens;
- private int pencils;
- public pencilCase(int pens, int pencils)
- {
- this.pens = pens;
- this.pencils = pencils;
- }
- public void addPencil()
- {
- pencils++;
- }
- public void addPen()
- {
- pens++;
- }
- public void subPencil()
- {
- pencils--;
- }
- public void subPen()
- {
- pens--;
- }
- public int pens()
- {
- return pens;
- }
- public int pencils()
- {
- return pencils;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement