Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions