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
  • 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...

  • 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...

  • I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt...

    I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...

  • 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 = "";      ...

  • (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming...

    (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming for code for the new GameChanger class. // the code for Main class for step number 6 has already been given, please show modified progrraming for Main class and GameCHanger class, thank you. package .games; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println("Welcome to the Number Guessing Game"); System.out.println(); Scanner sc = new Scanner(System.in); // Get upper...

  • 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...

  • 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...

  • 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...

  • in java Part 1 In this section, we relook at the main method by examining passing...

    in java Part 1 In this section, we relook at the main method by examining passing array as parameters. Often we include options/flags when running programs. On command line, for example, we may do “java MyProgram -a -v". Depending on options, the program may do things differently. For example, "a" may do all things while "-v" display messages verbosely. You can provide options in Eclipse instead of command line: "Run ... Run Configurations ... Arguments". Create a Java class (Main.java)....

  • 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...

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