This document describes a computer program you must write in Python and submit to Gradescope. For this project, the program will simulate the operation of a vending machine that sells snacks, accepting coins and dispensing products and change. In an actual vending machine, a program running on an embedded computer accepts input from buttons (e.g. a numeric keypad) and devices such as coin acceptors, and its output consists of signals that control a display, actuate motors to dispense products, etc.. However, for this project you will build a simulation where all of the necessary input signals are replaced by keyboard input from a user, and all output signals and actions are indicated by printing text to the terminal. 2. PREVIEW Here is a sample session of using the kind of vending machine simulator you are going to write. This example is meant to convey the general idea. A longer sample input and output for the program can be found in Section 7. Red boxes indicate keyboard input from the user. CREDIT : $0 .00 > inventory 0 Nutrition nuggets $1 .00 (5 available ) 1 Honey nutrition nuggets $1 .20 (5 available ) 2 Almonds $18 .00 (4 available ) 3 Nutrition nugget minis $0 .70 (10 available ) 4 A carrot $4 .00 (5 available ) 5 Pretzels $1 .25 (8 available ) CREDIT : $0 .00 > 3 MSG : Insufficient credit CREDIT : $0 .00 > quarter CREDIT : $0 .25 > quarter CREDIT : $0 .50 > quarter CREDIT : $0 .75 > 3 VEND : Nutrition nugget minis RETURN : nickel CREDIT : $0 .00 > 3. OPERATIONAL SPECIFICATION This section describes how your program must operate. The program will be given one command line option, which is the name of a text file containing the inventory. The format of this file is described below (Section 3.1). The program will read this file to determine the starting inventory of snacks. It will then begin the simulation, in which it reads user commands and responds accordingly. The required commands are described in Section 3.4. 3.1. Inventory. Before starting the simulation, your program must open, read, and close the text file specified in the first command line argument after the script name. This file will consists of 6 lines, each of which describes one of the six snacks available for purchase. The format of a line is stock,price,name where stock is the number of the snack available at the beginning of the simulation, price is the price of the snack in cents (which will be a multiple of 5), and name is a string not containing the character ”,” that describes the snack. The order of the snacks is important, because when ordering from the machine, a snack is indicated by its 0-based index; thus snack 2 means the third line of the inventory file. Here is a sample inventory you can use for testing: 6,125,Cheesy dibbles 10,115,Oat biscuits 12,75,Sugar rings 5,150,Celery crunchies 6,205,Astringent persimmon 10,95,Almond crescents This inventory file is available for download from https://dumas.io/teaching/2020/fall/mcs260/project2/sample_inventory.txt This inventory indicates, for example, that snack 2 is Sugar rings, of which there are initially 12 available, each of which has a cost of $0.75. 3.2. The simulation. After reading the inventory, your program should enter a loop (the command loop) in which it does the following, repeatedly, in order: • Print CREDIT: followed by the total amount of credit currently deposited in the machine, printed on the same line. The credit is initially $0.00. It should always be printed as a dollar sign, followed by a dollar amount with two digits after the decimal point. • Print a prompt > • Wait for one line of user input • Perform the action associated with the user input, which may involve additional output (see Section 3.4) Note that during the simulation, you need to keep track of the credit (the total amount of money deposited to the machine) and display it on each iteration of the loop. The remaining stock of each snack must also be tracked, as this will change as a result of purchases and restocking. 3.3. Control logic overview. The next section describes the commands your simulation must accept from the user. This section is a high-level description of the underlying principles of operation; for full details see Section 3.4. The simulated vending machine allows the user to insert coins to add credit. If the credit already equals or exceeds the price of the most expensive snack in the inventory, any coin inserted will be immediately returned. The user can select a snack by number (0–5), and if the credit currently in the machine equals or exceeds the price of the snack, then the snack is dispensed. Any change (the difference of the credit and the price) is dispensed as coins. Finally, a maintenance worker can specify that one of the snacks is being restocked, i.e. more of that snack has been loaded into the machine. Restocked snacks are then available for purchase. 3.4. Commands. The simulation must support the following commands: • quarter - simulates deposit of one quarter ($0.25). If the current credit is less than the most expensive item in the inventory (including any items that may be out of stock), the coin is accepted and credit increases by $0.25. Otherwise, the coin is rejected by printing the line RETURN: quarter to indicate that the quarter just deposited is returned. • dime - simulates deposit of one dime ($0.10). The logic is the same as the quarter command, except that if the dime is not accepted, the line to be printed is RETURN: dime • nickel - simulates deposit of one dime ($0.05). The logic is the same as the quarter command, except that if the nickel is not accepted, the line to be printed is RETURN: nickel • inventory - display the current inventory in the format of 0-based index, followed by name, followed by price, and then a parenthetical statement of the number available, in this format: 0 Cheesy dibbles $1.25 (6 available) 1 Oat biscuits $1.15 (10 available) 2 Sugar rings $0.75 (12 avilable) 3 Celery crunchies $1.50 (5 available) 4 Astringent persimmon $2.05 (6 available) 5 Almond crescents $0.95 (10 available) • Any of the digits 0, 1, 2, 3, 4, 5 - this is a request to purchase the snack whose 0-based index in the inventory is the given integer. The action depends on the current credit and stock: – If the current credit is sufficient to purchase that snack, and if the stock of that snack is positive, then the machine dispenses the snack followed by change. Dispensing the snack is simulated by printing VEND: Name of snack where “Name of snack” is replaced by the name specified in the inventory. Then, returning change is simulated by printing lines such as RETURN: quarter RETURN: dime RETURN: nickel so that each line corresponds to one coin that is returned. The process for making change is subject to additional rules, described in Section 3.5. After a successful purchase and dispensing of change, the stock of that item decreases by one, and the credit is set to $0.00. – If the stock of the requested item is zero, the following line is printed: MSG: Out of stock The credit is unchanged, and the loop begins again immediately. (For example, if the credit was also insufficient for that item, no message is printed to that effect.) – If the stock of the requested item is positive, but the current credit is NOT sufficient to purchase that snack, then the following line is printed: MSG: Insufficient credit The credit is unchanged. • restock - add to the inventory of one snack. This command never appears on a line by itself, and is always followed by a space and then two integers separated by spaces. The first integer is the 0-based index of a snack, and the second is the number of additional items loaded. The effect of this command is to immediately increase the inventory of that snack. The current credit is not changed. For example, restock 3 18 means that the inventory of snack 3 should be increased by 18. • return - a request to return all currently-deposited credit. The credit should be returned to the user in the same way that change is returned after a successful purchase (see Section 3.5 for detailed rules). • exit - exit the program. 3.5. Coin return rules. The specifications above include two situations in which coins need to be dispensed to the user: • After a purchase, to give change • In response to the return command, to return the current credit In each case, simulated coins are dispensed by printing lines such as RETURN: quarter RETURN: dime RETURN: nickel each of which corresponds to a single coin. The sequence of coin return lines must begin with quarters, followed by dimes, and lastly nickels. Change must be given using the largest coins possible, so for example it is never permissible to give two or more dimes and one or more nickel, because the same change could be made with the number of quarters increased by one. For the purposes of this assignment, the machine never runs out of coins. The following “greedy” approach will dispense coins meeting these requirements: (1) Dispense quarters until the remaining amount to return is less than $0.25. (2) Dispense dimes until the remaining amount to return is less than $0.10. (3) Dispense nickels until the remaining amount to return is zero. Note that unlike most real-world vending machines, these rules mean that the return command may give back a different set of coins than the user deposited. For example, after depositing five nickels, the return command would return a single quarter. 3.6. Efficiency. Your program must be able to complete 50 commands in less than 30 seconds, not counting the time a user takes to enter the commands. This is an extraordinarily generous time budget, as a typical solution will take at most 0.01 seconds to complete 50 commands. It is almost certain that you will not need to pay attention to the speed of any operation in your program. However, if you perform tens of millions of unnecessary calculations in the command loop, or do something else unusual that makes your program slow to respond to commands, then the autograder will run out of time in testing your program. In this case you will not receive credit.
In: Computer Science
FoodBox is an online business that serves many customers by allowing them to order food for delivery from local restaurants. The company has a web portal that has a listing of local restaurants for a zip code. The restaurants will be able to register with the portal and list their menus for an annual subscription fee of $190 or a monthly subscription fee of $25. Drivers, who are willing to pick up food from restaurants and deliver to customers will be able to register with the portal for an annual subscription fee of $95 or a monthly subscription fee of $15. Customers will be able to search for restaurants based on the zip code and view a list of all restaurants registered with FoodBox around that area. They will be able to view the menu for a particular restaurant and place an order. The payment is complete when the order is placed. Once an order is placed, the restaurant can either accept or reject the order. If an order is rejected, the customer must be refunded for the payment made. If an order is accepted by the restaurant, the restaurant provides an estimated time in the portal when the order will be ready for pickup. The application searches for drivers who are near the restaurant and available to deliver the food and notifies the selected driver to drive to the restaurant at the time when the order is expected to be ready for pickup. The driver is also provided with the address of the customer to whom the delivery needs to be made. The portal also provides a way for users to register for an account with the system, track their orders, view their order history and process a payment using credit card, paypal or zelle.
Assume the following Use Case Description:
Use Case Name: |
Create Order |
Primary Actor(s): |
Customer |
Brief Description: |
This use case describes how an order will be created using the system. |
Trigger: |
Customer accesses the portal and creates and order. |
Precondition: |
None |
Normal flow of events: |
|
Alternate/Exception flow: |
|
In: Computer Science
There are two algorithms:
–Algorithm A requires 5*n2 time units to solve a problem of size n.
–Algorithm B requires 7*n time units to solve a problem of size n.
Draw a chart (graph) to show the performance of the programs.
In: Computer Science
Could I please get explainations and working out as to how to get to the answers.
Note that is where part of the answer goes.
1.
Write a statement that removes the first occurrence of item 10 (if any) from an ArrayList of Integer objects, data.
data.remove( );
2.
Complete the following function that returns true if ArrayList list contains any positive (more than 0) item, false otherwise.
public static containsPositive(ArrayList list) {
for(int i=0; i < list.size(); i++) {
if( ) {
; }
} ; }
3.
Consider the following list:
ArrayList list = new ArrayList(Arrays.asList(10, 70, 20, 90, 30, 80, 50, 40, 60));
Complete the following code that gives the following output:
20 90 30 80 50 40 60
<interger> iter = list.listIterator( );
while(iter. ) {
System.out.println( +" ");
}
In: Computer Science
Purpose: To write an application using the list data structure that sorts objects in ascending order.
Details:
Create a class called Rectangle containing the following:
Create a second class called RectangleTest that contains the main method, and thoroughly tests the Rectangle class’s methods. This test class does not need to ask users for input. Just create the needed Rectangle objects to ensure that you test the Rectangle class’s methods well. The thoroughness of your testing is important.
***Throw an IllegalArgumentException indicating there is a problem with the input parameters in the constructor and the set methods.Also, rewrite the RectangleTest class from Chapter 8 to handle the exceptions thrown by the Rectangle class. Thoroughly tests the Rectangle class’s methods. This test class does not need to ask users for input. Just create the needed Rectangle objects to ensure that you test the Rectangle class’s methods well. The thoroughness of your testing in will impact your grade.***8
Then---create a second class called RectangleComparator that implements the Comparator interface to compares two Rectangle objects according to area.
Create a third class called RectangleSortTest that contains the main method. The method should create a List containing five Rectangle objects, not in order by area. The method should print the list, displaying each rectangle’s area. Then sort the list, and print the list again showing the list has been sorted by area. This test class does not need to ask users for input, nor does it need to do any additional error checking.
In: Computer Science
Q1) Create a program that do the following:
1. Asks the user to enter n marks for n students, read the marks and the names and store them in a double linked list.
2. Write a method to find the largest mark and print the name of the student having that mark
3. Write a method to print the content of the list (name, mark)
4. Write a method to search the list for a given mark and prints the result
6. Insert 2 new students to the list (print the list before and after the insertion)
7. Delete any students with the first letter "D" in his name, (print the list before and after the deletion)
Submit .java files only.
In: Computer Science
3) Based on your own experience and reading, identify and briefly discuss an example of an organization that has invested greatly in IT and yet has relatively little to show as a result. Identify and briefly discuss an organization where the opposite is true. To what do you attribute the difference?
6) What is meant by management expectations, and how can they affect the acceptance of new IT?
In: Computer Science
Could I please get explainations and working out as to how to get to the answers.
Note that is where part of the answer goes.
1.
Complete the following function that returns true if ArrayLists
list1 and list2 are exactly the same in terms of contents
(same items in same order), false otherwise.
public static sameSame(ArrayList<Integer> list1,
ArrayList<Integer> list2) {
if(list1 == null || list2 == null)
return false;
if( != )
return false;
for(int i=0; i < list1.size(); i++) {
if( .equals( )==false) {
return ;
}
}
return ;
}
2.
Complete the missing statements so that the output of the
following code is:
[[10, 70, 20, 90], null, [50, 80]]
Do NOT include spaces in your answer!
ArrayList<Integer> b = new
ArrayList<Integer>(Arrays.asList(10,888,20,90));
ArrayList<Integer> a = null;
ArrayList<Integer> c = ; //make a reference copy
only!
b.set(1, 70);
b = new ArrayList<Integer>(Arrays.asList(50, 80));
ArrayList< > list = new ArrayList< >();
list.add( );
list.add( );
list.add( );
System.out.println(list);
In: Computer Science
Write a program which compresses a given string of 1s and 0s and uncompress the string that was compressed. Use the run-length compression technique which replaces runs of 0s with a count of how many 0s.
The interactive input/output should allow users to select and run required processes.
The assignment submission on Blackboard should be as CIS_232_Project_LastName.zip file and include:
project report file: ProjectReportLastName.doc
program’s source file: ProjectLastName.java
program’s bytecode file: ProjectLastName.class
and any other relevant files.
The project report should be prepared by using word processing software. To write a program you should complete and include in your assignment report the following steps:
Title:
Student’s name:
CIS 232 Introduction to Programming
Programming Project
Due Date: November 30, 2020
Instructor Dr. Lomako:
In: Computer Science
For a C program hangman game:
Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do)
setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and puts that into g->hidden_word. It sets the number of wrong guesses to zero, and initialises the guesses array to be empty (all zeroes). To select a random word, just pick a random number between 0 and numwords-1, and copy that element of wordlist into the hidden word part of the structure.
// Data that is in g (Game)
// g->wrong_guesses
// g->guesses
// g->hidden_word
int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords )
{
g->wrong_guesses = 0 ;
// next, have to set what the hidden_word is
// pick a random number between 0 and numwords-1
// now copy that index of the wordlist into hidden_word
// next, initialise the entire guesses array to be all 0s
// DONE
}
The exist code
/* Hangman game!
Author: 1305ENG students
Date: 13/7/2020
A simple hangman game
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <math.h>
// include all OUR function declarations and constants
#include "hangman.h"
// The main function!
int main( int argc, char **argv )
{
char wordfile[256], option, temp[256] ;
char wordlist[MAX_WORDS][MAX_WORD_LENGTH] ;
int num_words, result ;
Game g ;
// seed the rand() function first
srand ( time(NULL));
// check to see if command line argument was given, if
so use it as the filename for the words
if ( argc > 1 ){
strcpy ( wordfile, argv[1] ) ;
} else {
strcpy ( wordfile, "wordlist.txt" ) ;
}
// now read word file
num_words = read_words ( wordfile, wordlist ) ;
if ( num_words == 0 ){
printf ( "No words were read from file, exiting\n") ;
exit ( -1 ) ;
}
printf ( "Read %d words from file\n", num_words ) ;
setup_game ( &g, wordlist, num_words ) ;
result = play_game ( &g ) ;
printf ( "Would you like to play again (y/n)? " ) ;
fgets ( temp, 256, stdin ) ; // read the rest of the line to get
rid of it from stdin
while ( option == 'y' || option == 'Y' ) ;
return 0 ;
}
// Functions used in the program here!
// WEEK 1 FUNCTIONS
// Replace the call to the library function with your own
code
// draw_man()
// Draws the hangman picture for the specified wrong number of
moves.
// There is no need to exactly copy the example program, but it
should progress from almost nothing
// at zero wrong moves to the man being "hanged" at
MAX_WRONG_GUESSES
int draw_man ( int misses ){
return draw_man_lib(int misses);
}
// display_guesses
// Displays a representation of the guessed letters from the
guesses array.
// Each letter is displayed in all caps, separated by a space. If
the array is '1', that letter is display,
// otherwise if it is '0' it is not. For example if elements 0, 9,
and 19 are '1' and the others are 0, then
// "A J T" would be displayed. No newline should be displayed after
the list of letters.
int display_guesses( unsigned char guesses[])
{
printf("Guesses so far:");
for(int i=0;i<26;i++)
{
if(guesses[i]==1)//checking the array of guesses if the its there
or not
{
printf("%c",i+65);
}
printf("\t");
}
return 0;
}
// read_guess()
// Reads a guess from the user. Uses the guesses array to make sure
that the player has not
// already guessed that letter. If an invalid character is entered
or they have already guessed
// the letter, they are asked to continue guessing until they enter
a valid input.
// Returns the character that was read.
// Note that it is usually better to read an entire line of text
rather than a single character, and taking the first
// character of the line as the input. This way, the entire line is
removed from the input buffer and won't interfere
// with future input calls.
char read_guess(unsigned char guesses[])
{
return read_guess_lib(guesses);
}
//Week 2 Functions
// add_guess()
// Adds the given guess to the guesses array, making the relevant
entry 1. For exmpale, if guess is 'a' or 'A',
// element 0 of the guesses array is set to 1. If 'z' or 'Z' is
input, then element 25 is set to 1. Your function
// should check that the character is a valid letter and return -1
if it is not.
// Returns 0 if successful, or -1 if an invalid character is
entered.
int add_guess(char guess, unsigned char guesses[26])
{
if ((guess >= 'a' && guess <= 'z') || (guess >=
'A' && guess <= 'Z'))
{
if (guess >= 'a' && guess <= 'z')
{
guesses[guess - 'a'] = 1;
}
else
{
guesses[guess - 'A'] = 1;
}
return 0;
}
return -1;
}
// check_guess()
// Checks if the given character 'guess' is contained within the
string 'word'.
// Returns 1 if it is, 0 otherwise
int check_guess ( char word[], char guess )
{
int i;
while(word[i] != '\0')
{
if(guess == word[i])
return 1;
}
return 0;
}
// hidden_word()
// Creates the word that is displayed to the user, with all the
correctly guessed letters
// shown, and the rest displayed as underscores. Any non-letters
(punctuation, etc) are displayed.
// The function takes two strings as inputs. word[] is the word
that the player is trying to guess,
// and display_word[] is the output string to be displayed to the
player. The guesses array is a binary
// array of size 26 indicating whether each letter (a-z) has been
guessed yet or not.
// Returns 0 if successful, -1 otherwise.
int hidden_word ( char display_word[], char word[],
unsigned char guesses[])
{
return hidden_word_lib (display_word, word,
guesses);
}
// WEEK 3 FUNCTIONS
// read_words()
// takes a filename as input as well as the wordlist to
populate
// Reads from the give file and stores each word (line of text)
into a new row of the array.
// A maximum of MAX_WORDS is read, and the wordlist array should be
this big (at least).
// Each word read from the file should be a maximum of
MAX_wORD_LENGTH characters long.
// Returns the total number of words read. If the file cannot be
opened, 0 is returned.
int read_words ( char input[], char
wordlist[][MAX_WORD_LENGTH])
{
int count= 0;
FILE*fp = fopen(input, "r");
if(fp == NULL)
return 0;
char buf[MAX_WORD_LENGTH];
while (fscanf(fp, "%s", buf) != EOF && count <
MAX_WORDS)
{
strcpy(wordlist[count], buf);
count++;
}
fclose(fp);
return count;
}
// display_game()
// Displays the entire game to the screen. This includes the
picture of the hangman, the hidden word,
// and the guesses so far.
int display_game ( Game *g )
{
return display_game_lib (g);
}
// WEEK 4-5 FUNCTIONS
// check_win()
// Checks to see whether all letters in the word have been guessed
already.
// The hidden word and guesses inside the Game structure should be
used to check this
// Returns 1 if so, 0 otherwise
int check_win ( Game *g ){
return check_win_lib ( g ) ;
}
// setup_game()
// Initialises the given game structure by chooseing a random word
from the supplied wordlist.
// The number of words in the wordlist is also passed to the
function.
// As well as doing this, the number of incorrect guesses is set to
0, and the guesses array is
// initialised to be all zeros.
int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH],
int numwords ){
return setup_game_lib ( g, wordlist, numwords ) ;
}
// play_game()
// Runs one complete game of hangman with the supplied Game
structure.
// The usual hangman rules are followed - the player guesses
letters one at a time until either
// the entire word is guessed or the maximum number of incorrect
guesses MAX_WRONG_GUESSES is
// reached. If the player wins, 1 is returned, otherwise 0.
int play_game ( Game *g ){
return play_game_lib ( g );
}
In: Computer Science
Image Processing
1. Let rk be the GL given in the table, perform histogram
equalization by.
i) Calculate sk from the table.
ii) Plot the probability density functions pr(rk) and
ps(sk).
Using MATLAB, plot the new histogram after performing the histogram equalization.
Please explain with steps. This would be much appreciated!
In: Computer Science
I am trying to create a basic shell program in C that runs 10 commands and then quits. Only one word commands are required, like:
cal, date, ls, ps, pwd, who, quit
The part I am struggling with is passing the scanned command into my array in the child process to be executed using execvp().
Here is my code:
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<readline/readline.h>
#include<readline/history.h>
#define MAX_CMD_NUMBER 10
int main()
{
int i;
char command[10];
for (i=0; i< 10; i++)
{
printf("COMMAND-> ");
fflush(stdout);
scanf("%s", command); // takes in
the user's single-string command
if (strcmp(command, "quit") ==
0)
i =
MAX_CMD_NUMBER; // terminate the loop
else
printf("Command
#%d is: %s\n", i, command);
}
printf("hello world (pid:%d)\n", (int) getpid());
int rc = fork();
if (rc < 0) {
// fork failed;
exit
fprintf(stderr, "fork
failed\n");
exit(1);
}
else if (rc == 0)
{
char *command[2];
command[0] =
strdup(command);
command[1] =
NULL;
execvp(command[0],
command);
printf("this shouldn't
print out");
}
else
{
command =
wait(NULL);
}
return 0;
}
In: Computer Science
1. (a) Discuss the issues of Relational Database Scaling
(b) Briefly, discuss different types of NoSQL databases
In: Computer Science
Write a program to swap the first and last elements of a linked list.
(i) by exchanging info part
(ii) through pointers
Need the program in java with no direct usage of packages use node and link.
In: Computer Science
select one of the below process synchronization problem and describe the problem and its solution
1) producer - consumer problem
2) the dining - philosophers problem
3) reader - writer problem
4) sleeping barber problem
In: Computer Science