Write a C program to control an autonomous robot. It runs on two wheels, each wheel connected to a DC motor. If both wheels run at the same speed, robot moves forward. If the right wheel runs slower, robot makes a right turn. There are two sensors mounted on the robot that can detect an obstacle, one in the front, one on the right.
Once the robot is turned on, it moves forward at 80% of the maximum possible speed. When an obstacle is detected in front, if there is nothing blocking on the right side; it slows down to 40% of maximum speed and then it makes a right turn. Unless there is an obstacle on the right side too, then the robot will stop.
You must use PWM to control the wheels. The sensor outputs are digital, the mbed board will detect low when no obstacle and will detect high, when there is an obstacle. This is pin connections for this robot.
Device LPC1768 mbed pin
Right wheel pin 21
Left wheel pin 22
Front sensor pin 10
Right sensor pin 11
Use a flowchart to show the algorithm of your program.
In: Computer Science
1. Starting with an empty tree, show each step in the construction of an AVL tree using the following input in the order given. For full credit, you must show the tree after each new input is added. 16, 7, 14, 18, 6, 17, 2, 5, 13, 22, 4 (6 pts.)
2. Show how the AVL tree in previous changes with the following operations. For full credit, you must show the tree after each iteration.
Remove: 17
Remove: 18
Remove: 22
In: Computer Science
One of your chapters this week is on recursion. Below are the three recursive algorithms laws:
1. A recursive algorithm must have a base case.
2. A recursive algorithm must change its state and move toward the base case.
3. A recursive algorithm must call itself, recursively.
Do you have any examples of recursive algorithms used in the real-world?
Approximately 175 words in the answer.
In: Computer Science
ERD Lucid chart with Crow's foot notation for the following. include all entities, attributes, and correct carnality in relationships between entities. primary and foreign keys.
You have been asked to build a database for a sportswear company called Ath Fleet.
The company owner needs to keep track of the customers that buy their products, the employees that work at Ath Fleet, the vendors that provide them with products, and the products themselves.
Each vendor has contact with one employee representative and needs this support.
Employees in their first year usually don't have vendors to support, as they are learning the ropes, but as they work there longer and more vendors are reached, they may be assigned their only vendor.
The owner wants to track employee names and email addresses, as well as vendor names and locations.Vendors provide products to Ath Fleet, like shoes, apparel, and equipment.
Each product they sell comes from only one vendor. Some products are made in house, but if a vendor is in the system they must have provided a product.
The owner wants to track product names and each product's unique SKU.
Finally, customers purchase products from Ath Fleet and that transaction data needs to be recorded. Each product is often purchased by lots of customers, especially if it is popular.
Customers are only put in the system if they have made a purchase, but a product does not need to have been purchased to be stored.
The owner wants to keep track of customer names and email addresses.
In: Computer Science
CompSci 251: Intermediate Computer ProgrammingLab 3 – 2019
Introduction
This lab will focus on creating a Movie class conforming to the diagram above. From this class Movie objects can be instantiated and used in a running program. I have provided a mostly completely driver, you will need to add a few lines of code where specified.
What you need to do
Declare you instance variables at the top of the class.
Write a specifying constructor. No default constructor is required.
Write getName and setName. There are no restrictions on the setting the name.
Write getMinutes and setMinutes. When setting minutes, it is not allowed to be negative.
Write getTomatoScore and setTomatoScore. When setting tomato score, score is not allowed
to be negative or over 100.
Write isFresh. A score is considered fresh if it is 60 or above. It is rotten otherwise.
Write display. Print out the name, the total minutes, and if the movie is “Fresh” or “Rotten”.
Remember, you have method which tells you this now.
The driver is mostly complete. I placed one TODO, add a new movie of your choice to the array
that stores movies (called myCollection) in the driver.
Your output should match the output below plus the one movie you add to it. Pay attention to how objects are accessed in the driver. See your TA when your output is correct.
Output:
Here are all the movies in my collection of movies.
Movie: Batman The Dark Knight Length: 2hrs 32min.
Tomato Meter: Fresh
Movie: Avengers: Endgame Length: 3hrs 2min. Tomato Meter: Fresh
Movie: The GodFather Length: 2hrs 58min. Tomato Meter: Fresh
Movie: Suicide Squad Length: 2hrs 17min. Tomato Meter: Rotten
//The movie you add will print out here.
_______________________________________________ Here are the Fresh movies.
Batman The Dark Knight is fresh. Avengers: Endgame is
fresh.
The GodFather is fresh.
Here are the Rotten movies. Suicide Squad is rotten.
//The movie you add will print out here, it’s score will determine if fresh or not.
_______________________________________________
The movie Harry Potter and the Prisoner of Azkaban was created.
Is Harry Potter and the Prisoner of Azkaban a long movie? Yes, it is a bit long.
Can I set the minutes of Harry Potter and the Prisoner of
Azkaban to a negative number?
It did NOT work. Negative runtimes are not allowed.
Can I set tomato score of Harry Potter and the Prisoner of
Azkaban to a negative number?
It did NOT work. Negative scores are not allowed.
Can I set tomato score of Harry Potter and the Prisoner of
Azkaban to a number greater than 100?
It did NOT work. Still the best Harry Potter movie out all the
movies though.
Given Driver
public class MovieDriver {
public static void main (String [] args){
Movie[] myCollection = new Movie[5];
myCollection[0] = new Movie("Batman The Dark Knight", 152, 94);
myCollection[1] = new Movie("Avengers: Endgame", 182, 94);
myCollection[2] = new Movie("The GodFather", 178, 98);
myCollection[3] = new Movie("Suicide Squad", 137, 27);
//TODO
//Initialize the variable below and add it to myCollection at index 4.
//You can pick any movie you wish.
Movie yourMovie;
System.out.println("Here are all the movies in my collection of movies.\n");
for(int i = 0; i < myCollection.length; i++) {
if(myCollection[i] != null) {
myCollection[i].display();
System.out.println();
}
}
System.out.println("_______________________________________________");
System.out.println("\nHere are the Fresh movies.\n");
for(int i = 0; i < myCollection.length; i++) {
if(myCollection[i] != null && myCollection[i].isFresh()) {
System.out.println(myCollection[i].getName() + " is fresh.");
}
}
System.out.println();
System.out.println("Here are the Rotten movies.\n");
for(Movie movieTmp: myCollection){
if (movieTmp != null && !movieTmp.isFresh())
System.out.println(movieTmp.getName() + " is rotten.");
}
System.out.println("_______________________________________________\n");
Movie harryPotter = new Movie("Harry Potter and the Prisoner of Azkaban", 144, 91);
System.out.println("The movie " + harryPotter.getName() + " was created.\n");
System.out.println("Is " + harryPotter.getName() + " a long movie?");
if(harryPotter.getMinutes() > 120) {
System.out.println("Yes, it is a bit long.\n");
} else {
System.out.println("Nope, that isn't too bad.\n");
}
System.out.println("Can I set the minutes of " + harryPotter.getName() + " to a negative number?");
harryPotter.setMinutes(-5);
if(harryPotter.getMinutes() == -5) {
System.out.println("It worked. The runtime is -5 minutes.\n");
} else {
System.out.println("It did NOT work. Negative runtimes are not allowed.\n");
}
System.out.println("Can I set tomato score of " + harryPotter.getName() + " to a negative number?");
harryPotter.setTomatoScore(-100);
if(harryPotter.getTomatoScore() == -100) {
System.out.println("It worked. The score is -100. This movie is terrible according to the site.\n");
} else {
System.out.println("It did NOT work. Negative scores are not allowed.\n");
}
System.out.println("Can I set tomato score of " + harryPotter.getName() + " to a number greater than 100?");
harryPotter.setTomatoScore(101);
if(harryPotter.getTomatoScore() == 101) {
System.out.println("It worked. The score is 101. Best Harry Potter movie ever!\n");
} else {
System.out.println("It did NOT work. Still the best Harry Potter movie out all the movies though.\n");
}
}
}
In: Computer Science
Can you please tell me if this code needs to be fixed, if it does can you please post the fixed code below please and thank you
/**
* Driver to demonstrate WholeLifePolicy class.
*
* @author Tina Comston
* @version Fall 2019
*/
public class WholeLifePolicyDriver
{
/**
* Creates WholeLifePolicy object, calls methods, displays
values.
*
*/
public static void main()
{
WholeLifePolicyDriver myDriver = new WholeLifePolicyDriver();
// create a policy
WholeLifePolicy policy = new WholeLifePolicy("WLP1234567",
50000, 20);
// display values
myDriver.displayPolicy(policy);
// now change some values
policy.setPolicyNum("WLP9871235");
policy.setFaceValue(75000);
policy.setPolicyYrs(15);
// display again
myDriver.displayPolicy(policy);
// Display termination value at 10 years, borrowed $25K
System.out.printf("Termination value @10 years 25K borrowed "
+
"is %.2f \n", policy.surrenderVal(10.0, 25000));
}
/**
* Displays data for a policy.
*
*/
private void displayPolicy(WholeLifePolicy wlp)
{
System.out.println("*******************************************");
System.out.println(wlp.toString());
System.out.println();
}
}
In: Computer Science
Can you please tell me if this code needs to be fixed, if it does can you please post the fixed code below please and thank you
/**
* Models a Whole Life Policy.
*
* @author Tina Comston
* @version Fall 2019
*/
public class WholeLifePolicy
{
// instance variables
private double faceValue;
// your code here - code the remaining instance field
// constants
/**
* surrender rate.
*/
public static final double SURRENDER_RATE = .65;
/**
* ADMIN FEE.
*/
public static final double ADMIN_FEE = .005;
// constructors and methods
/**
* Default constructor for objects of class WholeLifePolicy.
* This is the default constructor.
*
* Default values are:
* face value = 0.0
* policy years = 0
* policy number WLP9999999
*
*/
public WholeLifePolicy()
{
this.setPolicyNum("WLP9999999");
this.setFaceValue(0.0);
this.setPolicyYrs(0);
}
/**
* Explicit constructor for objects of class WholeLifePolicy.
*
* @param inPolicyNum Number of the policy
* @param inFaceValue Face Value of policy.
* @param inPolicyYrs Length of policy in years.
*
*/
public WholeLifePolicy(String inPolicyNum, double
inFaceValue,
int inPolicyYrs)
{
// your code here, complete the constructor
}
/**
* Copy constructor for objects of class WholeLifePolicy.
* This constructor creates an exact copy of a
* WholeLifePolicy object.
*
* @param inPolicyObject WholeLifePolicy object.
*
*/
public WholeLifePolicy(WholeLifePolicy inPolicyObject)
{
this.setPolicyNum(inPolicyObject.getPolicyNum());
// your code here, complete the constructor
}
/**
* Set the Policy Face Value.
*
* @param inFaceValue Face Value of policy.
*
*/
public void setFaceValue(double inFaceValue)
{
this.faceValue = faceValue;
}
/**
* Get the Policy Face Value.
*
* @return double Face Value of policy.
*
*/
public double getFaceValue()
{
return this.faceValue;
}
/**
* Set the Policy Years.
*
* @param inPolicyYrs Length of policy in years.
*
*/
public void setPolicyYrs(int inPolicyYrs)
{
// your code here, complete the method
}
/**
* Get the Policy Years.
*
* @return int Length of policy in years.
*
*/
public int getPolicyYrs()
{
// your code here, replace the following statement
return 9999;
}
/**
* Set the Policy Number. Use to override the default
* policy number or for copy object processing.
*
* @param inPolicyNum Policy Number.
*
*/
public void setPolicyNum(String inPolicyNum)
{
// your code here, complete the method
}
/**
* Get the Policy Number.
*
* @return String Policy Number.
*
*/
public String getPolicyNum()
{
// your code here, replace the following statement
return "incorrect value";
}
/**
* Calculate surrender value.
* Surrender value is calculated as:
* (surrender rate * face value) *
* (years held / policy years) - amount borrowed -
* (face value * administrative fee)
*
* @param inYrsHeld Length in years policy held to date.
* @param inBorAmt Amount borrowed against policy if any.
*
* @return double Policy surrender value.
*
*/
public double surrenderVal(double inYrsHeld, double inBorAmt)
{
// Termination value is the surrender rate percentage of the
face
// value as a proportion of the years held to policy years less
any
// amount borrowed on the policy less a ADMINFEE on the
// face value.
// your code here, compute the surrender value and replace
the
// following line
return 99999.99;
}
/**
* Return a string representation of the WholeLifePolicy.
*
* @return String output string.
*
* <pre>
* Produce output in the following format:
*
* Policy Information:
* Policy #: WLP1000000
* Policy Years: 20
* Face Value: 50000.0
*
* </pre>
*/
public String toString()
{
String output = "Policy Information:\n";
output = output + "Policy #: " + this.getPolicyNum() + "\n";
// your code here, finish the output string
return output;
}
}
In: Computer Science
The Fibonacci series of numbers is a favorite of mathematicians, and goes as follows: 1, 1, 2, 3, 5, 8, 13, 21, . . . That is, the first two numbers are 1, and every subsequent number is the sum of the previous two. The mathematical definition as a recursive function is the following.
∀n = 0, 1, 2, . . .
F(n) = { 1 if n <=1
F(n-1) + F(n-2) if n > 1
The closed form of such function is in O(φ n ), where φ is a number called the golden ratio.
1. Coding: Write a Java class Fibonacci that has the following static methods.
(a) (20 points) A recursive method that returns F(n).
(b) (20 points) A non-recursive method that returns F(n).
(c) (10 points) A main method to obtain from the user the index n, and call the methods above one after the other. For each of the method calls, measure and display the running time using the following snippet of code.
...
// store the time now
long startTime = System.nanoTime();
// your method call here
...
// display the time elapsed
System.out.println("t = " +
(System.nanoTime() - startTime) + " nanosecs.");
2. Experiments: (10 points) Measure running times for different values of n and fill a table like the following. (You may need to adjust n to smaller values if it takes too long or your stack overflows, 0 points if you do not have at least 5 columns of measurements.)
n | 0 | 1 | 2 | 4 | 6 | 8 | 16
recursive | | | | | | |
non-recursive | | | | | | |
3. Analysis: For your recursive method:
(a) (10 points) What is the worst-case big-O running time with respect to n? (Explain how you computed the running time, 0 points if you do not say what is the basic operation counted and what counting rules you used.)
(b) (10 points) Are your measurements consistent with this big-O running time? (Explain using your measurements, 0 points if you do not say something like "looking at row recursive, when n is doubled the running time is xxx".)
For your non-recursive method:
(c) (10 points) What is the worst-case big-O running time with respect to n? (Explain how you computed the running time, 0 points if you do not say what is the basic operation counted and what counting rules you used.)
(d) 10 points Are your measurements consistent with this big-O running time? (Explain using your measurements, 0 points if you do not say something like "looking at row non-recursive, when n is doubled the running time is xxx".)
In: Computer Science
Hello, trying to create a three way currency conversion on python. One of the things I want to do is create an error message whenever there is an incorrect currency entered. So far, I have managed to display the error message in these two cases: when both From and To currencies are incorrect, and when only the From currency is incorrect. What can I do so that my program can also display a message when the To currency is only incorrect.
money = float(input("Please enter the From amount to be
converted: "))
fromCurrency = input("Please enter the From currency (USD, EUR, or
JYP): ")
toCurrency = input("Please enter the To currency (USD, EUR, or
JYP): ")
## conversions taken as of 9/26/19
# 1 USD = .91 EUR (1.1 factor), 1 USD = 107.63 JYP (.00929 factor),
1 EUR = 117.81 JYP (.0084 factor)
usdEur = money / 1.1
eurUsd = money * 1.1
usdJyp = money / .00929
jypUsd = money * .00929
eurJyp = money / .00848
jypEur = money * .00848
# Conversion from USD to other currencies
if fromCurrency.lower() == ("usd"):
if toCurrency.lower() == ("eur"):
result = usdEur
if toCurrency.lower() == ("jyp"):
result = usdJyp
print(money, fromCurrency, "equals", result, toCurrency)
elif fromCurrency.lower() == ("eur"):
if toCurrency.lower() == ("usd"):
result = eurUsd
if toCurrency.lower() == ("jyp"):
result = eurJyp
print(money, fromCurrency, "equals", result, toCurrency)
elif fromCurrency.lower() == ("jyp"):
if toCurrency.lower() == ("usd"):
result = jypUsd
if toCurrency.lower() == ("eur"):
result = jypEur
print(money, fromCurrency, "equals", result, toCurrency)
else: #does not work when 'to' currency is wrong
print("Error! Currency not available for conversion")
In: Computer Science
In java. Using a linked list only, iterator and scanner.
Develop a program to maintain a Linked List of homework assignments name and due date. When an assignment is assigned, add it to the list, and when it is completed, remove it. You should keep track of the due date. Your program should provide the following services each contained within its own method:
In: Computer Science
For this lab, you will design classes to represent three simple geometric shapes: circles, rectangles, and triangles.
Implement the classes for these three shapes in Java, each in a separate class file, according to the guidelines given below:
The classes must include instance fields (also known as attributes or data members) for the information necessary to represent objects of these classes. Recall that the instance fields represent the properties of objects. The most fundamental property of a circle is its radius, so this would be an ideal candidate for an instance field. Likewise, rectangles have a length and width, and a triangle has a base and a height (we will assume that these are all isosceles triangles). These fields must all be floating-point values, so you should use double as the data type for these fields.
The classes should include constructors, which allow us to initialize new objects of these classes with sensible starting values. The constructors should allow us to set the values of every instance field in each class.
The classes should include accessors (also known as "getter methods") for all of the instance fields.
The classes should include a method to compute and return the area of each of the three types of shapes. The area() method does not need to accept an argument, since the object already "knows" (through the value(s) of its instance field(s)) all the information it needs to compute its own area.
The classes should also include a toString() method which returns the string representation of the object, in the form of its area surrounded by symbols which indicate the shape of the object. For example, printing each of the three types of shape objects to the screen should look like this (assume the area is 4 units for each of these shapes):
/ 4.0 \ (for triangles)
[ 4.0 ] (for rectangles)
( 4.0 ) (for circles)
Finally, write a main() method in a fourth class which does the following ...
Create at least two shape objects of each class, initialized to different sizes ...
Print a string representation of every shape object, and ...
Call the area() method of every shape object to
get its area, and then compute the total area of all
objects of the same kind (that is, the total area of all
rectangles, the total area of all circles, and the total area of
all triangles). It should then print these totals along with a
descriptive label; for example ...
Total Triangle Area = 8.0
(These shape objects can be declared as individual variables; later, we will see how to unify these objects into a collection under a common type.)
this is java language
In: Computer Science
Complete the project functions for this week. Note that you have two weeks to complete these functions, however you should aim to get most of them done this week so you can focus on your own additions to the project next week. These functions are setup_game(), play_game() and computer_move(). To complete these functions, first remove the library function call from the function in the template (save_game_lib, etc), then replace that with your own code to complete the function. You can test your functions separately from the project by creating a small main() function that calls them (with appropriate inputs), or you can compile the entire project and see if it works.
setup_game(): The setup_game function takes a Game pointer as input, and initialises this structure so that it is ready to play a new game. There are three main tasks that this function needs to achieve. Firstly, it needs to determine whether player 1 and player 2 are human or
computer players. To do this, a prompt should be displayed to the user and they can enter 'h' for human or 'c' for computer for both players. The results of this input should set the "player1" and "player2" fields of the game structure to either 0 for a computer player or 1 for a human player. Next, your function needs to initialise the board to be empty, by filling every square with zeros. Finally, the turn and winner fields of the structure should be set. winner should be set to 0 (since nobody has won yet), and turn should be a randomly chosen as either 1 or 2.
play_game(): This function performs all the actions necessary to play the game. Most of the functionality of the game has already been implemented by other functions, so the main task of the play_game functions is to call these in the correct way. It takes a pointer to a Game as input, and this structure is assumed to be already initialised to either a new game or a game in progress. The function needs to then run the game until either somebody has won, or the board is full (a draw). To do this, on each turn the game needs to display the board, then either (a) get a move from the keyboard for a human player, or (b) determine a computer move for a computer player, then add this move to the board. The turn and winner fields should then be updated to reflect the new state of the game. If a human player enters 's' or 'q' (as indicated by the return value of get_move) then the move isn't added and the turn field is not changed, but instead the game is saved or quit as appropriate. Your play_game function should use the existing functions (get_move, add_move, display_board, board_full, winner, save_game, etc) to perform all the relevant tasks. You can also use the wait_seconds() function to delay the game for a few seconds before the computer moves, in order to stop this happening instantly.
computer_move(): This function is the "artificial intelligence" of the game. It takes the current board array, the player whose turn it is, and the 'level' of the AI as input, and returns a column number (between 1 and COLS) in which the computer will play. This is very similar to the get_move() function, except that rather than asking the player for a move, one is generated by the AI. The 'level' variable determines how 'smart' the AI is. Level 0 should just generate a random column (that isn't full) and return that. Level 1 should look if the computer can win the game in any column, and if so choose that column. If not, a random valid non-full column is chosen. For level 2, the computer should also check if the opponent can win in any column, and choose that column to block them. Level 3 and above do not need to be implemented for this version, so the behaviour should be the same as level 2.
HINT: Create a copy of the board, so that you can 'test' each move in turn (using add_move and winner) to see if it wins, and choose that column if so. If not, you can reset the copy back to the original board and try again.
TEMPLATE FILE:
#include #include #include #include #include #include "connect4.h" int main ( void ){ int option ; Game g ; // intitialise random seed srand(time(NULL)); while (( option = main_menu()) != -1 ){ if ( option == 1 ){ // setup a new game setup_game ( &g ) ; // now play this game play_game ( &g ) ; } else if ( option == 2 ){ // attempt to load the game from the save file if ( load_game ( &g, "game.txt" ) == 0 ){ // if the load went well, resume this game play_game ( &g ) ; } else { printf ( "Loading game failed.\n") ; } } else if ( option == -1 ){ printf ( "Exiting game, goodbye!\n") ; } } }
// WEEK 4-5 TASKS
// setup_game()
// play_game()
// computer_move()
// calcualtes a column for the computer to move to, using
artificial "intelligence"
// The 'level' argument describes how good the computer is, with
higher numbers indicating better play
// 0 indicates very stupid (random) play, 1 is a bit smarter, 2
smarter still, etc..
int computer_move ( int board[COLS][ROWS], int colour, int level
){
// If level 0, this is a 'dumb' opponent, pick a random column that isn't full and return that
// If level 1, this is slightly smarter - if the computer's move can win the game, choose that column, otherwise random
// If level 2, slightly smarter again. If computer can win it will do that, otherwise it will block an opponent's winning move, otherwise random
// Higher levels are up to you!
// Hint - you can copy the board into a 'temporary' board and
trial putting a token in a column, then simply call the winner
function to see
// if that move has won the game. Doing this for the current player
will check if that player can win, doing it for the opponent will
see if the opponent can win next turn
// You can use "lookahead" logic to search for the 'best' move many moves ahead
return computer_move_lib ( board, colour, level ) ;
}
// sets up the game to a new state
// prompts the user if each player should be a human or computer,
and initialises the relevant fields
// of the game structure accordingly
int setup_game ( Game *g ){
// prompt the user to enter whether each player is a human or
computer (h or c)
// set the player1 and player2 fields of the struct accordingly (1
for human, 0 for computer)
// initialise the board to all zeros
// set winner to 0 ( no winner yet!)
// set turn to either 1 or 2 (randomly)
return setup_game_lib ( g ) ;
}
// Starts or resumes playing the Game g. Continues until the game
is over or the user quits.
int play_game ( Game *g ){
return play_game_lib ( g ) ;
}
#ifndef CONNECT4_H #define CONNECT4_H 1 #define ROWS 6 // height of the board #define COLS 7 // width of the board (values of 9 are going to display poorly!!) // These lines detect what sort of compiler you are using. This is used to handle the time delay // function wait() in various operating systems. Most OS will use sleep(), however for windows it is // Sleep() instead. #ifdef _WIN32 #include <windows.h> #else #include <unistd.h> #endif typedef struct { int player1, player2 ; // variables for each player - 1 for human, 0 for computer player int board[COLS][ROWS] ; // the game board. 0 for empty space, 1 for player 1, 2 for player 2 // Note that row 0 is the TOP row of the board, not the bottom! // column 0 is on the left of the board int turn ; // whose turn it is, 1 or 2 int winner ; // who has won - 0 for nobody, 1 for player 1, 2 for player 2 } Game ; // displays the welcome screen and main menu of the game, and prompts the user to enter an option until // a valid option is entered. // Returns 1 for new game, 2 for load game, -1 for quit int main_menu ( void ) ; // displays the board to the screen int display_board ( int[COLS][ROWS] ) ; // sets up the game to a new state // prompts the user if each player should be a human or computer, and initialises the relevant fields // of the game structure accordingly int setup_game ( Game *g ) ; // Returns TRUE if the specified column in the board is completely full // FALSE otherwise // col should be between 1 and COLS int column_full ( int[COLS][ROWS], int col ) ; // plays a game until it is over int play_game ( Game *g ) ; // prompts the user to enter a move, and checks that it is valid // for the supplied board and board size // Returns the column that the user has entered, once it is valid (1-COLS) // note that this value is betweeen 1 and COLS (7), NOT between 0 and 6!! // If the user enters 'S' or 's' the value -1 should be returned, indicating that the game should be saved // If the user enters 'Q' or 'q' the value -2 should be returned, indicating that the game should be abandoned int get_move ( int[COLS][ROWS] ) ; // calcualtes a column for the computer to move to, using artificial "intelligence" // The 'level' argument describes how good the computer is, with higher numbers indicating better play // 0 indicates very stupid (random) play, 1 is a bit smarter, 2 smarter still, etc.. int computer_move ( int[COLS][ROWS], int colour, int level ) ; // adds a token of the given value (1 or 2) to the board at the // given column (col between 1 and COLS inclusive) // Returns 0 if successful, -1 otherwise int add_move ( int b[COLS][ROWS], int col, int colour ) ; // determines who (if anybody) has won. Returns the player id of the // winner, otherwise 0 int winner ( int[COLS][ROWS] ) ; // determines if the board is completely full or not int board_full ( int[COLS][ROWS] ) ; // saves the game to the specified file. The file is text, with the following format // player1 player2 turn winner // board matrix, each row on a separate line // Example: // //1 0 1 0 player 1 human, player 2 computer, player 1's turn, nobody has won //0 0 0 0 0 0 0 board state - 1 for player 1's moves, 2 for player 2's moves, 0 for empty squares //0 0 0 0 0 0 0 //0 0 0 2 0 0 0 //0 0 0 2 0 0 0 //0 2 1 1 1 0 0 //0 2 2 1 1 2 1 int save_game ( Game g, char filename[] ) ; // loads a saved game into the supplied Game structure. Returns 0 if successfully loaded, -1 otherwise. int load_game ( Game *g, char filename[] ) ; // waits for s seconds - platform specific! THIS FUNCTION IS INCLUDED IN THE LIBRARY, NO NEED TO WRITE IT! void wait_seconds ( int s ) ; // library versions of functions. Exactly the same behaviour done by course staff. Please just call these if you have not completed your version as yet. int display_board_lib ( int[COLS][ROWS] ) ; int setup_game_lib ( Game *g ) ; int column_full_lib ( int[COLS][ROWS], int col ) ; int play_game_lib ( Game *g ) ; int get_move_lib ( int[COLS][ROWS] ) ; int add_move_lib ( int b[COLS][ROWS], int col, int colour ) ; int winner_lib ( int[COLS][ROWS] ) ; int board_full_lib ( int[COLS][ROWS] ) ; int computer_move_lib ( int[COLS][ROWS], int colour, int level ) ; int save_game_lib ( Game g, char filename[] ) ; int load_game_lib ( Game *g, char filename[] ) ; int main_menu_lib ( void ) ;
In: Computer Science
What would an example of java code look like?
Producer class
- Declaring toolsPerHour as an instance variable
- Creating constructor that takes toolsPerHour
- Creating getter for toolsPerHour
- Method for calculating days produced
Tester class
- Creating 3 producer objects using constructor
- Setting toolsPerHour
- Calling methods
- Displaying output
In: Computer Science
Provide a specific example of how each layer of the OSI model processes the movement of data in communicating from one entity to another. For example, discuss how email is processed for each layer of the model.
In: Computer Science
I need know how to Write a java program called character length that prompts the user to enter a string and displays:
The length of the string is: xxxxx
The strings first character is: x
(where xxxxx is the length of the string and x is the first character.)
In: Computer Science