Questions
3. Write a Java program to demonstrate the concept of priority thread. It should show that...

3. Write a Java program to demonstrate the concept of priority thread. It should show that each thread have a priority. Priorities are represented by a number between 1 and 20. In most cases, thread schedular schedules the threads according to their priority (known as preemptive scheduling). But it is not guaranteed because it depends on JVM specification that which scheduling it chooses.


3 constants defined in Thread class:
1. public static int MIN_PRIORITY
2. public static int NORM_PRIORITY
3. public static int MAX_PRIORITY

Default priority of a thread is 5 (NORM_PRIORITY). The value of MIN_PRIORITY is 1 and
the value of MAX_PRIORITY is 20.

Here is an example of priority of a Thread:
1. class TestMultiPriority1 extends Thread{
2. public void run(){
3.    System.out.println("running thread name is:"+Thread.currentThread().getName());
4.    System.out.println("running thread priority is:"+Thread.currentThread().getPriority());
5.   }

6. public static void main(String args[]){
7.   TestMultiPriority1 m1=new TestMultiPriority1();
8.   TestMultiPriority1 m2=new TestMultiPriority1();
9.   m1.setPriority(Thread.MIN_PRIORITY);
10.   m2.setPriority(Thread.MAX_PRIORITY);
11.   m1.start();
12.   m2.start();
13.  
14. }
15. }

In: Computer Science

Python 3.7.4 ## Tombstones ''' A Grave is a dictionary with two keys: * 'Name': A...

Python 3.7.4

## Tombstones

'''
A Grave is a dictionary with two keys:
* 'Name': A string value with the grave's occupant's name
* 'Message': A string value with the grave's message
'''

Grave = {'name': str, 'Message': str}


'''
G1. Define the function `count_grave_all` that consumes a list of graves
and produces an integer representing the number of characters needed to
write all of the message of the grave. Include spaces and new lines.
'''


'''
G2. Define the function `count_grave_characters` that consumes a list of graves
and produces an integer representing the number of characters needed to
write all of the message of the grave. Do not count spaces and new lines.
'''


'''
G3. Define a function named `estimate_grave_cost` that consumes a list of graves
and produces an integer representing the total estimate lettering cost by
multiplying the number of letters on the grave (ignoring spaces and newlines) by
the cost of writing a letter ($2).
'''


"""
G4. Define a function named `count_shouters` that consumes a list of graves
and produces an integer representing the number of graves that had their
messages in all capital letters. Hint: use the `.upper()` method.
"""

In: Computer Science

Function Return Value In this program, you will be using C++ programming constructs, such as functions...

Function Return Value

In this program, you will be using C++ programming constructs, such as functions and loops.

main.cpp

Write a program that allows the user to enter the information for multiple packages to determine the shipping charges for each package. The program will exit when the user enters 0 or negative for the package weight.

Your program will ask the user to enter the weight of a package they want to ship. If the weight they enter is a positive number, your program will then prompt the user to enter the distance the package will be shipped. Your program will then output the shipping charges with a precision of 2 digits past the decimal point, and will prompt the user for the next package.

calculateCharge

Create a function called calculateCharge that contains 2 parameters: a double to represent the weight of the package, and an integer to represent the distance the package will be shipped. This function returns the shipping charge. See types.hpp for the function prototype for this function.

This function calculates the charge based on the package weight as well as the distance. The rates per weight are defined in types.hpp. And that rate is multiplied by how many 500 mile segments the package will be traveling. For instance, if the distance is 1-500 then the rate is multiplied by one. If the distance is 501-1000 then the rate is multiplied by two. 1001-1500, multiplied by three, and so forth.

Input Validation

  1. You can assume the user will always input valid data types (floating-point for package weight and integer for distance).

Hints

  1. Be sure to include the file types.hpp with the #include files so that the compiler knows where to find the program constants and function prototype.
  2. Shipping charges should be displayed with a precision of 2 digits past the decimal point.
  3. Don't forget to add comments to explain what the code is doing and where control of the program is executing.
  4. Choose variable names and function names that describe the purpose of the variable.

Sample Output

Welcome to Fast Freight Shipping Company

Enter the package weight in lbs (or 0 to exit): 0
Welcome to Fast Freight Shipping Company

Enter the package weight in lbs (or 0 to exit): 33
Enter shipping distance in miles: 3

Shipping cost: $6.40

Enter the package weight in lbs (or 0 to exit): -1
Welcome to Fast Freight Shipping Company

Enter the package weight in lbs (or 0 to exit): 3.4
Enter shipping distance in miles: 501

Shipping cost: $8.40

Enter the package weight in lbs (or 0 to exit): 3.4
Enter shipping distance in miles: 500

Shipping cost: $4.20

Enter the package weight in lbs (or 0 to exit): 1.1
Enter shipping distance in miles: 1100

Shipping cost: $9.30

Enter the package weight in lbs (or 0 to exit): 1.1
Enter shipping distance in miles: 1

Shipping cost: $3.10

Enter the package weight in lbs (or 0 to exit): 0

Here is is the information on the types.hpp file to be used:


//-----------
// Constants
//-----------

// shipping distance per segment

const int SEGMENT_MILES = 500;

// rates per 500 miles shipped

const double RATE1 = 3.10; // pkgs weighing <= 2 lb
const double RATE2 = 4.20; // pkgs > 2 lb but <= 6 lb
const double RATE3 = 5.30; // pkgs > 6 lb but <= 10 lb
const double RATE4 = 6.40; // pkgs > 10 lb


//---------------------
// Function prototypes
//---------------------

// This function receives a package weight in lbs and
// a shipping distance in miles. It uses these to compute
// and return the shipping charge.

double calculateCharge(double weight, int distance);

In: Computer Science

ALGORITHMS AND ANALYSIS Show with a counterexample that the greedy approach does not always yield an...

ALGORITHMS AND ANALYSIS

Show with a counterexample that the greedy approach does not always yield an optimal solution for the Change problem when the coins are U.S. coins and we do not have at least one of each type of coin.

In: Computer Science

Write a program to compute numeric grades for a course. The course records are in a...

Write a program to compute numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format:


Each line contains a student’s last name, then one space, followed by the student’s first name, then one space, then ten or fewer quiz scores.


(If there are fewer than ten scores, that means the student missed one or more quizzes.) The quiz scores are whole numbers and are separated by one space. Your program will take its input from this file and send its output to a second file. The data in the output file will be the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student’s quiz scores. The average score is the sum of the quiz scores divided by 10. This amounts to giving the student a 0 for any missed quiz.


The output file will contain a line (or lines) at the beginning of the file explaining the output. Use formatting instructions to make the layout neat and easy to read.


After placing the desired output in an output file, your program will close all files and then copy the contents of the output file to the input file so that the net effect is to change the contents of the input file.


Use at least two functions that have file streams as all of some of their arguments.

Hint: Check out putback member function. See topic in Files menu.

SAMPLE OUTPUT


Input file:

test_ line_ 10 20 30 40 50 60 70

Price Betty 40 50 60 70 60 50 30 60 90

Goodman John 60 70 80 90 100 90

Smith Charles 70 80 90 60 70 60 80 90 90 90

Spangenberg Ward 70 70 80 90 70 80 90 80 70 60

Output file:

Last Name, First Name, up to 10 quiz scores. last entry is the average.

test_ line_ 10 20 30 40 50 60 70 28.00

Price Betty 40 50 60 70 60 50 30 60 90 51.00

Goodman John 60 70 80 90 100 90 49.00

Smith Charles 70 80 90 60 70 60 80 90 90 90 78.00

Spangenberg Ward 70 70 80 90 70 80 90 80 70 60 76.00


Point Distribution:
-50 Does not compile
-5 Warnings
-5 No description multiple line comments (name, date, etc)
-5 No single line comments (logic, input, output, etc)
-20 Does not use at least 2 programmer defined functions with stream passing.
-10 Does not copy output file to input file
-10 Does not format output


can you please send the answer to my emil [email protected]

thank you

C++

C++

In: Computer Science

Programming in C Game of Craps PR01 The game of craps is often said to be...

Programming in C Game of Craps

PR01
The game of craps is often said to be the “fairest” casino game of pure chance (meaning that
there is no player strategy involved) in that the house has the smallest advantage over the
player. What is that advantage? To answer this question we need to first define, precisely, what
we mean by “advantage”. The house advantage is simply the fraction of bets placed that will go
to the house, on average.


To estimate the house advantage for craps perform a Monte Carlo simulation of the game for
many millions of games, keeping track of the total amount bet and the total amount collected
by the house.


The rules of craps are very simple (note that we are not considering “side bets”). A player
places a wager and they will either lose the game (and their wager) or they will win the game
(and get both their wager and an equal payout from the house). Each game consists of a
number of throws of two fair six-sided dice (with sides equal to {1,2,3,4,5,6}. On each roll the
sum of the two dice is calculated. On the first roll, if a player rolls a 7 or an 11 they win
immediately. If the first roll is 2, 3, or 12 they lose immediately. Any other result establishes the
player’s “point” for that game. They then continue rolling the dice until they either roll their
point again (and win) or roll a 7 (and lose).


Write a predicate function that plays a single game of craps and returns TRUE if the player wins
and FALSE if the player loses. On each game place a random bet ranging from $1 to $1000
(whole dollar increments is fine). Collect data not only on the total amount wagered and the
total (net) amount taken by the house, but also aggregate data on how long games last and
their outcome. The end result should be output similar to the following (fake data). Note that
the percentages in parens on each line are the percentage of games that lasted that length, not
the fraction of total games played. The last column is the percentage of all games that lasted
that number of rolls.



GAMES PLAYED:........ 1000000
LONGEST GAME:........ 31 rolls
HOUSE ADVANTAGE:..... 1.734%
ROLLS WON LOST % OF GAMES
1 222222 (66.667%) 111111 (33.333%) 33.333
2 22222 ( 2.222%) 11111 ( 1.111%) 17.234
3 2222 ( 0.222%) 11111 ( 1.111%) 8.645
4 222 ( 0.022%) 1111 ( 0.111%) 0.935
...
20 22 ( 0.002%) 1 ( 0.000%) 0.006
>20 2222 ( 0.222%) 111 ( 0.011%) 0.521


PR02
Take a slightly different look at the game of craps by tabulating the odds of winning (the
fraction of the time that the player wins) for each possible mark value. This table should look
something like:
GAMES PLAYED:........ 1000000
FIRST ROLL WIN:...... 22.222%
FIRST ROLL LOSS:..... 11.111%
POINT WON LOST
4 222222 (22.222%) 111111 (11.111%)
5 22222 (22.222%) 111111 (11.111%)
6 2222 (22.222%) 111111 (11.111%)
8 26 (13.222%) 173 (86.778%)
9 222222 (22.222%) 111111 (11.111%)
10 222222 (22.222%) 111111 (11.111%)


Again, note that the numbers above are just effectively random placeholder values.
The percentages for the first-roll figures should be as a fraction of all games played. The
percentages for the values in the table should be as a fraction of all games that used that row’s
point value. The idea is for the player to know that IF their point is 8, then they have a 13%
change of winning that game – so the percentages on each row should sum to 100%.

In: Computer Science

In this lab, we will write some utility methods within a class called ListUtils. These three...

In this lab, we will write some utility methods within a class called ListUtils. These three methods will all be static methods, and their purpose will be to perform conversions between objects implementing one type of interface and objects implementing another type. For example, we will write a method for converting from an Iterable object to a Collection, and so on. We will discuss more about how this will work below.

Tip: you will definitely want to import java.util for this lab, since List and all of its relatives use it.

Iterable to Collection task:
public static <E> Collection<E> iterToCollection(Iterable<? extends E> iterable)

(3pts) Every Collection is an Iterable but not every Iterable is a Collection. However, if we have an Iterable, it implies a sequence of elements, so we can use that to built a Collection. That is what we will do in this method. To implement the method, we will need to create some kind of Collection object, and add elements from the Iterable's sequence to it one by one.

Hint: we don't want to store the result in a Collection itself, because it is just an interface, but there may be a more familiar choice of structure which implements Collection.

Collection to List task:
public static <E> List<E> collToList(Collection<? extends E> coll)

(3pts) As above, every List is a Collection but not every Collection is a List. However, if we have a Collection, it implies a fixed number of elements which can be retrieved in sequence, so we can use that to built a List by numbering the element indices in the order they are retrieved. That is what we will do in this method. To implement the method, we will need to create some kind of List object, and add elements from the Collection.

List to Map task:
public static <E> Map<Integer, E> listToMap(List<? extends E> list)

(3pts) A Map, sometimes known as an associative array or dictionary, is in some ways similar to a List, except that instead of accessing elements by the indices 0, 1, 2, etc., the elements are accessed by a key, which may or may not be in order, and which may or may not be a number. Every element in a Map is stored as a key-value pair (the value of the element plus the key which is used to access it). Thus, when we call the get() method, instead of passing in an int index, we pass in the key corresponding to the element we're looking for. An example of a class which implements the Map interface in Java is the HashMap class.

A List is not a Map and a Map is not a List. However a Map stores collections of data indexed by some kind of mapping. A Map is essentially a dictionary which allows us to look up elements in a collection of data using some reference key to find each element. The reference key for a Map can be any data type, but if we make that data type an Integer, then we can use the key to represent a List index. Thus, in this method, we will take a List and use it to build a Map by using the list index of each element as the element's key within the Map. Thus, if our List contains the elements 2, 4, and 6, then this method will produce a Map with the mappings 0 ⇒ 2, 1 ⇒ 4, and 2 ⇒ 6. As above, this would involve creating an appropriate type of Map and adding the elements from the List.

In: Computer Science

What is a first-class function? Provide two scenarios where you would implement this concept.

What is a first-class function? Provide two scenarios where you would implement this concept.

In: Computer Science

Show that Boruvka's algorithm has O(lgV) iterations.

Show that Boruvka's algorithm has O(lgV) iterations.

In: Computer Science

Take a device or system that you have to hand—a mobile phone, a website – and...

Take a device or system that you have to hand—a mobile phone, a website – and critique the design, focussing on the aspects that are central to its use. Make a list of claims about the design.

In: Computer Science

Demonstrate your knowledge of creating business documents, by adhering to organisational requirements, in terms of style,...

Demonstrate your knowledge of creating business documents, by adhering to

organisational requirements, in terms of style, layout format etc. You may wish

to refresh yourself of the organisation’s particular style requirements.

You should create two separate documents; this will allow you to show how you

can apply standardised formatting to different types of documents.

You may ask your instructor for advice on which documents to produce, or they

may specify which ones they want you to produce.

By completing this assessment, you will have demonstrated your knowledge of;

  • Keyboarding and computer skills

  • Literacy skills

  • Problem solving skills

  • Numeracy skills

  • Appropriate technology

  • Computer applications

  • Organisational policies, plans and procedures

  • Organisational requirements for document design

Please give me any details or example that you can think of. thank you in advance

In: Computer Science

Provide SQL Statement for the ff queries: 1. List the total computer offer value in Stevens...

Provide SQL Statement for the ff queries:

1. List the total computer offer value in Stevens Point

2. List of the computer transactions ordered by transaction value in descending order

3. List of the number and average value of computer requests in Wausau

4. List the number and average value of computer transactions

Tables are :

Tb_Product

Prod_ID, Name, MU

Tb_Offers

Supp_ID, Prod_ID, Price, Quantity

Tb_Transactions

Tran_ID,Supp_ID, Con_ID, Prod_ID, Price, Quantity

Tb_Suppliers

Supp_ID, Name, City

Tb_Request

Con_ID, Prod_ID, Price, Quantity

In: Computer Science

Problem 14.1.2 Let M be a DFA with transition function δ. Prove carefully, by induction for...

Problem 14.1.2 Let M be a DFA with transition function δ. Prove carefully, by induction for all strings w over M’s alphabet, that δ ∗ (i, w) = j if and only if there is a path from node i to node j in the graph of M such that the labels on the edges of the path, read in order, form w.

In: Computer Science

Discuss your rationale for choosing the specific firewall in question, and determine the primary way in...

Discuss your rationale for choosing the specific firewall in question, and determine the primary way in which a company could incorporate it into an enterprise network in order to enhance security. Select the two (2) most important and / or unique features of the chosen firewall, and explain the primary reasons why those features make the firewall a viable option in enterprises today. Justify your answer. Discuss what you believe to be the two (2) most important security considerations related to cloud deployments, and explain the main reasons why you believe such considerations to be the most important.

In: Computer Science

Create a program that has an App Class which holds your main() method and create a...

Create a program that has an App Class which holds your main() method and create a Band class.

Create an array of 5 Band objects in your main() method.

Each band should have it's own compete() method along with a a drummer, vocalist, and piano player.

Each band should have the names of the drummer, vocalist, and piano player.

The complete method() assigns a random score between 0 and 20 to to each band.

Create a method to calculate the top 2 winners from highest score to least and write each band's information to a "winners.txt" file.

A grabInfo() method should be called to display a band's information.

In: Computer Science