“
Artificial Intelligence (AI) is a branch of computer science dealing with the simulation of intelligent behavior in computers, or the capability of a machine to imitate intelligent human behavior.
Artifical Intelligence (AI) is a topic that is being talked about a lot lately, because people feel that it really will change every aspect of our lives - from health care, to traffic lights, to teaching assistants. Isn’t that cool? Computer science is changing every aspect of our lives!
When you consider the programs you’ve written so far (programs that have calculated areas, volumes and taxes) you might ask yourself: Are these examples of AI?
The answer is: sort of.
While not everyone agrees on what exactly constitutes AI, in it’s simplest form, a machine performing calculations is AI. What everyone does agree on is that there are “levels” of AI, or an AI continuum, where some technologies are more “AI-ish” than others, or where some technologies include more sophisticated, complex and advanced AI systems.
Did You Know?
Did you know that the ghosts in the famous game Pac-Man all have their own “personalities?” Not only do they pursue Pac-Man throughout the game, but they were each programmed to chase him using different patterns of behaviour.
Toru Iwatani, Pac-Man creator, said that this "is the heart of the game. I wanted each ghostly enemy to have a specific character and its own particular movements, so they weren’t all just chasing after Pac Man in single file, which would have been tiresome and flat."
You can read more about the Pac-Man ghost personalities, and about other components of the game’s AI.
In this activity, you are going to add a bit more AI to your programs by learning concepts that will allow your programs to “make decisions.”
Machine learning is considered a little more complex than AI.
While AI includes a lot of behaviour that has been programmed by the programmer, machine learning involves the program eventually deciding upon it's own behaviour.
“
“Machine learning is an application of artificial intelligence (AI) that provides systems the ability to automatically learn and improve from experience without being explicitly programmed. Machine learning focuses on the development of computer programs that can access data and use it to learn for themselves.”
Learning After High School
Many leading computer science departments have researchers dedicated specifically to the area of AI:
MIT even offers a free “Introduction to AI” course that anyone can take. You don’t even have to be registered at MIT or at any other University. The course includes lectures, assignments, quizzes and exams. Here is an example of an assignment.
Your task is to consider your experience with AI and to share with your friends and family.
Consider at least three of the following questions:
Take a look at the following program. Can you figure out
After considering for a few minutes, rollover the indicated spots to find out.
The program above uses what is called an “If… then.. else…” statement in order to make a decision. The decision is made based on the value of the variable age.
Line 19 will be executed if age is greater than or equal to 16.
Line 23 will be executed if age is not greater than or equal to 16.
In order to make this decision a comparison was made. The value of the variable age was compared to the number 16. This was done using what’s called a comparison operator.
Comparison Operators allow the program to compare two or more pieces of information. The following are the main comparison operators used in computer programming:
|
|
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Before you start to write code that includes selection, let’s make sure you can read through some programs that include it, and see if you can make predictions about what might happen.
In the driver’s license example above, there was really only one decision, and therefore only two potential actions, involved in the program.
The person’s age was either >= 16, or it wasn’t. That’s why the program used an “if…. then… else…” statement.
In some programs, however, you might want to have more than one decision and more than one action involved. If this is the case, then it’s smart to use what is called an “if… then… else if…” statement.
Take a look at the program below. Can you figure out the purpose of each line of code?
In the marks program above, there is only one selection statement. Although the statement contains several else ifs, there is still only one of these that will be true. This means that the programmer has written five possible output statements, but only one will be executed.
Also, it’s important to note that as soon as one of the statements evaluates to true, the program then jumps to the end of the overall selection statement (line 35). Therefore, if more than one of these conditions evaluates to true, it will only execute the first one that evaluates to true, and then skip the rest.
The order of the statements is also very important. If the programmer had started with if (mark >= 50)
{
System.out.println("You received a D.");
}
Then even a mark of 87.4% would have resulted in this being true and the user would receive the message “You received a D.”:
A store is offering a certain percentage off all purchases, depending on the amount spent:
Create a program that asks the user to enter the amount that was spent, and then output
You can create this program simply using the console for input and output.
The following are screenshots showing the output based on a variety of amounts spent:
Your program should include the following:
Note: For now you can output $11.80 as $11.8. Later you will learn how to force Java to output this number to 2 decimal places.
Boolean operators are used when programming slightly more complicated decisions that involve more than one thing being true or false at a time.
The two main Boolean logical operators that you will use are OR and AND.
Let’s take a look at some examples:
Imagine that in order to drive a person had to be at least 16 years of age and own a dog. This would be a ridiculous idea, but let’s go with it…
You could write a Java if statement that uses the AND Boolean logical operator. It would resemble the following:
if ((age >=16) && (ownsDog == true))
{
System.out.println (“You can obtain your license!”);
}
Notice that in the above code, age >= 16 AND ownsDog == true both have to be true in order for the statement to be output.
Imagine that in order to pass this course you could either obtain a mark of at least 50% or buy your teacher an awesome birthday present. (Note that this would be highly unethical on both your parts, by the way.)
You could write a Java if statement that uses the OR Boolean logical operator. It would resemble the following:
if (mark >= 50) || (bdayPresent == true))
{
System.out.println (“Yes, you pass!”);
}
Notice that in the above code, only one of marks >= 50 OR bdayPresent == true has to be true in order for the statement to be output to the screen.
Here is a slightly more complex (but more realistic) example that highlights how Boolean logical operators can be used:
In basketball, it is said that a player has obtained a “triple double” if he or she has achieved double digits in three statistical categories: points, assists and rebounds (it is possible to obtain a triple double by obtaining double digits in another category, like steals or blocks, but this is very rare).
A player can obtain a double-double by achieving double digits in two statistical categories.
The program below prompts the user for the points, rebounds and assists obtained in a game. It then uses Boolean and comparison operators to generate an accurate output statement based on the statistics.
Take a few minutes to read through the code. Pay close attention to the logic involved, and notice how Boolean operators, comparison operators, and brackets were used to ensure that the program made the correct decisions.
As your programs begin to get more and more complex, it’s important for you to spend time planning and organizing programs. If you don’t do this, then programming will take a lot longer, it will be a lot more difficult, and you may end up with very disorganized programs. It will also be very hard to explain your ideas and programs to other people.
One way programmers design and organize programs is by creating a flowchart.
“
A flowchart is a visual representation of the sequence of steps and decisions needed to perform a process. Each step in the sequence is noted within a diagram shape. Steps are linked by connecting lines and directional arrows. This allows anyone to view the flowchart and logically follow the process from beginning to end…. With proper design and construction, it communicates the steps in a process very effectively and efficiently.
Notice the different shapes in the above flowchart. These are important. Each shape represents a different component of the program.
Now let’s look at the marks program again and the flowchart following it:
For this course, you have a number of options for how you would like to create your flowcharts. You can draw them by hand, take a picture, and then submit them that way. Or, you can use digital tools to create your flowchart. Many word processing software packages allow you to create flowcharts quite easily by inserting the symbols to a document. You can also try flowchart creation software that is available online, such as:
Putrid Pizza is a pizzeria that only makes one type of pizza with the following toppings: extra, extra anchovies and extra, extra olives.
Customers aren’t allowed to order any other type of pizza, but they are allowed to select the size (by indicating the diameter).
Your task is to prompt the user for the diameter of pizza he or she would like to purchase, and then calculate the subtotal, the taxes, and the grand total.
Your program should also output a message based on the following:
The following lists the charges for a pizza at Putrid Pizza:
You will submit your completed program, as well as a flowchart that outlines the start, end, processes, input/output and decisions involved in the program.
Your program should include
The following is a screen capture of a sample GUI created for this program: