3. Write a Java program that generates a set of random strings from a given string of same length where no character is ever repeated and characters belong to the original string.
Examples
Input: “Hello World”
Output: “World oHlel”
In: Computer Science
use java Write a program that, given two binary numbers represented as strings, prints their sum in binary. The binary strings are comma separated, two per line. The final answer should not have any leading zeroes. In case the answer is zero, just print one zero i.e. 0
Input:
Your program should read lines from standard input. Each line contains two binary strings, separated by a comma and no spaces.
Output:
For each pair of binary numbers print to standard output their binary sum, one per line.
In: Computer Science
numbers = [75, 635, 274, 353, 534, 684, 381, 67, 968, 155, 502, 149, 10, 789, 757, 379, \
732, 386, 692, 473, 797,
272, 538, 703, 629, 179, 197, 521, 411, 590, 818, 892, 896, 951, 365, 800, 76\
7, 651, 584, 220, 584, 221,
23, 819, 794, 957, 74, 985, 395, 544, 324, 464, 980, 293, 980, 208, 560, 651,\
710, 21, 322, 968, 610,
947, 622, 369, 504, 113, 785, 119, 46, 332, 137, 865, 127, 333, 83, 403, 696,\
771, 733, 811, 220, 451,
559, 446, 895, 90, 591, 257, 506, 208, 432, 197, 16, 344, 261, 830, 115, 924,\
288, 442, 464, 213, 409,
815, 495, 205, -123, 147, 930, 69, 188, 419, 880, 815, 291, 646, 464, 888, 31\
0, 228, 529, 218, 565, 642,
315, 328, 288, 374, 208, 830, 834, 879, 75, 983, 112, 556, 736, 211, 582, 437\
, 717, 833, 719, 684, 518,
517, 744, 350]
I got to find average, maximum and minimum value from that given list in Python
In: Computer Science
A teacher needs list to fill student scores on five assignments.There are 15 students in her class.The students are numbered 1 through 15.Use nested for loops to print out the list for the teacher.
In: Computer Science
3D printing
What are the technical parameters such as range, speed,
capacity, etc. (if
applicable)?
o What are the strengths and weaknesses of the technology?
In: Computer Science
Write a Java application that inputs an unknown number of employees and determines and displays the gross pay for each employ. The company pays straight time for the first 40 hours worked by each employee (hours times rate), and straight time plus time-and-a-half for all hours worked in excess of 40 hours. Input the number of hours worked and hourly rate for each of the employees, then determine and display the employee’s gross pay. At the end of the program, print the total gross pay for all employees. Make sure you use the sentinel control Algorithm
In: Computer Science
Write a program that determines the probability of tossing a coin 10 times and getting exactly 0, 1, 2, 3, etc. heads. This is the binomial probability distribution. Store the probability in an array. You could get 0 heads or 10 heads or anything inbetween.
Use a for loop. The for loop will go from 0 to 10 inclusive. Use r as the number of successes. So r will go from 0 to 10. The probability of a success is .5, and also the probability of a failure is .5.
Print out in table form, column 1=r; goes 0 to 10, and then column 2; the probability of r.
Use 4 decimal places for the probability. You know if you get the correct answers because The sum of all the probabilities is 1.0, and all probabilities are in the range of 0 to 1 inclusive.
In C++, prefer visual studios but not required.
In: Computer Science
6. Why do you need to declare the data type of a variable before you can use it in Java? Give two (2) reasons
7. Is the World Wide Web and the Internet just two names for the same entity? Explain.
8. Why was it necessary to use the import statement when we used Scanner and Random?
9. Communication was a problem at Target. What would you recommend as an escalation process if someone encounters a threat and wants it to be known to upper management?
10. TCP is extremely reliable in delivering messages. Explain how this reliability is built into the message distribution process. Optional
11. The Operating System of a computer is the glue that bridges the hardware and software of a computer to make it work. Explain three (3) ways (features) the operating system provides to accomplishes that
. 12. Name the three (3) programming constructs we coded in class using Java along with a description of each one.
In: Computer Science
Please use Java language in an easy way with comments! Thanks!
Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack to perform the evaluation. Specifically, you should use the Stack class from the java.util package (For this problem, you must write a static "evaluate" method).
Also, in the same file, write a program that prompts the user to enter a postfix expression. Your program should evaluate the expression and output the result. Your program should call the "evaluate" method described above. Here are some examples:
Postfix expression: 1 2 +
Result: 3
Postfix expression: 1 2 + 3 4 - *
Result: -3
Postfix expression: 3 4 5 + + 1 -
Result: 11In: Computer Science
In Java for beginners:
The math teacher at Garfield High School, Mr. Escalante, is looking for new ways to help his students learn algebra. They are currently studying the line equation ( y = m * x + b ). Mr. Escalante wants to be able to give his students a phone app that they can use to study for the midterm exam. This is what he'd like the program to do:
The user will be presented with the option to study in one of 3 modes, or to quit the program:
In each mode, all of the given values should be randomly generated integers between -100 and +100. This means that the correct answer must be calculated by the program.
Once the student selects a mode, the program will continue to present randomly generated questions until the student has correctly answered 3 questions in a row. If the student attempts more than 3 questions in a particular mode, a hint about how to solve the problem should be given before the next question is presented.
After the student has correctly answered 3 questions in a row, an overall score (the number of questions answered correctly divided by the total number of questions attempted) should be displayed, and the menu is presented again.
DIRECTIONS
Your program must
This is a three-part staged assignment. You must complete part 1 with at least 80% success before you can begin part 2, and the same with part 3. After you've completed and submitted each part, you can proceed to the next part by selecting the drop-down arrow next to the assignment title. You will need to complete all parts to receive full credit.
---------------------------------------------------------------------------------------------
Part 1. Solve for y.
Write a program with a that displays a randomly generated problem that asks the user to solve for the y variable, takes input from the user, and prints "correct" if the user answered correctly and prints "incorrect" if not. Your main should give one problem and then exit. Use one or more methods to produce this behavior. Example interactions: Given: m = 10 x = 3 b = 2 What is the value of y? 32 Correct! Given: m = 6 x = 9 b = 3 What is the value of y? 52 Sorry, that is incorrect. The answer is 57.
Part 2. Solve for y, m and b.
Add 2 choices that behave similarly to your part 1 program, but have the user solve for m and b instead. These choices should also randomly generate problems, and print if the user answers correctly. Your main program should display a menu asking which type of question to ask: Select 1 to Solve for Y, 2 to Solve for M, 3 to Solve for B and 4 to quit. When the user selects the question type, one question should be asked, then the user should return to the menu. This should repeat until the user selects quit, then the program should exit. Use one or more methods and loops to produce this behavior.
Part 3.Three in a Row with Hints.
Update your program so that each problem type mode will repeatedly ask questions until the user gets 3 correct answers in a row. If the attempts more than 3 questions in a particular mode, the program should provide a hint on how to solve problems of this type. After the student has correctly answered 3 questions in a row, an overall score (the number of questions answered correctly divided by the total number of questions attempted) should be displayed, and the menu is presented again.
In: Computer Science
1. Lets construct a Dog class
2.Declare name, breed and weight as their private variables
3.Add a default constructor
4.Write a constructor with name, breed and weight as arguments
5.Add a toString method to the class
6.Add a equals method
7.Add a copy contructor
8.Add a bark method in Dog class
•This method checks if the weight is greater than 25 , then print (dog.name says woof!) else (dog.name say yip!)
In: Computer Science
Draw a memory layout to show the relations of a, b and c.
char a[3][10] = {"abcdefg", "1234567", "!@#$%^&"};
char* b[3];
char** c;
b[0] = &a[0][0];
b[1] = &a[1][0];
b[2] = &a[2][0];
c = b;
char x = b[0][3];
char y = b[0][13];
In: Computer Science
(matlab) Since the problem is fairly complex, it may be better to complete & debug the program offline, then submit in Grader.
In this exercise you will complete a simplified program to play a hand of Blackjack. The goal is to complete a modular program using local and anonymous functions. Although there are several functions that must be written, they are all quite short and simple, just 1 to 4 lines. The most important learning objective is to understand how function definitions and function calls fit together.
PART 1: At the bottom of the template, complete the following local functions:
deal_hand() function
This function will generate a hand of two cards by generating two random numbers between 1 and 13.
Input argument: None
Output argument: A row vector of 2 integers between 1 and 13.
The body of the function can be implemented in a single line using the Matlab built-in function randi(). (NOTE: we are making a simplifying assumption that we have an infinite deck of cards, so we don’t have to keep track of which cards have already been dealt.)
To deal two cards, each having a value between 1 and 13, the form of the function is:
hand = randi (13, 1, 2);
display_hand() function
This function will display a blackjack hand to the screen.
input argument: a row vector containing the hand as described in 1.
output argumen: None
The contents of the display_hand() function will be as follows:
Define a row vector with characters representing the card values, like so:
cards = ['A','2','3','4','5','6','7','8','9','T','J','Q','K'];
(this can also be written more compactly as cards='A23456789TJQK')
NOTE: Each card is represented by a single character; thus ‘T’ is used for 10.
The character corresponding to a card value is accessed by indexing. For example if the card is a ten, the corresponding character using can be displayed by:
fprintf(‘%c’,cards(10))
The entire hand can be displayed with a single fprintf() call as follows:
fprintf(‘%c ’,cards(hand))
Once the hand has been displayed, print a new line using
fprintf(‘\n’)
score_hand()function
This function calculates the score of a blackjack hand.
Input argument: a hand (row vector of numbers between 1 and 13)
Output argument: the score corresponding to that hand of cards
To keep it simple, we will only allow the Ace to have a value of 1. (Allowing it to have either a value of 1 or 11 depending on context is a challenge problem that you can try after you have the rest of the game working.)
With this restriction, the value of the card is equal to the number representing the card, with the exception of face cards (11, 12, and 13), which are worth 10. You can use the min() function and the sum()function to sum the values of the cards while limiting each card to an upper value of 10.
Since the simplified score_hand() function only requires one line of code, it can be implemented via an in-line (anonymous) function. Try implementing it that way. It can be defined anywhere in the script before it is called for the first time.
deal_card() function
This function adds a card to an existing hand. Generate a single card using randi(), and use concatenation to add it to the existing hand. For example,
new_hand = [existing_hand new_card];
Input argument: a hand (row vector of numbers between 1 and 13)
Output argument: a hand consisting of the input hand with one additional card added to it.
PART 2: Add calls to your user-defined functions in the appropriate places of the template script. So that you don't have to think much about the logic of the game for this exercise, we have provided the looping and branching code.
(Script)
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%to make an anonymous function for score_hand()
%complete this line:
score_hand = %code to calculate the score
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%Testing the functions
testScore = score_hand(deal_card(deal_hand()));
testLength1=length(deal_hand());
testLength2=length(deal_card(deal_hand()));
disp('Blackjack:')
display_hand([1,13]);
%The main things that your program has to do are:
%
% Deal the cards
% Display the hand
% Calculate the score and store in the variable player_score or
% dealer_score
% display the score
%
%The other logic (when to quit the game, etc.) is already built into the
%template
%****************************************************
% ENTER YOUR CODE BETWEEN THE %XXXXXXXXXXXXXXX LINES.
%
%****************************************************
dealer_score = 0; %initialize dealer score so grader doesn't fail if player busts
disp('Your hand:')
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
% Deal the player's initial cards, score the hand, display the hand, display the score
player_score = 0; %Replace the 0 with a function call
fprintf('Score = %i\n', player_score);
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
hit = 1; %flag that says deal another card
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%CHANGE THE FOLLOWING LINE AFTER YOU HAVE COMPLETED THE REST OF THE SCRIPT
%CHANGE THE 1 TO A 0
busted = 1; %flag that says player is not busted
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
while busted == 0 && hit == 1 && player_score < 21
% Since this game does not use user input, use a semi-intelligent
% algorithm to decide whether the player hits:
% if his score is <15, definitely hit
% if his score is >18, do not hit
% if his score is between 15 and 18, generate a random number
% to decide if he hits.
hit = player_score<15 || 15+randi(4)>player_score;
if hit == 1
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
% Deal one more card and calculate the score and display the hand
% and the score
fprintf('Score = %i\n', player_score); %display the score
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if player_score > 21
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
% The player is busted and stops playing. Display a losing
% message
busted = 1;
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end
end
end
if busted == 0
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
% Deal the dealer a separate hand, score it, then show it
disp('Dealer''s hand:')
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
while (dealer_score < player_score) && (dealer_score < 21)
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%Deal the dealer a new card and calculate his score and display his
%new hand
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end
if dealer_score > 21
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
% Show that the player wins
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
else
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%Show that the dealer wins
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end
end
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
%Complete these local functions
%Add input & output arguments as needed
function [] = deal_hand()
end
function [] = deal_card()
end
function [] = display_hand()
cards = 'A23456789TJQK';
end
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
In: Computer Science
Write a program that will calculate the sum of the first n odd integers, and the
sum of the first n even integers.
Use a Do while loop
Use a for loop
Here is a sample of how the program should run:
How many odd integers would you like to add? 5
Count Odd Integer Sum
1 1 1
2 3 4
3 5 9
4 7 16
5 9 25
The sum of the first 5 odd integers is 25
How many even integers would you like to add? 7
Count Even Integer Sum
1 2 2
2 4 6
3 6 12
4 8 20
5 10 30
6 12 42
7 14 56
The sum of the first 7 even integers is 56
Do you want to add again? Press y or n
y
How many odd integers would you like to add?
Make sure your program works with any input value from 1 to 1000.
REMEMBER! The sum of the first 5 odd integers is 1 + 3 + 5 + 7 + 9. It is NOT the
sum of the odd integers up to 5
In: Computer Science
Below is part of my code to sort table of x,y,z cordinates using x,y with qsort. I can read all the data into *xyz part of the structure and allocate memory, I keep getting errors on line 7, "read access violation". I would take any help...Thanks
typedef struct
{
int x;
int y;
int z;
} Coordinates;
typedef Coordinates * xyz;
int compare(const void *p1, const void *p2)
{
const xyz num1 = *(const xyz *)p1;
const xyz num2 = *(const xyz *)p2;
7 if (num1->x < num2->x) //read access violation
{
return -1;
}
else if (num1->x > num2->x)
{
return 1;
}
else
{
if (num1->y < num2->y)
{
return -1;
}
else if (num1->y > num2->y)
{
return 1;
}
else
{
return 0;
}
}
Main
{
//allocates memory
Coordinates * xyz = (Coordinates *) malloc(sizeof(Coordinates) * numElem);
qsort(xyz, numElem, sizeof(xyz), compare);
}
In: Computer Science