Question

Problem 1 1. In the src → edu.neiu.p2 → problem1 directory, create a Java class called...

Problem 1

1. In the src → edu.neiu.p2 → problem1 directory, create a Java class called HW4P1 and add the following:

• The main method. Leave the main method empty for now.

• Create a method named xyzPeriod that takes a String as a parameter and returns a boolean.

• Return true if the String parameter contains the sequential characters xyz, and false otherwise. However, a period is never allowed to immediately precede (i.e. come before) the sequential characters xyz. If .xyz occurs, the method should return false.

• You may only use the three methods discussed recently in lecture: length(), charAt(), and indexOf()

2. In the main method, call your method and test it with the below examples. Print out your results to make sure that they match the given return values below.

3. Go to the HW4P1Test class in the tests → problem1 directory and uncomment the import at the top, the block of tests in the main method, and the corresponding methods. Run the test to see if you created your code correctly. Make sure all 3 tests pass.

Sample Method Usage Return Value
boolean b1 = xyzPeriod("abcxyz") true
boolean b2 = xyzPeriod("4abc.xyzygxyzop") false
boolean b3 = xyzPeriod("xyz.yadda") true
boolean b4 = xyzPeriod("st.uffxyz") true
boolean b5 = xyzPeriod("xuyddz") false

Problem 2

1. In the src → edu.neiu.p2 → problem2 directory, create a Java class called HW4P2 and add the following:

• The main method. Leave the main method empty for now.

• Write a method named productOfDigits that takes a String parameter and does not return anything. You can assume that the parameter is a non-empty String.

• The method should print out the product of all the digits in the String. If there are no digits, print out "No digits". You should take into account BigIntegers when creating your code.

• You may use at most one loop.

• You may only use the three methods discussed recently in lecture: length(), charAt(), and indexOf().

2. In the main method, call your method and test it with the below examples. Print out your results to make sure that they match the given return values below.

3. Go to the HW4P2Test class in the tests → problem2 directory and uncomment the import at the top, the block of tests in the main method, and the corresponding methods. Run the test to see if you created your code correctly. Make sure all 3 tests pass.

Sample Method Usage Output
productOfDigits("tfg113f8f2okil"); Product: 48
productOfDigits("h4739jf938473jfj983jfjoirui49484949848393d"); Product: 91725702944299941888
productOfDigits("hdhgheielsldhf"); No digits
productOfDigits("dj37hg0kr7"); Product: 0

Problem 3

1. In the src → edu.neiu.p2 → problem3 directory, create a Java class called HW4P3 and add the following:

• The main method. Leave the main method empty for now.

• Create a method named beforeAfter that takes two String parameters, str1 and str2, and returns aString. You can assume that str2 is a non-empty String.

• The beforeAfter method should create a new String formed by concatenating the character found immediately before and immediately after every appearance of str2 in str1. If str2 cannot be found in str1, return null.

• You may use at most one loop. You may only use the three String methods discussed recently in lecture: length(), charAt(), and indexOf().

2. In the main method, call your method and test it with the below examples. Print out your results to make sure that they match the given return values below.

3. Go to the HW4P3Test class in the tests → problem3 directory and uncomment the import at the top, the block of tests in the main method, and the corresponding methods. Run the test to see if you created your code correctly. Make sure all 4 tests pass.

Sample Method Usage Return Value
String s1 = beforeAfter("abcXY123XYijk", "XY"); c13i
String s2 = beforeAfter("ABC123ABC", "ABC"); 13
String s3 = beforeAfter("ZY1YZ", "Z"); YY
String s4 = beforeAfter("GHsjd38", "44"); null

Running Tests:

At various steps of the assignment, you will be told to run tests to check your code. All tests can be found in src → test directory. DO NOT MODIFY THE TEST PACKAGE LOCATION OR THE TEST CODE OTHER THAN TO UNCOMMENT.

• All test classes have a main method.

• Uncomment the method calls in the main method and the methods themselves as directed.

• Each method call in the main method is a test.

• To run the tests, right-click on the test file and choose Run (followed by the class name).

• Check to make sure that all the tests display "PASSED". If not, look at the Expected vs the Actual values or the stack trace (i.e. error) if applicable.

Note: These problems are done through IntelliJ.

For Problem 1: HW4P1Test class

package edu.neiu.p2.tests.problem1;

//import edu.neiu.p2.problem1.HW4P1;

public class HW4P1Test
{
    public static void main(String[] args) {
        // TESTS
        /*shouldReturnFalseIfNoXYZ();
        shouldReturnTrueIfNoXYZAndNoPeriod();
        shouldReturnFalseIfXYZAndPeriod();*/
    }

    // UNCOMMENT ALL OF THESE TESTS
    /*private static void shouldReturnFalseIfNoXYZ() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        try {
            boolean b = HW4P1.xyzPeriod("3xdydjz8d");
            System.out.println(!b ? "PASSED" : "FAILED");
            System.out.println("Expected: false");
            System.out.println("Actual: " + b);
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            e.printStackTrace();
        }
        System.out.println();
    }

    private static void shouldReturnTrueIfNoXYZAndNoPeriod() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        try {
            boolean b = HW4P1.xyzPeriod("happyxyzhappy.happy");
            System.out.println(b ? "PASSED" : "FAILED");
            System.out.println("Expected: true");
            System.out.println("Actual: " + b);
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            e.printStackTrace();
        }
        System.out.println();
    }

    private static void shouldReturnFalseIfXYZAndPeriod() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        try {
            boolean b = HW4P1.xyzPeriod("hxyzbb.xyziikxyzll");
            System.out.println(!b ? "PASSED" : "FAILED");
            System.out.println("Expected: false");
            System.out.println("Actual: " + b);
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            e.printStackTrace();
        }
        System.out.println();
    }*/
}

------------------------------------------------------------------------------------

For Problem 2: HW4P2Test class

package edu.neiu.p2.tests.problem2;

//import edu.neiu.p2.problem2.HW4P2;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class HW4P2Test
{
    public static void main(String[] args) {
        // TESTS
        /*shouldReturnProduct();
        shouldReturnProductForLargeValues();
        shouldReturnNoDigits();*/
    }

    // UNCOMMENT ALL OF THESE TESTS
    /*private static void shouldReturnProduct() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
        final PrintStream originalOut = System.out;
        System.setOut(new PrintStream(outContent));
        try {
            HW4P2.productOfDigits("ghsl111dj11dgjs1");
            String out = outContent.toString();
            System.setOut(originalOut);
            System.out.println("Product: 1\n".equals(out) ? "PASSED" : "FAILED");
            System.out.println("Expected: " + "Product: 1");
            System.out.println("Actual: " + out.trim());
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            System.out.println(e.getMessage());
        }
        System.out.println();
    }

    private static void shouldReturnProductForLargeValues() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
        final PrintStream originalOut = System.out;
        System.setOut(new PrintStream(outContent));
        try {
            HW4P2.productOfDigits("9494949dhg372747492948dghf28282");
            String out = outContent.toString();
            System.setOut(originalOut);
            System.out.println("Product: 36698669445021696\n".equals(out) ? "PASSED" : "FAILED");
            System.out.println("Expected: " + "Product: 36698669445021696");
            System.out.println("Actual: " + out.trim());
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            System.out.println(e.getMessage());
        }
        System.out.println();
    }

    private static void shouldReturnNoDigits() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
        final PrintStream originalOut = System.out;
        System.setOut(new PrintStream(outContent));
        try {
            HW4P2.productOfDigits("yaddayaddayadda");
            String out = outContent.toString();
            System.setOut(originalOut);
            System.out.println("No digits\n".equals(out) ? "PASSED" : "FAILED");
            System.out.println("Expected: " + "No digits");
            System.out.println("Actual: " + out.trim());
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            System.out.println(e.getMessage());
        }
        System.out.println();
    }*/
}

------------------------------------------------------------------------------------

For Problem 3: HW4P3Test class

package edu.neiu.p2.tests.problem3;

//import edu.neiu.p2.problem3.HW4P3;

public class HW4P3Test
{
    public static void main(String[] args) {
        // TESTS
        /*shouldFindBeforeAndAfterStringCharacters();
        shouldFindBeforeAfterForBeginningOfString();
        shouldFindBeforeAfterForEndOfString();
        shouldReturnNullIfNotInString();*/
    }

    // UNCOMMENT ALL OF THESE TESTS
    /*private static void shouldFindBeforeAndAfterStringCharacters() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        try {
            String s = HW4P3.beforeAfter("tyedeighed8idie3", "ed");
            System.out.println(s.equals("yeh8") ? "PASSED" : "FAILED");
            System.out.println("Expected: yeh8");
            System.out.println("Actual: " + s);
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            e.printStackTrace();
        }
        System.out.println();
    }

    private static void shouldFindBeforeAfterForBeginningOfString() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        try {
            String s = HW4P3.beforeAfter("g873dghe8ls", "g87");
            System.out.println(s.equals("3") ? "PASSED" : "FAILED");
            System.out.println("Expected: 3");
            System.out.println("Actual: " + s);
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            e.printStackTrace();
        }
        System.out.println();
    }

    private static void shouldFindBeforeAfterForEndOfString() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        try {
            String s = HW4P3.beforeAfter("eyellowjdug0yellow", "yellow");
            System.out.println(s.equals("ej0") ? "PASSED" : "FAILED");
            System.out.println("Expected: ej0");
            System.out.println("Actual: " + s);
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            e.printStackTrace();
        }
        System.out.println();
    }

    private static void shouldReturnNullIfNotInString() {
        System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
        System.out.print("Test Outcome: ");
        try {
            String s = HW4P3.beforeAfter("8heg8f8ef", "8f86");
            System.out.println(s == null ? "PASSED" : "FAILED");
            System.out.println("Expected: null");
            System.out.println("Actual: " + s);
        } catch (RuntimeException e) {
            System.out.println("FAILED. ERROR!!");
            e.printStackTrace();
        }
        System.out.println();
    }*/
}

------------------------------------------------------------------------------------

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// HW4P1.java
package edu.neiu.p2.problem1;

public class HW4P1
{
   public static boolean xyzPeriod(String str) {
       if(str.indexOf(".xyz") != -1) // if period precedes xyz return false
           return false;
       else if(str.indexOf("xyz") != -1) // if string contains xyz return true
           return true;
       else // if string doesn't contains xyz return false
           return false;
   }      
}
//end of HW4P1.java

// HW4P1Test .java
package edu.neiu.p2.tests.problem1;

import edu.neiu.p2.problem1.HW4P1;

public class HW4P1Test
{
public static void main(String[] args) {
// TESTS
shouldReturnFalseIfNoXYZ();
shouldReturnTrueIfNoXYZAndNoPeriod();
shouldReturnFalseIfXYZAndPeriod();
}

  
private static void shouldReturnFalseIfNoXYZ() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
try {
boolean b = HW4P1.xyzPeriod("3xdydjz8d");
System.out.println(!b ? "PASSED" : "FAILED");
System.out.println("Expected: false");
System.out.println("Actual: " + b);
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
e.printStackTrace();
}
System.out.println();
}

private static void shouldReturnTrueIfNoXYZAndNoPeriod() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
try {
boolean b = HW4P1.xyzPeriod("happyxyzhappy.happy");
System.out.println(b ? "PASSED" : "FAILED");
System.out.println("Expected: true");
System.out.println("Actual: " + b);
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
e.printStackTrace();
}
System.out.println();
}

private static void shouldReturnFalseIfXYZAndPeriod() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
try {
boolean b = HW4P1.xyzPeriod("hxyzbb.xyziikxyzll");
System.out.println(!b ? "PASSED" : "FAILED");
System.out.println("Expected: false");
System.out.println("Actual: " + b);
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
e.printStackTrace();
}
System.out.println();
}
}
//end of HW4P1Test .java

Output:

// HW4P2.java
package edu.neiu.p2.problem2;

import java.math.BigInteger;

public class HW4P2
{
public static void productOfDigits(String str)
{
   BigInteger result = null;
   for(int i=0;i<str.length();i++) // loop over the string
   {
       if(str.charAt(i) >= '0' && str.charAt(i) <= '9') // if character is a digit, perform multiplication with the result
       {
           if(result != null)
               result = result.multiply(new BigInteger(str.charAt(i)+""));
           else
               result = new BigInteger(str.charAt(i)+"");
       }
   }
  
   if(result == null) // if no digits exist in the input string
       System.out.print("No digits\n");
   else
       System.out.print("Product: "+result.toString()+"\n");
}  
      
}
//end of HW4P2.java

// HW4P2Test .java
package edu.neiu.p2.tests.problem2;

import edu.neiu.p2.problem2.HW4P2;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class HW4P2Test
{
public static void main(String[] args) {
// TESTS
shouldReturnProduct();
shouldReturnProductForLargeValues();
shouldReturnNoDigits();
}

// UNCOMMENT ALL OF THESE TESTS
private static void shouldReturnProduct() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
final PrintStream originalOut = System.out;
System.setOut(new PrintStream(outContent));
try {
HW4P2.productOfDigits("ghsl111dj11dgjs1");
String out = outContent.toString();
System.setOut(originalOut);
System.out.println("Product: 1\n".equals(out) ? "PASSED" : "FAILED");
System.out.println("Expected: " + "Product: 1");
System.out.println("Actual: " + out.trim());
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
System.out.println(e.getMessage());
}
System.out.println();
}

private static void shouldReturnProductForLargeValues() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
final PrintStream originalOut = System.out;
System.setOut(new PrintStream(outContent));
try {
HW4P2.productOfDigits("9494949dhg372747492948dghf28282");
String out = outContent.toString();
System.setOut(originalOut);
System.out.println("Product: 36698669445021696\n".equals(out) ? "PASSED" : "FAILED");
System.out.println("Expected: " + "Product: 36698669445021696");
System.out.println("Actual: " + out.trim());
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
System.out.println(e.getMessage());
}
System.out.println();
}

private static void shouldReturnNoDigits() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
final PrintStream originalOut = System.out;
System.setOut(new PrintStream(outContent));
try {
HW4P2.productOfDigits("yaddayaddayadda");
String out = outContent.toString();
System.setOut(originalOut);
System.out.println("No digits\n".equals(out) ? "PASSED" : "FAILED");
System.out.println("Expected: " + "No digits");
System.out.println("Actual: " + out.trim());
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
System.out.println(e.getMessage());
}
System.out.println();
}
}

// end of HW4P2Test .java

Output:

// HW4P3.java
package edu.neiu.p2.problem3;


public class HW4P3
{
public static String beforeAfter(String str1, String str2)
{
   String result = null;
   int i = 0;
   // loop over the string
   while(i < str1.length())
   {
       int index = str1.indexOf(str2, i); // get the index of str2 in str1 starting from i
       if(index == -1) // if str2 not found, break the loop
           break;
       else // if str2 is found
       {
           if(index > 0) // check if character before the found string exists, then add the character to the result string
           {
               if(result == null)
                   result = str1.charAt(index-1)+"";
               else
                   result += str1.charAt(index-1)+"";
           }
          
           if(index+str2.length() < str1.length()) // check if character after the found string exists, then add the character to the result string
           {
               if(result == null)
                   result = str1.charAt(index+str2.length())+"";
               else
                   result += str1.charAt(index+str2.length())+"";
           }
          
           i = index+1; // make i point to 1 position after the found index
       }
   }
  
   return result; // return the result
}      
}
//end of HW4P3.java

// HW4P3Test .java
package edu.neiu.p2.tests.problem3;

import edu.neiu.p2.problem3.HW4P3;

public class HW4P3Test
{
public static void main(String[] args) {
// TESTS
shouldFindBeforeAndAfterStringCharacters();
shouldFindBeforeAfterForBeginningOfString();
shouldFindBeforeAfterForEndOfString();
shouldReturnNullIfNotInString();
}

// UNCOMMENT ALL OF THESE TESTS
private static void shouldFindBeforeAndAfterStringCharacters() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
try {
String s = HW4P3.beforeAfter("tyedeighed8idie3", "ed");
System.out.println(s.equals("yeh8") ? "PASSED" : "FAILED");
System.out.println("Expected: yeh8");
System.out.println("Actual: " + s);
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
e.printStackTrace();
}
System.out.println();
}

private static void shouldFindBeforeAfterForBeginningOfString() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
try {
String s = HW4P3.beforeAfter("g873dghe8ls", "g87");
System.out.println(s.equals("3") ? "PASSED" : "FAILED");
System.out.println("Expected: 3");
System.out.println("Actual: " + s);
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
e.printStackTrace();
}
System.out.println();
}

private static void shouldFindBeforeAfterForEndOfString() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
try {
String s = HW4P3.beforeAfter("eyellowjdug0yellow", "yellow");
System.out.println(s.equals("ej0") ? "PASSED" : "FAILED");
System.out.println("Expected: ej0");
System.out.println("Actual: " + s);
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
e.printStackTrace();
}
System.out.println();
}

private static void shouldReturnNullIfNotInString() {
System.out.println("Test Name: " + Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.print("Test Outcome: ");
try {
String s = HW4P3.beforeAfter("8heg8f8ef", "8f86");
System.out.println(s == null ? "PASSED" : "FAILED");
System.out.println("Expected: null");
System.out.println("Actual: " + s);
} catch (RuntimeException e) {
System.out.println("FAILED. ERROR!!");
e.printStackTrace();
}
System.out.println();
}
}
//end of HW4P3Test .java

Output:

Add a comment
Know the answer?
Add Answer to:
Problem 1 1. In the src → edu.neiu.p2 → problem1 directory, create a Java class called...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 1 1. In the src → edu.neiu.p2 directory, create a package named problem1. 2. Create...

    Problem 1 1. In the src → edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named StringParser with the following: • A public static method named findInteger that takes a String and two char variables as parameters (in that order) and does not return anything. • The method should find and print the integer value that is located in between the two characters. You can assume that the second char parameter will always follow the first...

  • Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing an...

    Lab 3 Step One First, create an empty directory for lab3. There is no starter code for this lab. You will be throwing and catching exceptions in this exercise. Create a file called RuntimeException.h and put the following code in it. #include <string> class RuntimeException { private: string errorMsg; public: RuntimeException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } } Step Two In a new .cpp file in your directory, write a main function...

  • complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class...

    complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */    public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null;...

  • Java Project Draw a class diagram for the below class (using UML notation) import java.io.BufferedReader; import...

    Java Project Draw a class diagram for the below class (using UML notation) import java.io.BufferedReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; public class myData { public static void main(String[] args) { String str; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter text (‘stop’ to quit)."); try (FileWriter fw = new FileWriter("test.txt")) { do { System.out.print(": "); str = br.readLine(); if (str.compareTo("stop") == 0) break; str = str + "\r\n"; // add newline fw.write(str); } while (str.compareTo("stop") != 0); } catch (IOException...

  • Hi so I am currently working on a project for a java class and I am...

    Hi so I am currently working on a project for a java class and I am having trouble with a unit testing portion of the lab. This portion wants us to add three additional tests for three valid arguments and one test for an invalid argument. I tried coding it by myself but I am not well versed in unit testing so I am not sure if it is correct or if the invalid unit test will provide the desired...

  • Hi, So I have a finished class for the most part aside of the toFile method...

    Hi, So I have a finished class for the most part aside of the toFile method that takes a file absolute path +file name and writes to that file. I'd like to write everything that is in my run method also the toFile method. (They are the last two methods in the class). When I write to the file this is what I get. Instead of the desired That I get to my counsel. I am having trouble writing my...

  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • The DictionaryClient program featured in the class lecture also used the try-catch when creating a socket....

    The DictionaryClient program featured in the class lecture also used the try-catch when creating a socket. Socket are auto-closeable and thus can use a try-with-resources instead. Edit the dictionary program to use try-with-resources instead. package MySockets; import java.net.*; import java.io.*; public class DictionaryClient {       private static final String SERVER = "dict.org";    private static final int PORT = 2628;    private static final int TIMEOUT = 15000;    public static void main(String[] args) {        Socket   ...

  • Error: Main method not found in class ServiceProvider, please define the main method as: public static...

    Error: Main method not found in class ServiceProvider, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application This is the error im getting while executing the following code Can you modify the error import java.net.*; import java.io.*; public class ServiceProvider extends Thread { //initialize socket and input stream private Socket socket = null; private ServerSocket server = null; private DataInputStream in = null; private DataOutputStream out = null; private int...

  • Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the...

    Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the following program? public class Quiz2B { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } Question 1 options: The program displays Welcome to Java two times. The program displays Welcome to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT