This maze project assumes that a cell is rectangular, and that there is an entrance into and an exit from the cell. What if the entrance and the exit were closed doors and the user was to choose which door leads to the next cell? What would be some pseudocode for this scenario?
Notice that " switch case " statements are used for this project along with " if " statements. Can they be interchanged and still produce the same results [ i.e., make the switch case statements into if statements, and the if statements into switch case statements ] ? Support your answer!
Reference source code for more information:
public class Maze
{
static Scanner sc = new Scanner(System.in);
// maze movements
static char myMove = '\0';
// cell position
static int currentCell = 0;
static int score = 0;
static boolean advance = true;
static boolean checkThis = false;
public static void main(String args[])
{
// the local variables declared and initialized
char answer = 'Y';
displayMenu();
while(answer == 'Y' || answer == 'y')
{
displayMovement();
makeYourMove();
checkThis = checkYourMove();
mazeStatus();
System.out.println("move again(Y or N)?");
answer = sc.next().charAt(0);
}
System.out.println("***************************");
}// end main() method
static void displayMenu()
{
System.out.println("");
System.out.println("***************************");
System.out.println("----The Maze Strategy---");
System.out.println("");
}// end method
static void displayMovement()
{
if(currentCell == 0)
{
System.out.println("You have entered the maze!!");
System.out.println("There is no turning back!!");
currentCell = 1;
mazeStatus();
advance = true;
}
System.out.println("make your move (W, A, S, D)");
System.out.println("W = up, A = left, S = down, D = right)");
}// end method
static void makeYourMove()
{
myMove = sc.next().charAt(0);
score++;
switch(myMove)
{
case 'W': { MoveUp(); break; }
case 'A': { MoveLeft(); break; }
case 'S': { MoveDown(); break; }
case 'D': { MoveRight(); break; }
}
// end program menu
}// end method
static boolean checkYourMove()
{
if(currentCell == 1 && advance == true)
{
if (myMove == 'W')
{
advance = false;
System.out.println("try again");
return advance;
}
if (myMove == 'A')
{
advance = false;
System.out.println("SORRY, there is no return");
return advance;
}
if (myMove == 'D')
{
currentCell = 2;
advance = true;
System.out.println("continue through the maze");
return advance;
}
if (myMove == 'S')
{
advance = false;
System.out.println("continue through the maze");
return advance;
}
}
return advance;
// end program menu
}// end method
static void MoveLeft()
{
System.out.println("you moved to the left");
}// end method
static void MoveRight()
{
System.out.println("you moved to the right");
}// end method
static void MoveUp()
{
System.out.println("you moved up (forward)");
}// end method
static void MoveDown()
{
System.out.println("you moved down (downward)");
}// end method
static void mazeStatus()
{
System.out.println("current position: cell " + currentCell);
}// end method
}// end class
In: Computer Science
Information Security
-Why are modes of operation needed for block ciphers like AES?
In: Computer Science
If the action is Balance 'B’, use a print balance function to return and print an account balance. You will need to write a function called printbalance.
a. Create a prompt for the user to input the account action. There are three possible actions:
Code | Action | Function |
---|---|---|
D | Deposit | deposit_amount |
W | Withdrawal | withdrawal_amount |
B | Account Balance | account_balance |
Create a function to print the account_balance, print the account actions and create the action for outputting the account balance outputting.
Input Information
The following data will be used as input in the test:
userchoice = input ("What would you like to do?") userchoice = 'B'
Output Information
Your current balance: 500.25
import sys# importing the sys library
# account balance
account_balance = float(500.25)
#PPrint the balance
# This is a custom function, it returns the current balance upto 2
decimal places
def printbalance():
print("Your current balance : %2f" % account_balance)
#the function for deposit
#This is a custom function
def deposit():
deposit_amount = float(input("Enter amount to deposit : ")) # takes
in input for deposit amount
balance = account_balance + deposit_amount #calculates
balance
print("Deposit was $%2f, current balance is $%2f" %(deposit_am
ount,balance)) # prints out the balance
#function for withdraw
#this is a custom function
def withdraw():
withdraw_amount = float(input("Enter amount to withdraw")) # takes
in the withdraw amount
if(withdraw_amount > account_balance): #checks whether the
amount is more than balance or not
print("$%2f is greater than account balance $%2f\n"
%(withdraw_amount,account_balance)) #if yes then
print wd amount greater than balance
else:
balance = account_balance - withdraw_amount
print("$%2f was withdrawn, current balance is $%2f" %
(withdraw_amount, balance))
# User Input goes here, use if/else conditional statement to call
function based on user input
userchoice = input("What would you like to do?\n")
if (userchoice == 'D'):
# here deposit function is called
deposit()
elif userchoice == 'W':
# here withdraw function is called
withdraw()
elif userchoice == 'B':
# here printbalance function is called
printbalance()
else:
# it ends the program execution
sys.exit()
In: Computer Science
I need this in C# with pseudocode
Exercise #2: Design and implement a programming (name it EvenOdd) that uses a while loop to determine and print out all even numbers between 50 and 100 on a single line, separated by commas. Then another while loop in the same program to print out all odd numbers between 50 and 100 on a new line, separated by commas. Document your code and properly label the outputs as shown below.
Even numbers between 50 and 100: 50, 52, 54, 56, 58, 60, 62, 64, …
Odd numbers between 50 and 100: 51, 53, 55, 57, 59, 61, 63, 65, …
In: Computer Science
All code in JAVA please
1. Implement Insertion Sort
2. Implement Selection Sort
*For problem 1 and 2, please:
a. Let the program generate a random array.
b. Output both the original random array and the sorted version of
it
In: Computer Science
In c++:
Code Challenge
Consider the following code:
struct ListNode { int value; struct ListNode *next; };
ListNode *head; // List head pointer
Assume that a linked list has been created and head points to the first node. Write code that traverses the list displaying the contents of each node’s value member
Now write the code that destroys the linked list
In: Computer Science
Problem specifications:
You are tasked with developing a complete temperature conversion program in Java.
Your program should:
-prompt the user with the following menu:
-1-Convert Fahrenheit to Celcius
-2-Convert Celcius to Fahrenheit
-3-Quit Program
The menu must be coded in its own method.
-If user select option 1 then call a method that prompts the user to enter a value in degrees Fahrenheit and return it back to main.
-call a method that converts from Fahrenheit to Celcius
-call a method that displays the degrees in Fahrenheit and its equivalent in degress celcius.
-If user select option 2 then call a method that prompts the user to enter a value in degrees Celcius and return it back to main.
-call a method that converts from Celcius to Fahrenheit.
-call a method that displays the degrees in Celcius and its equivalent in degress celcius.
-if user select option three, abort the process and display a suitable message to that effect.
-the program must repeat the whole processes until user select 3.
-do not allow user to select a value other than 1, 2, or3 from the menu
-declare all needed variables inside the class (globally inside) and out of all methods including main().
In: Computer Science
Create a form with two inputs name and roll number.And write a
script to validate the inputs.Any of them should not be
empty.
Name will be string and roll number will be number between 1 -10
only
In: Computer Science
Assume s is a string of numbers. Write a program that prints the longest substring of s in which the numbers occur in ascending order and compute the average of the numbers found. For example, if s = '561984235272145785310', then your program should print Longest substring in numeric ascending order is: 14578 Average: 5 In the case of ties, print the first substring. For example, if s = '147279', then your program should print Longest substring in numeric ascending order is: 147 Average: 4
I need python code for this one?
In: Computer Science
Develop a python program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:
Account number Balance at the beginning of the month Total of all items charged by this customer this month Total of all credits applied to this customer’s account this month Allowed credit limit
The program should input each of the facts, calculate the new balance (=beginning balance + charges – credits), and determine if the new balance exceeds the customer’s credit limit. For those customers who credit limit is exceeded, the program should display the customer’s account number, credit limit, new balance and the message “Credit limit exceeded”.
In: Computer Science
Using Java,
Ask for the runner’s name
Ask the runner to enter a floating point number for the number of miles ran, like 3.6 or 9.5
Then ask for the number of hours, minutes, and seconds it took to run
Format the numbers with leading 0's if the pace is 8 minutes and 3 second, it should be 8:03 and for marathon time, if its 1 hour and 15 minutes and 9 seconds, it should be 1:15:09
Please read through the whole thing, as the pace table example and fastest man time is listed below...
A marathon is 26.219 miles
Pace is how long it takes in minutes and seconds to run
1 mile.
Example Input:
What is your first name? // user enters Pheidippides
How far did you run today? 10.6 // user enters 10.6
miles
How long did it take? Hours: 1 // user enters 1 hours
Minutes: 34 // user enters 34 minutes
Seconds: 17 // user enters 17 seconds
Example Output:
Hi Pheidippides
Your pace is 8:53 (minutes: seconds)
At this rate your marathon time would be 3:53:12
Good luck with your training!
After your program tells the user what their pace is,
your program will build a table showing the following columns. The
pace table should start with the fastest man time which is Eliud
Kipchoge with a pace of 4:37 and 2:01:04 and continue in 17 minute
and 37 second intervals until you reach the marathon time of the
user.
Example: (THE PACE TABLE EXAMPLE)
Pace Table
Pace Marathon
4:37 2:01:04 ←- Eliud Kipchoge
5:17 2:18:41
5:57 2:36:18
6:37 2:53:55
7:18 3:11:32
7:58 3:29:09
8:38 3:46:46
8:53 3:53:12 ← Pheidippides
HINTS
The table should start with the World Record pace and time which is 4:37, 2:01:04.
Then continues in 17 minute and 37 second intervals until you reach the marathon time of the user.
Use a static function to print the pace table, introduce a while loop.
For the first person it should call a printTable function
Example : printTable (pace, “<--- Eliud Kipchoge”)
The pace table continues until it reaches the user
printTable (myPace, name) something like that
For the marathon and pace time, make sure the format has 0’s if the time is 9 seconds, it should be 09.
Use the printf statement for formatting output (“02d %f%s”)
In: Computer Science
Who are the five scientists who came up with the linear time selection algorithm? How many of them are still alive? What is the title of their original paper? What basis did they have for thinking that a linear time algorithm existed for this problem?
In: Computer Science
The electricity accounts of residents in a very small rural community are calculated as follows: a. if 500 units or less are used the cost is 2 cents per unit; b. if more than 500, but not more than 1000 units are used, the cost is $10 for the first 500 units, and then 5 cents for every unit in excess of 500; c. if more than 1000 units are used, the cost is $35 for the first 1000 units plus 10 cents for every unit in excess of 1000; d. in addition, a basic service fee of $5 is charged, no matter how much electricity is used. The five residents use the following amounts (units) of electricity in a certain month: 200, 500, 700, 1000, and 1500. Write a program which uses logical vectors to calculate how much they must pay. Display the results in two columns: one for the electricity used in each case, and one for amount owed. (Answers: $9, $15, $25, $40, $90)
In: Computer Science
JAVA:
Compute the average of a list of user-entered integers representing rolls of two dice. The list ends when 0 is entered. Integers must be in the range 2 to 12 (inclusive); integers outside the range don't contribute to the average. Output the average, and the number of valid and invalid integers (excluding the ending 0). If only 0 is entered, output 0. The output may be a floating-point value. Ex: If the user enters 8 12 13 0, the output is:
Average: 10 Valid: 2 Invalid: 1
Hints:
Use a while loop with expression (userInt != 0).
Read the user's input into userInt before the loop, and also at the end of the loop body.
In the loop body, use an if-else to distinguish integers in the range and integers outside the range.
For integers in the range, keep track of the sum, and number of integers. For integers outside the range, just keep track of the number.
Use a cast to get a floating-point output: (double) sum / num .
Whenever dividing, be sure to handle the case of the denominator being 0.
In: Computer Science
There are various selection structures that can be used in programming. What are the different relational operators used in selection structures in the Python programming language? Also, explain what short-circuiting is with respect to compound conditional expressions in Python. Provide examples to support your response in addition to constructive feedback on the structures and circumstances posted by your peers. Provide at least one reference to support your findings.
In: Computer Science