CSAlpha Assign4: To-Do List App

Notice: Assignments are currently being rewritten for CSAlpha. This assignment was created for an old version of the curriculum and may no longer align with the current curriculum.

If you have any questions regarding the assignment or see any errors in the assignment writeup, please let me know.

Create a text file called assign4.txt. You will be using this to respond to questions in the assignment writeup and paste your code.

Classes

There are many types of cars. However, all these types of cars have some common characteristics: they have four wheels, we can drive them, and though their colors might be different, they all have a color scheme. Without these common characteristics, we can't tell the difference between a car and another object. These traits are imperative for the ability to classify a particular object and declare what type of object it is.

A class is essentially just that; it is a declaration of type. Particularly, it is the declaration of type through defining the shared attributes of objects with that type. Below is the beginning of the definition of a class named Car:

We create the Car class so that if we happen to create multiple cars in our program, we already have the blueprint to make that object. We don't want to keep redeclaring the shared characteristics of cars every time we want to make one; since we already know that these are common attributes, we can declare them once and reuse them by using the same Car class.

Java is an Object Oriented Programming Language. It emphasizes the use of classes and objects to encourage reusable, modular code. When you program a class with OOP in mind, you hide away all the implementation details of an object and use it a higher level. For example, a person uses a car to drive, but isn't worried about how the car works internally. This concept is known as abstraction, and we'll learn more of these OOP concepts as we move along in the course.

Returning to our Car class, we have to include what's called a constructor. This is the function that is called every time we want to make a new Car. Its syntax is defined below:

Now, as said above, we need to declare some common characteristics that all cars have. We can do this by declaring properties local to the class, like below:

Note that we haven't said anything about what the values of the properties actually are. Referring back to our color example earlier, the color for different cars is different. But since cars all have color, we include it as a local property to say that cars have color, but they don't all have the same color.

Because of this, we might want to define color and maxSpeed when we create a car. Where can we do this? Hint: look at the orange comment.

The constructor! When we create the object, we want to pass in the color and maxSpeed, so we'll have to add parameters to the constructor. Then, inside the constructor, we want to pass in the parameters to the local properties that belong to the Car:

The reason we use the keyword this is because our parameters have the same name as our class local properties. Thus, we need to have a way to refer to the properties that belong to the class and not the parameters of the constructor, which is exactly what this does.

Finally, objects have uses and actions. A car is meant to be driven; let's add a drive() method for our Car class. I'll also add a speed local property to keep track of how fast the car is going:

What speed do newly created cars start out at? Can you explain what the drive() function does in plain English? Put your answers into your assign4.txt.

Objects

Objects are the things that are created from the blueprints of classes. With our class above, we can create a Car object by calling to the constructor we made. To access the car's local properties and methods, we use the dot operator. Take a look at the example below:

What is the output of the above program? Write your answer in assign4.txt.

We can also create multiple cars that have all their own, separate properties:

How useful!

Core Assignment: To-Do List App

Someone has hired you to create a to-do list Java app for them. In terms of OOP, you already know what you'll begin with: a class that will be the blueprint for each task object in the to-do list. You'll call the class Task.

Upon telling the client this, they tell you that they'll send the implementation details for what a Task should be able to do. A week later, they send an email with all the implementation details, listed below:

Once you are done with the job, test out to see if it works in the Main class. Then please paste it in assign4.txt.

-Client

Assignment Extension

After you've created the Task class, you are not quite sure the client will be satisfied with testing happening in the Main class exclusively. So you've decided to design a testing harness that doesn't require any coding to use. To the console!

Your objective with this testing harness is to design an interactive prompt in the console that creates and interacts with a Task based on user input. Here's an example of what this would look like:

The shell prompt character (>) indicates user input, but you are not required to include it in the test harness. The test harness should run until the command end.

Here is a list of all the commands you are required to implement:

Paste your work in assign4.txt.