Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class MrSocks {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- int size;
- String color;
- String sample;
- boolean found = false;
- boolean comparison;
- System.out.printf("Mr. Socks, please enter your sock details.\n");
- System.out.printf("Size: ");
- size = in.nextInt();
- System.out.printf("Color: ");
- color = in.next();
- System.out.printf("Sample: ");
- sample = in.next();
- Socks mainSock = new Socks(size, color, sample);
- System.out.printf("Try to find a pair.\n");
- while(!found)
- {
- System.out.printf("Size: ");
- size = in.nextInt();
- System.out.printf("Color: ");
- color = in.next();
- System.out.printf("Sample: ");
- sample = in.next();
- Socks currentSock = new Socks(size, color, sample);
- comparison = mainSock.compareToSock(currentSock);
- System.out.printf("%s", comparison ? "Congrats, these are a pair!" : "Keep trying Mr. Socks.\n");
- found = comparison ? true : false;
- }
- in.close();
- }
- }
- // Next class
- public class Socks
- {
- private int size;
- private String color;
- private String sample;
- public Socks(int size, String color, String sample)
- {
- this.size = size;
- this.color = color;
- this.sample = sample;
- }
- public int getSize()
- {
- return size;
- }
- public String getColor()
- {
- return color;
- }
- public String getSample()
- {
- return sample;
- }
- public boolean compareToSock(Socks nextSock)
- {
- boolean isValid = true;
- if(size != nextSock.getSize())
- isValid = false;
- if(!(color.equals(nextSock.getColor())))
- isValid = false;
- if(!(sample.equals(nextSock.getSample())))
- isValid = false;
- return isValid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement