JAVA programming Classwork- please answer all prompts as apart of one java programming project
Part A
Add to your project this class Position, which has x and y coordinates.
Create an abstract class GameElt, which has a String name, an int health (keep it in the range 0 to 100) and a Position pos.
For GameElt, include a default constructor that starts pos at (0, 0), and a parameterized constructor that takes x and y coordinates and a name. health should always start at 100.
Create a class BigDarnHero which inherits from GameElt. Override toString so that when we print a hero, we see something like "Thondar the Hero (3, 17)" based on the name and the position. Other than toString and two constructors taking the same parameters as in GameElt, you do not need to add anything else for this class at this time.
Part B
☑ Create an interface MoveStrategy which requires methods
The idea is that moving in a given direction will change the given position, and chanceToFall will return true if a fall happened or false otherwise. How this happens will depend on the implementation in the actual classes.
Moving North or South will change the Y coordinate (vertical movement) moving East or West will change the X coordinate (horizontal movement). Direction will be passed as "N", "S", "E", or "W".
☑ Write a class WalkMoveStrategy which implements MoveStrategy. When walking, the position changes by 1 in the direction chosen, and a message like "Walking from (7,1) to (7, 2)." should also be printed out.
People who are walking have a 1 in 20 chance of falling. In chanceToFall choose a random number and use it to determine if chanceToFall returns true.
You do not need to add anything other than the methods to implement the strategy, not even a constructor
☑ Change GameElt so that it also has an instance variable moveStrat of type MoveStrategy.
Add to GameElt a method move(direction) which calls moveStrat's move method, passing it the direction given and GameElt's pos instance variable. Then call chanceToFall and if the GameElt fell while moving, print a statement about this and reduce health by 5.
☑ In all constructors for BigDarnHero, set the MoveStrategy to a new instance of WalkMoveStrategy.
☑ In a main program, create a BigDarnHero named "Mighty Thog" at (5, 3) and have them walk three moves north and one west. Print the hero before they move, and again after they have moved.
Part C
☑ Add another class RunMoveStrategy which implements MoveStrategy, and whose move method changes the position by 5 in the direction given, as well as printing something like "Running from (9, 3) to (4, 3). Boy my mighty thews are tired."
People who run have a 1 in 10 chance of falling.
☑ To BigDarnHero, add a method speedUp() which changes the hero's MoveStrategy to a RunMoveStrategy, and a method slowDown which changes the MoveStrategy to a WalkMoveStrategy.
☑ In the main program, have Mighty Thog move around, speed up, move around, slow down, and move around again.
Part D
☑ Add another strategy for movement, RandomCursedMoveStrategy, which changes the position by a random amount in a random direction, no matter what direction is passed in, and prints out something like "Truly, I am accursed and shall never get to class on time".
People moving by this strategy have a 50/50 chance of falling and hurting themselves.
In the main program, create a hero, set this as their movement strategy, and add some movement for them.
In: Computer Science
Professor Al Gorithum has the following grading policy:
Al likes to round each student's grade according to these rules:
For example, grade=84 will be rounded to 85 but grade=29 will not be rounded because the rounding would result in a number that is less than 40.
Given the initial grade value for each of Al's students, write code to automate the rounding process.
Detailed Description
What to submit:
In: Computer Science
def main():
print('This program determines whether you have hypertension.')
systolic_pressure = float(input('Enter your systolic pressure: '))
diastolic_pressure = float(input('Enter your diastolic pressure: '))
# insert statement here to call the hypertension_tester function
def hypertension_tester(dp, sp):
if sp >= 140 or dp >= 90:
print('You have hypertension')
else:
print('You do not have hypertension')
main()
A person has hypertension if systolic pressure is 140 or above or diastolic pressure is 90 or above. Which of the following statements correctly calls the hypertension_tester function?
A. |
hypertension_tester(diastolic_pressure, systolic_pressure, ) |
|
B. |
hypertension_tester(sp=systolic_pressure, dp=diastolic_pressure) |
|
C. |
Both (A) and (B) are correct |
|
D. |
Both (A) and (B) are incorrect |
def main():
num1 = float(input('Enter a number: '))
num2 = float(input('Enter another number: '))
difference, total = sum_diff(num1, num2)
print('Their total is', total)
print('Their difference is', difference)
# Insert definition of the sum_diff function here
main()
Which of the following definitions of the sum_diff function is correct?
A. |
def sum_diff(x, y): sum = x + y diff = x - y return sum return diff |
|
B. |
def sum_diff(x, y): sum = x + y diff = x - y return diff, sum |
|
C. |
def sum_diff(x, y): sum = x + y diff = x - y |
|
D. |
def sum_diff(x, y): sum = x + y diff = x - y return sum, diff |
my_dict = {21 : 'Amy', 45 : 'Bob', 62 : 'Connie', 57 : 'Dave'}
Which of the following statements will display the string 'Bob'?
A. |
print(my_dict[1]) |
|
B. |
print(my_dict[45]) |
|
C. |
print(my_dict['45']) |
|
D. |
None of the above |
Which of the following statements creates an empty set in Python?
A. |
my_set = ( ) |
|
B. |
my_set = set() |
|
C. |
Both (A) and (B) create an empty set |
|
D. |
None of the above |
Suppose all elements in the set my_set are integers. Which of the following Python program fragments selects all even numbers from my_set and stores them in my_set2?
A. |
my_set2 = {x for x in my_set if x % 2 == 1} |
|
B. |
my_set2 = [x for x in my_set if x % 2 != 0] |
|
C. |
my_set2 = {x for x in my_set if x % 2 == 0} |
|
D. |
none of the above |
In: Computer Science
Suppose that you have a list containing the following 10 letters: A C E G L M P S T Y. Binary search is applied for the following questions.
A) What is the maximum number of comparisons needed
to find if any letter in the alphabet is in the list?
B) How many comparisons would it take to find if A is
in the list? If K is in the list?
In: Computer Science
In: Computer Science
Consider the three following pieces of pseudocodes. In each case,
- Give the number of times "Hello" will be printed,
- Generalize, giving the number of times as a function of n
- Express this in theta notation in terms of n.
a) set n = 32
set i = 1
while i<= n
print "Hello"
i=i*2
endwhile
b) set n = 4
set i = 1
while i not equal to n
print "Hello"
i=i+2
endwhile
c) set n = 4
set i = 1
while i<= n
set j = 1
while j <= i
print "Hello"
j=j+1
endwhile
i=i+1
endwhile
In: Computer Science
Manipulating Strings
Manipulating strings are an important part of programming. When I first started I had quite a few assignments on just taking the strings apart and doing different manipulations to them. This helped me understand programming logic and ended up helping me a lot with future database programs. String manipulations can be done in programming, database, and reports which make it essential to know.
Class, have you been practicing some string manipulations? Any tips or tricks?
Dealing with Python Code language: Any enlightenment on this subject would help not just with the discussion question but to better understand this topic.
Thanks,
In: Computer Science
In C++, cstring is implemented as an array of characters. What is the difference between cstring and a regular array of characters? In other words, how do you distinguish them?
In: Computer Science
In: Computer Science
Python Programming, Could you also show the right indents in Python Shell. Below are the skeleton of the program, and the input and output.
# Initialize list
mylist = [ ]
# Set up loop to put menu on screen
num = 1
while num != 0:
print(" ")
print(" ")
print(" Menu ")
print ("0 - Quit")
print ("1 - Add item to list")
print ("2 - Pop item off list and print it")
print ("3 - Print list")
print ("4 - Sort list")
print ("5 - Reverse list")
snum = input("Enter choice from menu ")
num = int(snum)
print (" ")
Put your if or if-else or if-elif statements here
(They will be inside the while
loop)
You should start this lab by entering the above program and saving it as Week5LabA in your Python Programs folder. Then run it to see how it displays the menu. Note that you can enter 0, 1, 2, 3, 4, or 5 in response to the menu choices. Your entry will be assigned to the variable num. Entering a 0 will end the program.
Your other entries (1, 2, 3, 4, or 5 ) should cause something to be done with the list that is called mylist. You will note that mylist has been initialized to the empty list with the mylist = [ ] statement.) For example, if you enter a 1 (value of num is 1), the program should ask you to enter a value to be placed on the list and then append it onto the list. As another example, if you enter a 3 (value of num is 3), the program should print the list using the statement, print(mylist).
The video below shows what the original program (the one I gave you above) should do and how you can enter the if statement for a value of 1 for num.
View video to get started=> https://youtu.be/PxTwMpBFFas
The following is a sample execution of the program. The following integers were placed on the list: (Values entered by the user are in red.)
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 1
Enter value to put on list 3
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 1
Enter value to put on list 7
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 1
Enter value to put on list 9
The following operations were performed on the list:
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 3
[3, 7, 9]
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 4
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 5
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 3
[9, 7, 3]
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 2
Value popped = 3
Menu
0 - Quit
1 - Add item to list
2 - Pop item off list and print it
3 - Print list
4 - Sort list
5 - Reverse list
Enter choice from menu 3
[9, 7]
In: Computer Science
Respond to the following in a minimum of 175 words:
One of the most important concepts of programming is handling input and output. The following activity will allow you to get familiar with this concept specifically when using PYTHON.
Write a function to add two values and display the results. (Please show me where indentation goes as well, I'm not only seeking guidance on answers I'm trying to understand this so I can learn).
Discuss the steps in your thought process as you created the code, any issues you encountered, and how you solved those issues.
In: Computer Science
Read the following code:
x = 1
while(x < 26)
print(x)
x = x + 1
There is an error in the while loop. What should be fixed?
Add a colon to the end of the statement Begin the statement with the keyword count Change the parentheses around the test condition to quotation marks Use quotation marks around the relational operator
Question 2(Multiple Choice Worth 5 points)
(03.03 LC)
Python uses __________ to determine whether the condition of a
while loop is true or false.
algebra artificial intelligence Boolean logic input
Question 3(Multiple Choice Worth 5 points)
(03.03 LC)
What is the proper syntax for writing a while loop in Python?
Begin the statement with the keyword repeat End the statement with a semicolon Place the test condition outside of parentheses Use relational operators to indicate test conditions
Question 4(Multiple Choice Worth 5 points)
(03.03 LC)
What is the purpose of using a while loop in Python?
To repeat an action when the condition is false To repeat an action when the exact number of repetitions is known To repeat an action when the exact number of repetitions is unknown To repeat an action when the condition is not stated
Question 5(Multiple Choice Worth 5 points)
(03.03 MC)
Read the following code:
n = 2
while(n < 5):
print(n)
n = n + 1
What output would be produced for the given values of n?
0 1 2 3 4 1 2 3 4 5 2 3 4 2 3 4 5
In: Computer Science
Create JAVA PROGRAM, and write comment for codes also.
1) Let the user enter in candidate names for a ballot. Then imagine the program is moved to a voting booth. Each voter enters their unique name and who they vote for, and when there are no more voters display who won. (Imagine something outside your program is telling it there are no more voters.)
In: Computer Science
PLEASE DO IN JAVA
4.15 Palindrome
A palindrome is a string that is the same spelled forward as it is spelled backward. So, "abcba" is a palindrome, as are "eye" and "madam". This program takes as input from the user, a string and outputs whether the string is a palindrome.
(1) Modify the given program to use a loop to output the string one character at a time. (1 pt)
Example output for word = radar:
Word Entered: radar r a d a r
(2) Now modify the program to use a loop to output the string in reverse order one character at a time. (2 pt)
Example output for word = read:
Word Entered: read r e a d Word Reversed: d a e r
(3) Finally, modify the program to check character-by-character the string given by the user to see whether or not the string is a palindrome, and then prints either "Yes" or "No". For example, if the input string is "abba" or "rotator", the output would be "Yes". If the input string is "cat" or "garbage", the output would be "No". You may ignore punctuation, in that the test strings used for this program do not contain any. You may also assume all lowercase letters will be used in the test strings.
Note: The strings may be of odd or even length, as in "cat", "dad", "racecar", or "hannah". (8 pt)
Example output for word = radar:
Word Entered: radar r a d a r Word Reversed: r a d a r Yes
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
/* Your Code Here */
return;
}
THANK YOU SO MUCH
In: Computer Science
Design and construction of a multipurpose security
system with alarm and display
A. Provide the activities sequence with bar chart.
B. work breakdown structure
In: Computer Science