Question: Java program In this assignment, I want someone to help me with this, please Instructions In this assessment, you will create 2 out of 3
Java program
In this assignment, I want someone to help me with this, please
Instructions
In this assessment, you will create 2 out of 3 classes.
The doWork () method for two of those classes returned an int, and one of those classes returned a boolean (true/false). In this assessment, you will write a new class to encapsulate the return code of the various doWork() methods in the classes.
This class will be called DoWorkResults class. It must be able to hold any one of these three types: integer, string, boolean.
Copy the source code from HW1 to this assignment's project:
public class HW1 {
}
class SumDigitsInString{
public int doWork(String inputstr){
int sum=0;
for (int i=-0;i { char ch= inputstr.charAt(i); if (Character.isDigit(ch)) sum+=(ch-48);} return sum; } } class CountVowels{ public int doWork(String inputstr) { int c=0; for (int i=-0;i { char ch= inputstr.charAt(i); if ((ch=='a')||(ch=='e')||(ch=='i')||(ch=='o')||(ch=='u')) c++; if ((ch=='A')||(ch=='E')||(ch=='I')||(ch=='O')||(ch=='U')) c++; } return c; } } public class IsGrimString { boolean doWork(String str) { for (int i=0;i { if ((str.charAt(i)=='g') && (str.charAt(i+1) == 'r')) { if ((str.charAt(i+2)!='g')||(str.charAt(i+3)!='r')) return false; i+=4; } else i++; } return true; } Change your classes so that each class' doWork() method now returns a DoWorkResults object. You will need to modify the doWork() method of each class to do this. And you will need to change the HW1 class as well. Start by creating the DoWorkResults class. It will have the following private data members: Integer intResult; Boolean booleanResult; String stringResult; It will have public methods to get and set each of the data members. It will have a public String toString() method that returns a String with the result. (There is only one result in each class. Do not put 'null' into the returned string. You will need to check each data member to see if it a null reference, and only return a String created from the non-null data member.) For this assessment class, you can either write it from scratch or make a copy of the up-code class and modify it. The main() method in this assessment must call the doWork() methods of all the classes you implemented in up-code, and print out the results. The main() method in code you will write must do everything that the main() method in up-code or above code did. Refer back to the code gave up for details. The key difference is that the assessment class will get DoWorkResults objects back from the doWork() methods. (Note: This part is optional.) In your main method, create an object from each class you implemented, and store the object in an array. Store 3 test strings in a string array. Then loop through the arrays, invoking objArray[i].doWork(testData[i]), until you reach the end of the array. Homework Report Questions
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
