Question

----JAVA IMPLEMENTATION URGENTLY NEEDED ------ //Ques 3 /** * Computes the standard Rayleigh distribution probability density...

----JAVA IMPLEMENTATION URGENTLY NEEDED ------

//Ques 3

/**

* Computes the standard Rayleigh distribution probability density function (The mathematical function describing the standard Rayleigh distribution is given by: y = [ x / (σ)^2 ] * e ^ [ (-x^2) / (2σ^2) ] where σ =sigma is the scale variable of Rayleigh distribution. The function y is called the probability density function of the standard Rayleigh distribution. Complete the method rayleigh(double x, int sigma) that returns the value of y given by the formula above

* the lab document for the actual formula) with scale parameter.

*

* @param x

* a value

* @param sigma

* scale parameter

* @return the standard Rayleigh distribution probability density function

* evaluated at x

*/

public static double rayleigh(double x, int sigma) {

return 0;

}

//Ques 6

/**

* Returns true if year is a leap year and false otherwise.

*

*

* A year is always a leap year if it is evenly divisible by 400; for all other

* years, a year is a leap year if it is evenly divisible by 4 and not evenly

* divisible by 100. For example:

*

*

 

* isLeapYear(2000) returns true (2000 is divisible by 400)

* isLeapYear(1900) returns false (1900 is divisible by 4 and 100)

* isLeapYear(2004) returns true (2004 is divisible by 4 but not 100)

* isLeapYear(2005) returns false (2005 is not divisible by 4)

*

*

* @param year

* a year

* @return true if year is a leap year and false otherwise

* @throws IllegalArgumentException

* if year is less than 1582 (the year the Gregorian

* calendar was adopted)

*/

public static boolean isLeapYear(int year) {

return false;

}

//Ques 9

/**

* Returns a string representation of a <code>Range</code> that is different

* than the one returned by <code>Range.toString</code>.

*

* <p>

* The returned string has the form <code>"minimum: x, maximum: y"</code> where

* x is the minimum value of the range and y is the maximum value of the range.

*

* @param r

* a Range instance

* @return a string representation of the range

*/

public static String toString(Range r) {

return false;

}

//Ques 14

/**

* Returns a new list of characters formed by shuffling the

* characters of the given list. It is a precondition that

* the given list t contains at least two elements, and that

* the number of elements is an even number. The list is not

* modified by this method.

*

* <p>

* To shuffle the characters in t, imagine splitting the list

* t in half so that the first (n / 2) characters of t are in

* one sublist, and the remaining (n / 2) characters of t are

* in the second sublist. The new returned list is formed by

* adding the first character of the first sublist to the

* new list, then adding the first character of the second sublist,

* then adding the second character of the first sublist, then

* adding the second character of the second sublist, and so on,

* until all of the characters in the two sublists are added

* to the new list.

*

* <p>

* For example, if t was the list:

*

* <pre>

* ['a', 'b', 'c', 'd', 'e', 'f']

* </pre>

*

* <p>

* then splitting t into two sublists yields:

*

* <pre>

* ['a', 'b', 'c'] and ['d', 'e', 'f']

* </pre>

*

* <p>

* Take the first two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd']

* </pre>

*

* <p>

* Then take the next two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd', 'b', 'e']

* </pre>

*

* <p>

* Then take the next two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd', 'b', 'e', 'c', 'f']

* </pre>

*

* @param t a non-null list of characters

* @return a new list equal to the shuffle of the characters in t

* @pre. t is not null

* @pre. t.size() is greater than or equal to 2

* @pre. t.size() is an even number

*/

public static List<Character> shuffle(List<Character> t) {

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/**
* Computes the standard Rayleigh distribution probability density function (The mathematical function describing the standard Rayleigh distribution is given by: y = [ x / (σ)^2 ] * e ^ [ (-x^2) / (2σ^2) ] where σ =sigma is the scale variable of Rayleigh distribution. The function y is called the probability density function of the standard Rayleigh distribution. Complete the method rayleigh(double x, int sigma) that returns the value of y given by the formula above

* the lab document for the actual formula) with scale parameter.

*

* @param x

* a value

* @param sigma

* scale parameter

* @return the standard Rayleigh distribution probability density function

* evaluated at x

*/


public static double rayleigh(double x, int sigma) {
    double power = (-1 * Math.pow(x, 2) / (2.0 * Math.pow(sigma, 2)));
    double first = x/Math.pow(sigma, 2);

    return first * Math.pow(Math.E, power);

}

//Ques 6

/**

* Returns true if year is a leap year and false otherwise.

*

*

* A year is always a leap year if it is evenly divisible by 400; for all other

* years, a year is a leap year if it is evenly divisible by 4 and not evenly

* divisible by 100. For example:

*

*



* isLeapYear(2000) returns true (2000 is divisible by 400)

* isLeapYear(1900) returns false (1900 is divisible by 4 and 100)

* isLeapYear(2004) returns true (2004 is divisible by 4 but not 100)

* isLeapYear(2005) returns false (2005 is not divisible by 4)

*

*

* @param year

* a year

* @return true if year is a leap year and false otherwise

* @throws IllegalArgumentException

* if year is less than 1582 (the year the Gregorian

* calendar was adopted)

*/

public static boolean isLeapYear(int year) {
        return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}

//Ques 9

/**

* Returns a string representation of a <code>Range</code> that is different

* than the one returned by <code>Range.toString</code>.

*

* <p>

* The returned string has the form <code>"minimum: x, maximum: y"</code> where

* x is the minimum value of the range and y is the maximum value of the range.

*

* @param r

* a Range instance

* @return a string representation of the range

*/

public static String toString(Range r) {
    return "(" + r.getMinimum() + ", " + r.getMaximum() + ")";

}

//Ques 14

/**

* Returns a new list of characters formed by shuffling the

* characters of the given list. It is a precondition that

* the given list t contains at least two elements, and that

* the number of elements is an even number. The list is not

* modified by this method.

*

* <p>

* To shuffle the characters in t, imagine splitting the list

* t in half so that the first (n / 2) characters of t are in

* one sublist, and the remaining (n / 2) characters of t are

* in the second sublist. The new returned list is formed by

* adding the first character of the first sublist to the

* new list, then adding the first character of the second sublist,

* then adding the second character of the first sublist, then

* adding the second character of the second sublist, and so on,

* until all of the characters in the two sublists are added

* to the new list.

*

* <p>

* For example, if t was the list:

*

* <pre>

* ['a', 'b', 'c', 'd', 'e', 'f']

* </pre>

*

* <p>

* then splitting t into two sublists yields:

*

* <pre>

* ['a', 'b', 'c'] and ['d', 'e', 'f']

* </pre>

*

* <p>

* Take the first two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd']

* </pre>

*

* <p>

* Then take the next two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd', 'b', 'e']

* </pre>

*

* <p>

* Then take the next two characters of each sublist and add them to the

* new list:

*

* <pre>

* ['a', 'd', 'b', 'e', 'c', 'f']

* </pre>

*

* @param t a non-null list of characters

* @return a new list equal to the shuffle of the characters in t

* @pre. t is not null

* @pre. t.size() is greater than or equal to 2

* @pre. t.size() is an even number

*/
public static List<Character> shuffle(List<Character> t) {
    List<Character> r= new ArrayList<>();

    int l = t.size();
    for(int i=0; i<l/2; i++) {
        r.add(t.get(i));
        r.add(t.get(i + l/2));
    }

    return r;
}
Add a comment
Know the answer?
Add Answer to:
----JAVA IMPLEMENTATION URGENTLY NEEDED ------ //Ques 3 /** * Computes the standard Rayleigh distribution probability density...
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
  • Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the...

    Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the following data entry error conditions: A number less than 1 or greater than 12 has been entered for the month A negative integer has been entered for the year utilizes a try and catch clause to display an appropriate message when either of these data entry errors exceptions occur. Thank you let me know if you need more info import java.util.*; //Class definition public...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • I am currently using eclipse to write in java. A snapshot of the output would be...

    I am currently using eclipse to write in java. A snapshot of the output would be greatly appreciated to verify that the program is indeed working. Thanks in advance for both your time and effort. Here is the previous exercise code: /////////////////////////////////////////////////////Main /******************************************* * Week 5 lab - exercise 1 and exercise 2: * * ArrayList class with search algorithms * ********************************************/ import java.util.*; /** * Class to test sequential search, sorted search, and binary search algorithms * implemented in...

  • n JAVA, students will create a linked list structure that will be used to support a...

    n JAVA, students will create a linked list structure that will be used to support a role playing game. The linked list will represent the main character inventory. The setting is a main character archeologist that is traveling around the jungle in search of an ancient tomb. The user can add items in inventory by priority as they travel around (pickup, buy, find), drop items when their bag is full, and use items (eat, spend, use), view their inventory as...

  • In java---- The DeckTester.java file, provides a basic set of Deck tests. Add additional code at...

    In java---- The DeckTester.java file, provides a basic set of Deck tests. Add additional code at the bottom of the main method to create a standard deck of 52 cards and test the shuffle method ONLY in the Deck class. After testing the shuffle method, use the Deck toString method to “see” the cards after every shuffle. Deck: import java.util.List; import java.util.ArrayList; /** * The Deck class represents a shuffled deck of cards. * It provides several operations including *...

  • JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet {    ...

    JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet {     /**      * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList      * containing all the indexes of Strings in arr that match String s. For this method, two Strings,      * p and q, match when p.equals(q) returns true or if both of the compared references are null.      *      * @param s The string...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • This assignment is comprised of 3 parts: ​All files needed are located at the end of...

    This assignment is comprised of 3 parts: ​All files needed are located at the end of the directions. Part 1: Implementation of Dynamic Array, Stack, and Bag First, complete the Worksheets 14 (Dynamic Array), 15 (Dynamic Array Amortized Execution Time Analysis), 16 (Dynamic Array Stack), and 21 (Dynamic Array Bag). These worksheets will get you started on the implementations, but you will NOT turn them in. ​Do Not Worry about these, they are completed. Next, complete the dynamic array and...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • Preliminaries Download the template class and the driver file. Objective Learn how to traverse a binary...

    Preliminaries Download the template class and the driver file. Objective Learn how to traverse a binary search tree in order. Description For the template class BinarySearchTree, fill in the following methods: insert - Inserts values greater than the parent to the right, and values lesser than the parent to the left.parameters elem - The new element to be inserted into the tree. printInOrder - Prints the values stored in the tree in ascending order. Hint: Use a recursive method 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