Question
## Problem Description You are to write a program that will take one string of four positive, single-digit integers (e.g. 0 1 1 2) and
## Problem Description
You are to write a program that will take one string of four positive, single-digit integers (e.g. "0 1 1 2") and will test to see if there are two pairs present in the string. This will be implemented by the **IntegerPairs** object. This object will have a constructor that takes no arguments and the following two methods:
- ```java
public void setPairString(String str)
```
- This method will take a string as an argument and then store it in an instance variable.
- ```java
public boolean hasTwoPairs()
```
- This will return true when there are only two pairs present in the string.
Hints:
- You can use a **Scanner** on a string as well as **System.in**. It works the same way but the constructor takes a string rather than **System.in**.
- After you are done with the scanner be sure to call **{your scanner variable name}.close()**;
- Don't be afraid to make local variables. You can use them to hold the numbers you get from the string.
- You do NOT need nested ifs and you definitely do NOT need loops to solve this
- Think about using the && (logical and) operator to test conditions
- Depending on what method you use to convert strings (e.g. Integer.parseInt), you may want to use an try...catch block (covered in class) to handle a parsing exception. See the Java API documentation for what type of exception an the parseInt method throws
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started