JAVA:
Use existing Java Stack class to solve the "Balancing Symbols" problem. The symbols are (), [], and {}, and each opening symbol must have a corresponding closing symbol as well as in correct order. Ignore operands and arithmetic operators since they are not relevant to our problem. You can assume each token is separated by spaces. For example:
{ ( a + b ) * c1 } – valid
{ ( a + b ) * c1 ] – invalid
( ( a + b ) * c1 } / 15 ) – invalid
Outline a solution to handle an expression like {(a+25 )*c1}. Notice that spaces are now optional.
Implement a Queue ADT using a circular array with 5 string elements. Create a Queue object and try various operations below.
Queue myQueue; // Queue myQueue = new Queue(); in
JavamyQueue.enqueue(“CPS 123”);
myQueue.enqueue(“CPS 223”);
myQueue.enqueue(“CPS 323”);
myQueue.dequeue();
myQueue.enqueue(“CPS 113”);
myQueue.enqueue(“CPS 153”);
string course = myQueue.front(); // course should be CPS 223 size =
myQueue.size(); // size should be 4
// output course and size
In: Computer Science
In: Computer Science
Make a C program that simulates time-sharing in the operating system.
Please follow the instructions provided:
a) Use a circular queue.
b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes.
c) As this requires process name and duration, use an array of structures.
d) To simulate time-sharing, following the algorithm presented below:
d.1) Use the sleep() function to simulate the time duration in
seconds.
d.2) The CPU processes the job at the head of the queue.
d.3) The maximum time each process can execute is 10 seconds.
d.3.1) If a process has a duration of more than 10 seconds, then after running for 10 seconds it is timed out and returned to the queue (and reprocessed later).
d.3.2) Do not forget to reduce the time duration of the job by 10 seconds.
d.4) If a process has a remaining time to execute of x seconds (where x <= 10), then this process can execute until the x seconds is consumed. The process is then terminated.
d.5) As the process is executed, display the process name as well as the remaining time after it timed out.
d.6) While there are still processes left in the queue, repeat step 3b. Otherwise, the program terminates. The program shall display a message upon completion of all the jobs in the queue.
e) To test your program, try out four different sets of processes.
e.1) There should be five processes per set and each process should have its corresponding process name and duration in seconds.
e.2) In the input, if the duration is zero or negative, your program should warn the user about it and should ask the user to input again the duration.
Thank you.
In: Computer Science
Write a method that returns the percentage of the number of elements that have the value true in an array booleans.
In: Computer Science
SCHEME
In: Computer Science
PUT IN JAVA PROGRAMMING LANGUAGE
The Rectangle class:
Design a class named Rectangle to represent a rectangle. The
class contains:
• Two double data fields named width and height that specify the
width and height of a rectangle. The default values are 1 for both
width and height.
• A no-arg (default) constructor that creates a default
rectangle.
• A constructor that creates a rectangle with the specified width
and height.
• A method named findArea() that finds the area of this
rectangle.
• A method named findPerimeter() that finds the perimeter of this
rectangle.
• Create a client (test) class (program) to test and use your
Rectangle class.
In the client program, you need to create objects of the Rectangle type and use those
objects to perform some meaningful and valid rectangle operations (finding area and perimeter).
The test/client class should display all results.
In: Computer Science
What is the difference among the principles of modularization, abstraction, encapsulation, and separation of interface and implementation. Please provide with related examples.
#Course: Software Engineering
In: Computer Science
PUT IN JAVA PROGRAMMING
The StockB class:
Design a class named StockB that contains the following
properties:
• Name of company
• Number of shares owned
• Value of each share
• Total value of all shares
and the following operations:
• Acquire stock in a company
• Buy more shares of the same stock
• Sell stock
• Update the per-share value of a stock
• Display information about the holdings
• The StockB class should have the proper constructor(s).
• Create/write a client class (program) to test and use your StockB
class. In the client program,
you need to create objects of the StockB type and use those objects
to perform some meaningful and valid stock transactions.
In: Computer Science
Draw a DFA for the following ( ∑ = {0,1}):
In: Computer Science
Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, it will be 15 (3pm). Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what the time will be on the clock when the alarm goes off.
Using python
In: Computer Science
UNIX ONLY -- DIFFICULT LAB ASSIGNMENT
This is an extremely difficult subject for me. Could you please give step by step instructions on how to write a script called "encrypt_password.sh" and say line by line what the code should be to complete the assignment according to the instructions and examples below?
The assignment will be done entirely in Terminal on Mac
Our Lab assignment is as follows:
In this lab, you will write a script called encrypt_password.sh to encrypt passwords. The script will ask user to enter user name and password repeatedly and will store it in file unencrypted. Then the script will read the user names and the corresponding passwords from the unencrypted file one line at a time, encrypt the password, and store the name and the encrypted password in another file. The objective of this lab is to familiarize and gain proficiency with the following:
• Use of loops (while and for)
• Read input from keyboard
• Read from file line by line
• Use of md5sum utility to generate md5 hash
The md5sum utility (command) computes and checks a MD5 message digest of a file. Message digest is the cryptographic hash of a clear text. Cryptographic hash or message digest is a one-way encryption; once encrypted the hash cannot be decrypted to get the original text. There are many algorithms for generating message digest or hash from text. MD5 is one such algorithm. Other algorithms are SHA256, SHA512etc. Unix/Linux has utilities(commands) to generate message digest using these algorithms. MD5 uses 128-bit encryption and is considered not secured. SHA 256 or SHA 512 is more secured than MD5. Following is the command to create a hash of a file called “input.txt” using MD5algorithm is
md5sum input.txt
The command to create a hash of the string “CSC2500 is fun and interesting” is
echo CSC2500 is fun and interesting | md5sum
Your script should accept two command line arguments. The 1st argument should be number of users and the 2nd argument should be the name of the unencrypted file.
Your script should do the following
1. Accept user name and password using for loop repeatedly (as many times as the 1st argument).
2. Write the user name and password to the designated file (2nd argument) separated by colon (:) as it reads the inputs from user.
3. Once all the names and passwords are written into the file; read the unencrypted name and password one line at a time from the unencrypted file and encrypt the password and write the username and the encrypted password into the encrypted file (separated by colon). The name of the encrypted file should be same as the unencrypted file with an extension .enc. For example, if the name of the unencrypted file is “user”, the name of the encrypted file should be “user.enc”
Following is an example of the execution of the script
./encrypt_password.sh 3 userInfo
Enter Name: user23
Enter Password: lol
Enter Name: user21
Enter Password: hehe
Enter Name: Mike
Enter Password: password
After the successful execution of the script the current directory should contain two files name userInfo and userInfo.enc
The content of userInfo should be
user23:lol
user21:hehe
Mike:password
The content of the userInfo.enc should be
user23:59bcc3ad6775562f845953cf01624225
user21:f68277605308bf967037423eb4f03fcf
Mike:11408e6f3846af9379b7ca60cbf1b913
Following is an example script that reads lines from a file called input.txt and will print 1st and 3rd words of all the lines.
#!/bin/bash
while read -r line #line is a variable which will store the line read from the file
do
first=$(echo $line | cut -d ' ' -f 1)
third=`echo $line | cut -d ' ' -f 3`
echo $first $third done
THANKS!
In: Computer Science
The Following Java expression:
S/10 * 10 + 10 – S = C
Show that this expression gives a value of 2 when S contains the int value 78. You must show every step in your working, performing exactly one operation on each line.
I have tried to no end to make sense of this and I know there is an order of precedence in the operators but I can't make any sense of it. Could someone please explain this to me?
In: Computer Science
Explain the use of neural networking modeling in predictive analytics. Discuss a real-life example of where a neural network model could be used or is used currently in your organization. How would you use SAS Enterprise Miner to create a neural network model of your example?
In: Computer Science
Why normalization and referential integrity are important principles when designing relational databases?
In: Computer Science
I am having trouble with my assignment and getting compile errors on the following code. The instructions are in the initial comments.
/*
Chapter 5, Exercise 2
-Write a class "Plumbers" that handles emergency plumbing
calls.
-The company handles natural floods and burst pipes.
-If the customer selects a flood, the program must prompt the user
to determine the amount of
damage for pricing.
-Flood charging is based on the numbers of damaged rooms.
1 room costs $300.00, 2 rooms cost $500.00, and 3 or more rooms
cost $750.00.
-Pipe bursting is based on the number of pipes: 1 pipe costs
$50.00, 2 pipes cost $70.00,
and 3 or more pipes cost $100.00.
-The Plumber class should contain a nested class to handle
billing charges.
Use And, Or, and Not in the if statements to obtain the customers'
inputs.
*/
import java.util.Scanner; //Import scanner
public class Plumbers //create Plumbers class
{
private void getData()
{
double rmsPrice = 0;
double pipesPrice = 0;
double roomOne = 300.00;
double roomTwo = 500.00;
double roomThreePlus = 750.00;
double pipeOne = 50.00;
double pipeTwo = 70.00;
double pipeThreePlus = 100.00;
Scanner scanner = new Scanner(System.in);
//Ask about flooding
System.out.println("Thank you for calling. If you are flodding
please enter 1 for yes and 2 for no: ");
int userInput1 = scanner.nextInt();
//Ask about how many rooms are flooded if 1
if (userInput1 == 1)
System.out.println("How many pipes?. Please enter 1 for 1 pipe, 2
for 2 pipes, or 3 for 3 or more: ");
int userInput2 = scanner.nextInt();
if (userInput2 == 1)
rmsPrice = roomOne;
else
if (userInput2 == 2)
rmsPrice = roomTwo;
else
if (userInput2 == 3)
rmsPrice = roomThree;
//Ask about broken pipes
System.out.println("Do you have broken pipes? Please enter 1 for
yes and 2 for no: ");
int userInput3 = scanner.nextInt();
//Ask about how many pipes are busted if 1
if (userInput3 == 1)
System.out.println("How many pipes?. Please enter 1 for 1 pipe, 2
for 2 pipes, or 3 for 3 or more: ");
int userInput4 = scanner.nextInt();
if (userInput4 == 1)
pipesPrice = pipeOne;
else
if (userInput4 == 2)
pipesPrice = pipeTwo;
else
if (userInput4 == 3)
pipesPrice = pipeThree;
if (userInput1 == 1 && userInput3 == 1 &&
userinput4 >= 3 && userInput2 >= 3)
System.out.println("Wow! You have some Biblical flodding going on
there!");
System.out.println("Your total is: $" + (rmsPrice +
pipesPrice));
else
if ((userInput1 == 1 && userInput3 == 1) || (userInput1 ==
0 && userInput3 == 1) || (userInput1 == 1 &&
userInput3 == 0))
System.out.println("Your total is: $" + (rmsPrice +
pipesPrice));
else
if ((userInput1 == 0 && userInput3 == 0))
System.out.println("Please enter an amount of rooms or pipes."
);
}
}
In: Computer Science