Question: JAVA: Write a program that will take one string of four positive integers (e.g. 0 1 1 2) and will test to see if there

JAVA:

Write a program that will take one string of four positive 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 IntPairs object. This object will have a constructor that takes no arguments and the following two methods:

  • public void setPairString(String str) - will take a string as an argument & then store it in an instance variable.
  • public boolean hasTwoPairs() - will return true when there are only two pairs present in the string.

  • 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.
  • When done with the scanner, be sure to call the {scanner variable name}.close()
  • You are free to make local variables. You can use them to hold the numbers you get from the string.

**create two classes: IntPairs.java(source file) and main.java (for test code)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!