Question

JAVA HELP, CANNOT FIGURE THIS CLASS OUT, coding must be done in java. 1. Given a...

JAVA HELP, CANNOT FIGURE THIS CLASS OUT, coding must be done in java.

1. Given a Java test class PA01_01_02_WarmUpTest (code is below) and the following outputs as guidelines, you are to implement a Java class THAT MUST BE NAMED PA01_01_01_WarmUp, with several methods as well as a constructor and an integer array variable as instance variable in the class.

Your implementation should satisfy the following conditions:

 You may not modify class PA01_01_02_WarmUpTest ;

 The method names and their signatures should be defined as indicated in the test class;

 The output from the execution of your implementation should be exact the same as the following outputs:

The array contains:

5 7 -8 -9 0 12 11 -3 7 5 .

The reversed array contains:

5 7 -3 11 12 0 -9 -8 7 5 .

The smallest and largest are: -9, 12.

The number of times that 8 can be divided by 2 is: 3.

The number of times that 15 can be divided by 2 is: 3.

The number of times that 255 can be divided by 2 is: 7.

The number of vowels in "I love CSC260 very much!" is: 5.

The number of vowels in "I love CSC260 very much MUUUCH!" is: 8.

PA01 warmup test code (CANNOT MODIFY):

public class PA01_01_02_WarmUpTest {
   public static void main( String[] args ) {
  
       int [] tempA = {5, 7, -8, -9, 0, 12, 11, -3, 7, 5};
       int tn; String s;
  
       PA01_01_01_WarmUp pa01 = new PA01_01_01_WarmUp(tempA);
      
       System.out.println("The array contains: ");
       pa01.display();
       pa01.reverse();
       System.out.println("The reversed array contains: ");
       pa01.display();
      
       int [] smallestAndLargest = new int [2];
       smallestAndLargest = pa01.smallestAndLargest();
       System.out.printf("The smallest & laregest are: %d, %d.\n\n",
           smallestAndLargest[0], smallestAndLargest[1]);
          
       tn = 8;
       System.out.printf("The number of times that %d can be divided by 2 is: %d.\n\n",
           tn, pa01.numberOfTimesDividedBy2(tn));
       tn = 15;
       System.out.printf("The number of times that %d can be divided by 2 is: %d.\n\n",
           tn, pa01.numberOfTimesDividedBy2(tn));
       tn = 255;
       System.out.printf("The number of times that %d can be divided by 2 is: %d.\n\n",
           tn, pa01.numberOfTimesDividedBy2(tn));
          
       s = "I love CSC260 very much!";
       System.out.printf("The number of vowels in \"%s\" is: %d.\n\n",
           s, pa01.numberOfVowels(s));
       s = "I love CSC260 very much MUUUCH!";
       System.out.printf("The number of vowels in \"%s\" is: %d.\n\n",
           s, pa01.numberOfVowels(s));
   }
}

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

If you have any doubts, please give me comment...

class PA01_01_01_WarmUp{

    private int arr[];

    public PA01_01_01_WarmUp(int[] tempA){

        arr = new int[tempA.length];

        for(int i=0; i<tempA.length; i++){

            arr[i] = tempA[i];

        }

    }

    public void display(){

        for(int i=0; i<arr.length; i++){

            System.out.print(arr[i]+" ");

        }

        System.out.println(".");

    }

    public void reverse(){

        int len = arr.length;

        for(int i=0; i<len/2; i++){

            int temp = arr[i];

            arr[i] = arr[len-i-1];

            arr[len-i-1] = temp;

        }

    }

    public int[] smallestAndLargest(){

        int []result = new int[2];

        result[0] = arr[0];

        result[1] = arr[0];

        for(int i=0; i<arr.length; i++){

            if(result[0]>arr[i])

                result[0] = arr[i];

            if(result[1]<arr[i])

                result[1] = arr[i];

        }

        return result;

    }

    public int numberOfTimesDividedBy2(int n){

        int count = 0;

        while(n>0){

            n = n/2;

            count++;

        }

        return count-1;

    }

    public int numberOfVowels(String s){

        int count = 0;

        s = s.toLowerCase();

        for(int i=0; i<s.length(); i++){

            char ch = s.charAt(i);

            if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')

                count++;

        }

        return count;

    }

}

public class PA01_01_02_WarmUpTest {

   public static void main( String[] args ) {

  

       int [] tempA = {5, 7, -8, -9, 0, 12, 11, -3, 7, 5};

       int tn; String s;

  

       PA01_01_01_WarmUp pa01 = new PA01_01_01_WarmUp(tempA);

      

       System.out.println("The array contains: ");

       pa01.display();

       pa01.reverse();

       System.out.println("The reversed array contains: ");

       pa01.display();

      

       int [] smallestAndLargest = new int [2];

       smallestAndLargest = pa01.smallestAndLargest();

       System.out.printf("The smallest & laregest are: %d, %d.\n\n",

           smallestAndLargest[0], smallestAndLargest[1]);

          

       tn = 8;

       System.out.printf("The number of times that %d can be divided by 2 is: %d.\n\n",

           tn, pa01.numberOfTimesDividedBy2(tn));

       tn = 15;

       System.out.printf("The number of times that %d can be divided by 2 is: %d.\n\n",

           tn, pa01.numberOfTimesDividedBy2(tn));

       tn = 255;

       System.out.printf("The number of times that %d can be divided by 2 is: %d.\n\n",

           tn, pa01.numberOfTimesDividedBy2(tn));

          

       s = "I love CSC260 very much!";

       System.out.printf("The number of vowels in \"%s\" is: %d.\n\n",

           s, pa01.numberOfVowels(s));

       s = "I love CSC260 very much MUUUCH!";

       System.out.printf("The number of vowels in \"%s\" is: %d.\n\n",

           s, pa01.numberOfVowels(s));

   }

}

nagarajuanagaraju-Vostro-3550:16092019$ javac PA01_01_02_WarmupTest.java nagarajuanagaraju-Vostro-3550:16092019$ java PA01_01

Add a comment
Know the answer?
Add Answer to:
JAVA HELP, CANNOT FIGURE THIS CLASS OUT, coding must be done in java. 1. Given a...
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
  • Hi I really need help with the methods for this lab for a computer science class....

    Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...

  • import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...

    import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...

  • Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    //...

    Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    // checks customers in and assigns them a boarding pass    // To the human user, Seats 1 to 2 are for First Class passengers and Seats 3 to 5 are for Economy Class passengers    //    public void reserveSeats()    {       int counter = 0;       int section = 0;       int choice = 0;       String eatRest = ""; //to hold junk in input buffer       String inName = "";      ...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • the answer must be in java. thank you Question 2 [8 points] Consider the class Class...

    the answer must be in java. thank you Question 2 [8 points] Consider the class Class A below: class Class A implements Serializable{ int a; static int b; transient int c; String s; // Constructor public Class A (int a, int b, int c, Strings){ this.a = a; this.b = b; this.c = c; this.s = s; Complete the class Test to test the serialization and deserialization of the objects of class Class A. State the possible variable values following...

  • please answer in Java..all excercises. /** * YOUR NAME GOES HERE * 4/7/2017 */ public class...

    please answer in Java..all excercises. /** * YOUR NAME GOES HERE * 4/7/2017 */ public class Chapter9a_FillInTheCode { public static void main(String[] args) { String [][] geo = {{"MD", "NY", "NJ", "MA", "CA", "MI", "OR"}, {"Detroit", "Newark", "Boston", "Seattle"}}; // ------> exercise 9a1 // this code prints the element at row at index 1 and column at index 2 // your code goes here System.out.println("Done exercise 9a1.\n"); // ------> exercise 9a2 // this code prints all the states in the...

  • please help fill out the class menu create a prototype that will display information about housing...

    please help fill out the class menu create a prototype that will display information about housing data1. In this prototype you will use dynamic array data structures to store the data and compute metrics. For the requirements of the prototype, your client has given you a list of metrics and operations. The user interface will be a menu that displays this list and prompts the user to choose which option to execute.You will create two classes. First you will create...

  • Java Program 1. Write a class that reads in a group of test scores (positive integers...

    Java Program 1. Write a class that reads in a group of test scores (positive integers from 1 to 100) from the keyboard. The main method of the class calls a few other methods to calculate the average of all the scores as well as the highest and lowest score. The number of scores is undetermined but there will be no more than 50. A negative value is used to end the input loop. import java.util.Scanner; public class GradeStat {...

  • [IN JAVA] Copy the following code into your main.cpp and complete it public class Main { pub...

    [IN JAVA] Copy the following code into your main.cpp and complete it public class Main { public static void main(String [] args) { int [] array1 = {5, 8, 34, 7, 2, 46, 53, 12, 24, 65}; int numElements = 10; System.out.println("Part 1"); // Part 1 // Enter the statement to print the numbers in index 5 and index 8 // put a space in between the two numbers and a new line at the end // Enter the statement...

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