Module 8 guides learners through the creation of an Android app that implements a simple calculator, which provides features for adding, subtracting, multiplying, and dividing numbers input by various means (e.g., via numbers and buttons on the Android user interface).
This performs a code walk-through.
The skeleton files you can find for the mini project assignment in Module 8.
the particular files and choosing that in Android Studio.
then go take a look at the project.
Click down to find the files, you're down here.
you have to fill in to perform your work.
We'll start first by looking at the logic interface.
the second argument passed in from the user interface, which we'll examine later.
As well as the operation that's been selected by the user.
And it goes ahead and performs the operation on those particular arguments.
So let's go take a look at the logic file.
You can see the logic class implements the logic interface.
Which means you have to come along and implement this process method.
That's where your code will go.
to interact with the activity from within this code.
stores it in this field that's part of the logic class.
So you can focus your solution purely on the Java portion.
take a look at the various files as we mentioned in the earlier video.
These are all empty files, you can see add which is a class.
divide which is a class, multiply which is a class, and subtract which is a class.
these different classes, and then connect them together with the Logic class.
figure out the appropriate design, figure out the appropriate implementation.
Using the various Java features that we've been talking about throughout this mooc.
on, in order to be able to implement this particular calculator logic.
For completeness, we'll also walk you through the user interface.
you don't actually have to write this code.
We provide it to you.
But it might be fun to see how it works.
We'll go over here and take a look at the main activity.
the operation to perform on these values as shown in the earlier video.
Main activity extends activity, and implements activity interface.
We'll come and look at activity interface in just a second.
take a look at some of the fields that are provided in the main activity class.
that you can use to choose what operation to use.
There's also a button that you can Press when you want to perform the computation.
value two which are edit text and that means you can add things to them.
that stores the results of the computation.
That's where the output is actually stored.
We also have a reference to the logic object.
with the logic class that we looked at before.
Then at you have to go and fill it.
It is also something that it's called an array adaptor.
characters sequence to make it usable by the map spinner.
And this we'll see later on when the program actually runs.
these are called lifecycle hook methods.
in the specialization where we talk about activities in more detail.
the Android platform, by the framework portion of the Android platform.
In order to initialize Your activity object.
Activities are the ways that you interact with the user.
It provide user facing operations.
calculator to get the input in the operation and then present the output.
just always done in android code.
We'll talk about that on the next move.
You don't have to worry about that here.
interface, and we'll come back and talk about what that means in a second.
that's now available to interact with the code that you write.
Here's the initialized UI method.
worry about understanding it, I'm just going through it now for completeness.
the other text field to present the output.
get a bunch of references to the various view objects.
the user interface interactors, components.
The button, the edit text fields.
which allows you to be able to select a drop down result, and, the result object.
Then we go ahead and create an adapter.
Which is going to be used to allow us to visualize the spinner.
we add, we make the default selection for the math spinner to be add.
you'll end up adding the two inputs that are given by the user.
it'll select The other operations to perform.
that will go ahead and get the operation number.
We'll take a look at how that works in a second.
it's specified by the user in the user interface.
And here then is the hook that connects with the code that you write.
hook method on the logic reference with ARC one, ARC two in the operation.
And that vectors you over here where this code is going to be run.
The code that you write there.
If you go down a little bit and take a look at some of these helper methods.
You see get value one and get value two.
converts that into an integer for value one and for value two.
So those are returned as ints.
operation as an operation number.
subtract is two, multiply is three, divide is four, and so on, and so forth.
Here, then, is the way in which we print the result to the user output.
that you'll end up needing to call from within your logic/process method.
you'll print the result, which just goes ahead and sets the text.
For the result to be the text string, the string that's passed in here.
So that's basically how the activity works.
Let's now go take a quick look at the activity interface.
at various values that the user provided.
we only really need to provide the print method.
the math activity that we defined here, which is all Android code.
this computation whereas that allows us to write the android activity over here.
We're doing that in this course for a couple of reasons.
know about android at this point.
we'll teach you more about how these things work.
the android operations, and the android platform, and the android framework.
tests we could use with our auto graders.
Here's a bit more of this again we'll cover again at the next class.
environment to dictate the way in which information is laid out on the screen.
rather the main layout for the set activity.
have the calculate button and then you've got the output edit text for the result.
So those are some of the things that you get here.
Here's what this actually looks like in the XML format.
And I'm not going to go through this in gory detail right now.
This is something that we'll cover again in the next mu.
and then we're going to have the input for this.
and we're going to use those names in the main program.
you can see we can go look those things up by their name.
editing the value of, to edit text.
when somebody clicks on this button, call back to the button press method.
And if you take a look over here, here is button pressed.
There's the button pressed method.
with this method that's defined In the Android activity.
that's just one way of doing it.
And next week we'll cover that in more detail.
here's how we define the results that'll be printed out.
you don't have to know about all of this stuff in order to do the assignment.
I'm just walking you through it because it's kind of fun.
Divide, Multiply, and Subtract files.
in the in which we evaluated, we wanted to let you guys be as creative as you'd like.
Contact us on the discussion forums if you have any questions what so ever.