Transcripts
1. Introduction to Beginner Java: Java, One of the most popular programming languages in the world. And for good reason, it is one of the general use programming languages that can be used to create applications and much more. However, black with learning any language, studying Java can be a difficult process. But it doesn't have to be. My name is Matthew doing. I've been teaching programming for over four years and I've written books on the subject of programming from learning the languages themselves, hard to make a Korea from programming. My approach to teaching is purely practical. The best way to teach programming is not through the memorizing of code, but the application of that code. Memorizing is the byproduct of that process. I'll show you code you can write out and test for yourself. In this course, I'll go through beginner Java code from data types and variables. Two, if statements and loops. Don't worry if this seems a bit confusing. Now, as by the end, you'll have a foundation understanding of all this code. If you're looking for a hands-on course to start your Java programming studies. This is the one for you. I look forward to seeing you in the first lesson. For now.
2. Downloading and Installing Eclipse: Hello and welcome to the very first video in your Java programming course. In this video, we are going to be downloading and installing the IDE for this course, which is environment for programming. This software allows us to write out code and tested as well, which is crucially important when writing and learning any programming language. For this course, we're going to use him one of the most popular Java IDEs, Eclipse. Eclipse has all that you need to write and test basic code. And to top it off. It comes with its own Community Edition, which means it's free and open source for all Java programmers. But before we can start using it, we need to download and solid from the website. So open up the browser of your choice, Internet Explorer, Firefox, or as I'm using Google Chrome and search Eclipse and top Eclipse IDE download. One searched, you should see the following as the top result at Eclipse.org. Simply click here. And it should take you to the downloads page. Once on the downloads page you should see the following. Yeah, you can download your Eclipse IDE. It's as simple as a single click. Once collected should take you to this page. It would download from the nearest port available. For me. It's available here in South Africa, University of Pre-State. Simply click Download. And you should see a downloading. And the bottom left corner of your screen, as you can see here, see you in a moment when the standard is complete and we can start the installation. Once the fast download, you should have it looking just like this. It can either be on your desktop or in your downloads folder. Once you have that located, where one more thing left to download and install before we begin the installation. Now transits are likely you don't have the proper Java files installed on your computer. And which case, you need to download them from a very particular sat known as Oracle. I will be providing you with a link to this particular sat. But the easy way to make sure that you get there is by simply double-clicking on this in-store file. Eclipse will recognize any job on your system and epitaphs Marat can't and needs to be updated. Or if you don't have it and it needs to be installed. It will tell you by simply opening up your browser of choice and telling you here, as you can see, unfortunately, the Java version needed to run the eclipse installer couldn't be fine on your system. It will then provide you with several links that you'll need to install, version that you need to use. It will then provide you with links to the front JDK files, which you need to install the right Java. Simply click on the highest link, which is Oracle, JDK 13 at might be higher for you depending on when you're watching us. But 1.5.0 is the latest version right now, SAR, simply click here, and it should take you to the oracle page where you can download the right child. Fun. Once you have clicked through to the oracle page, you should be presented with the following. Now, before you can download this file, you will need to create an Oracle Account. And once you have created your Oracle Account, simply scroll down the page to the download section here. Here you'll choose the installer that matches the OS that you're using. For example, if you're using an Apple computer, you'd use a Mac OS installer over here and simply click on this link. For me, I'm using Windows, so I'll be clicking on this link here. Once you've clicked on the link, simply click, I've reviewed and accept the terms of conditions Oracle's provided, and click on the download link here. After signing in, you should see the download and the bottom left corner of your screen. Once the download is complete, we'll execute the installation. And once that job is installed, we'll install eclipse next. So I'll see you then when that's complete. But that download complete, we are ready to begin our installations. First, we'll start with the Java kit. Simply double-click on their country, begin the installation. It'll ask you for user control. Simply say yes. And you should see this box here. Simply click Next, Next. And installation will begin. Once that's done, who our Java should be up to date, and we can begin the eclipse installation. Learning takes moment clothes and begin installing Eclipse. Now when we double-click on the icon, this box appears and Eclipse asks us what workspace we wanna install. Once you become more experienced with Eclipse, you can decide which workspace will best suit your project. For now, clicking here an Eclipse IDE for Java Developers will suit us just fun. It will then ask which folder you want to install the ID in. Our preferred to leave these at the default and simply click install. You'll then be provided with some terms and conditions, except those as well. And installation should begin. And what's the installation complete? We are ready to start creating our Java projects and begin cutting. You should see the icon on your desktop or you can check to start menu to see if it is new as well. Once you've located it. See you in the next video. We will start by first creating a job project and learning in our first lan of trial occurred. See you then. Bye for now.
3. Eclipse Tour and First Line Of Code: Hello, and welcome back to Java programming course. In this lesson, we'll be creating our first Java project and learning are first lan of job occurred. Once you've located the shortcut for your Eclipse IDE, simply double-click on it. You should see the following splash screen. And here we'll select our workspace. Leave it as the default for now, the Eclipse workspace and click launch our recommender. So clicking on this uses as default and do not ask again, as we are learning basic code in this course. And we don't need to go and use some more advanced and complex workspaces for now. But we'll take a moment for Eclipse to start. But afterwards it will be a quick start. Once that is done, you should see the following. The Eclipse workspace is open and we can start by creating our first project. First you will see this basic screen here. Simply click the Close button here on this splash screen and close the doughnut box here. And you should see the following. Now, to make these videos a bit easier to watch and assert, make your programming experience a bit easier. I'm going to change the theme for this workspace. I always prefer to use the darker theme as it is a lot easier on the eyes, making it easy for you to locate certain bits of code. And of course, it is easier for you to watch on these videos to change the theme for your workspace, simply go to Window and preferences. Once you've done that, click on this arrow here by General, that'll create a drop-down menu. Simply click on appearance. And here you can change your theme from light to dark. Simply click Apply and close. But that done, your Eclipse IDE should look as follows with that. And let me give you a brief tour of what you'll be seeing here. You have a task list on your Archea and an outline just above that. These are more guards that you can set up to help you manage your projects. But we won't be using them in this course. We're only learning some beginning occurred. So you can minimize these to make the screen a bit larger for you to work with. Now you should have this main box here covering most of the screen. This is where our code will be. Below that you'll see a small window box. This is where output and problems will be displayed if we do encounter any errors in our code. And finally, to the left, you will see a Package Explorer was where we'll have all of our projects arranged and sorted for us to work with. But that done we can create our first project, but simply creating, create a Java project link here. Or we can go to File and click New. So create your Java project. Given a name and be sure to use a lowercase letter, such as first. And click Finish. It'll ask if you want a module to be created. Simply click, don't create as I'll be showing you how to do that in a moment. And you see a Projects folder here in the top of your package explorer. Clicking the drop down menu should show you the following. The JRE system are varying is where most of the basic code for Java is kept and we will be calling upon it. And our IDE. And our source folder is where we're gonna be putting folders and packages and our main programs already derived. Click on his new source folder, go to NYU and create a package called this package first practice as well. And click finish. And then right-click on this package and click New Class. And our call this class, something like main class, like so. And I want you to check this box here where it says public, static, void, main, and click finish. I said Dan, you should see the following here. We now have our source folder, a package, and we have our main class. Here. It is within this main class will be rotting all of our code. As you can see, I've opened up the main class. The code window is displayed some basic code we created with the defaults. And it is here that will be writing our first line of code. To make this code a bit easier to read, we can increase the font size by going to window editor and click in, zoom in, like so. Until the code is enough, I think to his humans should be enough. Now let me explain the code that you've seen on the screen now. First, you will see the following package first practice at the very top, which refers to the package at this main class is containing. And as for this main class, we will see here public class, main class, which is the main class dot Java file we created. After main class, we have a set of code brackets, which as I highlight one, the second is highlighted as well. Now to explain what a class is, I need to explain how programs work. Programs consist of many smaller programs, which consists of smaller classes, which consists of methods. And methods contain the basic code that we write. Now, a code within a method will work with each other to perform some task. And this task can be repeated by reusing the method that the code is within. A class contains methods, and methods contain code back the code working with each other. The methods can work with each other. The classes can then work with each other. And finally, and on the largest scale, we have those programs working together to make the main program work. It's an entire hierarchy of different code working together to perform an ultimate task. And to perform an ultimate task, many smaller tasks need to be completed, which is where these methods come in. Within this main class, we have our main method, which is established here with public, static, void main. Now, this is the main class, meaning it is the class that is executed upon running our program. Code within this main method will call upon any other methods and any other lines of code and work together to complete a task. Don't stress too much about this for now, as we will be talking about grander per grams in more advanced courses. For this beginner course, you simply need to know where you're gonna be writing your first line of code. So don't worry too much about this for now. But if you want to take your Java studies further at the end of this course, it's best to keep this idea in mind that bigger programs take smaller programs which take smaller methods and smaller lines of code to work together. Now, we will write our first line of code below this comment here. Simply click at the end of stub and press Enter. It'll automatically indent. So we'll be writing our code, right? Yeah. To create a comment like this, simply tap into forward slashes. It's our way of Latina program knows that this isn't coded should be running at rather, these are messages that program is, we'll leave themselves explaining certain sections of code. And a good program. I'll always take care to add comments to your code. Especially if they're working in a team of programmers. And working in a team of Program is a program will be handed off on different days, two different Programmer. And they need to see how the previous program have progressed. And addition. And it always helps to have the program help explain this code with some comments here and there. That being said, let's learn our first line of code. I want you to tap the following and I'll explain what it does afterwards. Simply tap in system. Dot out, dot, print L, M, a set of parentheses, and a semicolon to end the line off. What this basic line of code does is output a line of text right now, however, it's not outputting any text as we don't have anything between these parentheses. What this code does is call upon the system. It makes use of a method called out. And in this method is another method called print Lun. Prince Lan is just as it says, it'll print a line of text and create a new line after that text has been printed. The line of text or data in question is contained within these set of brackets. And the semicolon at the end of a line of code is a lot like a full stop at the end of the sentence. You'll find that most code you'll be writing will end with a semicolon. With that said, let's give this print line some text to output. Now it is tradition in the programming world that your first line of code and puts a line of text saying hello world. To do so we'll create a set of double quotation marks. And within, well, like soft, and that is your first line of code. The reason we use double quotations here is because we want to separate helloworld from other code. And the way we do that is by encapsulating it in these double quotation marks. In doing so, we let our IDE know that this isn't code, that in fact data, I'll be explaining different types of data and variables and so on in the next lesson. But for now, we just need to establish how to output a line of text. With that done, we are ready to run our program by simply clicking the play button up here, which will run our main class. And as you can see in the output window below occurred, it prints Hello World. This line of code is one of the most important lines of code programming can learn as it shows you what programming is all about. We take data and we perform a task, and we output a result. And right now the simple task we've given this program is simply outputting Hello World. But you'll find that many complex programs will make use of this line of code. Before we end this lesson, I want to show you another variation of the output. Simply tap in system. Again. Out print. Then instead of l n, I'll just create another set of parentheses. And our topping low. Then basic text. Copy this as well. And paste it here. Add world instead of hello. I want to show you the difference between print and print line. When I run this line of code, you'll notice that hello world is printed, just fun. But hello and world, yeah, apprentice together. This is because if you add to the end of your print, it'll start a fresh land after the output has been given. So at the end of print line here, it created a new land, which Hello is printed, but seen as it was simply a print. This land was added to the end of it. And we could make this alarm and I will start a new line below it, but the result will be just the same. You'll find the same happens if we remove the line here. That hello gets added to the end of the text. Just like so. Now I have provided you with a workbook for this Java course and a first exercise, I'll be showing you some basic text shortcuts to work with with your system, our print plants. Once you've completed that exercise, I'll see you in the next video. We will be learning about different data types and variables. I'll see you then. Bye for now.
4. Data Types and Variables: Hello and welcome back to your Java programming course. In this lesson, we'll be going over data types and variables. Before we can discuss variables, we need to discuss data types. There are different tabs of data that we'll be working with throughout this course. And indeed in your career of programming, five particular data types I will be teaching you now. The first dire tab is the string data type. The string data tab contains text. For example. You had Wrap Text encapsulated in double quotation marks, such as alone or John, as a name, or even an entire sentence, containing any characters of a numbers at one of the most basic data types to work with. And in fact, we already used it in the previous lesson. Next we have the char data tab, which is short for character. This data tab contains only a single character. And this can be anything from symbols to letters, to numbers, to even whitespace. And you'll notice that we encapsulate the single character in single quotation marks rather than double quotation marks. This is our way of letting the software, we know that this data is not code. That in fact data itself. Those are the text-based data types. Of course, we also work with number based data. So there are two data types in particular that we're gonna need to know. The first is integer. The integer data tab contain values from negative infinity to positive infinity. And these are whole numbers. For example, 580, negative 10 thousand and so on. And the second data tab is double, which has the same range, but we also include decimal numbers as well. So it could be 0.67, negative 5.8. And of course 0, this is 0 and double. Noticed there no single quotation marks or double quotation marks surrounding these numbers. You write them as you normally would. And finally, one of the simplest but most important data types we will be learning is the boolean data type. These contain one of two values, true or false. You will find that when we create what is known as conditional code, a Boolean value is used to decide whether that code will run or not. So those are the data types. But now let's talk about variables. Variables are containers for data. We assign a type of data to a variable as well as a name. So that way whenever we want to use the same value, again, we'd call upon the name instead of writing out the entire value again. Because as you know, string for example, can contain an entire books worth of data. So that a month we need to shorten it and make sure that this values only used once. The way we create a variable is by first deciding which data tab will be assigned to it. First, let's talk about string. We simply tap on the word string capital S, and we give our variable name. Now when naming a variable, it is important to understand that you'll be using lowercase letters in the beginning. For example, if I wanted to create a variable name for the first name of a client, our tap in first and then capital name. Like so. This is CamelCase scene and is one of the notations that you can use. One of the notations are preferred to use is making use of simple underscores to name your variables. And I include in it the type of data that will be contained in that variable. So with this name, I've used F underscore name, underscore, SDR, STR stand equal string. And like with all lines of code, we close with the semicolon. Now, we can assign a value to this variable by simply tapping in its name, tapping equals afterwards and in double quotations will give this string of values such as John and close at the semicolon. Now if we were to print out this variable, like sound, noted, print out John, when we run the program, as you can see here in the output window, of course, to save on space, we can assign a value to its straightaway if we have one by simply saying equals John in the creation of that variable. And we can erase this line here. And it works the same way and saved us a line of code. So that's a string variable. To create a char variable, simply tap and char, such as test, underscore CH, and we can assign it a value the same way. For creating an integer variable. Simply type in int, give it a name and a value. For double, simply tap in double. And for Berlin values simply tap into grueling. Give it a name and value just like that. And there you have data types and variables. Be sure to complete the exercise for this section in your workbook as it pertains to how to name your variables, which is very important. And I'll see you in the next video where we will be working with variables. Bye for now.
5. Working with Data and Variables: Hello and welcome back to your Java programming course. In this lesson, we'll be working with data and variables. Now in the previous lesson, we learned how to create some variables and assign data types and values. But now we need to work with those variables when we create an output. In your very first exercise, you learned some key shortcuts when it comes to working with text data. For example, a IRR is line of text and I've put a backslash t. You'll notice it prints out a tab between the two words. If I've got a backslash n, it starts a new line. And we'll commonly, if we just simply add these words on together with the additional operator, it's simply puts them together as if there was no space between them. This operator among many is what we are going to be using to create data as well as add to it. Find that you'll use operators such as this, particularly with number data. And we take the number 50 and we use the addition operator. And let's say we had 45 to it. And we'll add it as a produces a normal math function axon. We have our subtraction through the minus symbol, multiplication to the asterisk symbol shift eight. On your keyboard. We have our division with a forward slash. And now let's have a look at modulus, which is the percent sun is tells you how many. We'll take four and divide it into 50, and then output the remainder, which is all very simple. Of course, the output of these results depends on the data type. For example, if we were to create two double values and let's say we give one the value of 30 and the other the value of 14. And we divide these numbers by each other. It will output a double value. Whereas if we did this with the integer values on their own, it would simply add to put an integer. So for more precise starts, we would of course be using doubles. I would also like you to take note that we can place an integer value within a double without any problems. But we cannot place a double value and an integer and expect it to be the same. It would then of course be cutoff and turned into an integer. Add one, round up or round down depending on the decimal values that follow. I would also like you to take note that when it comes to the mass order, Java is of course aware of it. So if you are derived out along sequence of numbers such as this, where various brackets operators. It will complete them in the proper mass order and output the correct result. And finally, to end off this, listen. When it comes to working with variables is very easy to override variables. And in some cases it's also very necessary. For example, if I give this integer value of 50, I could easily change this value by simply saying num underscore again equals 45. And our output this new value. Like so. So when working with data, if you want to save on code, you can replace values in a variable was ease, but also be warned that in doing so, you'll be removing that value from your program and you will have to, of course, the sign it again if you were to use it again. This will of course be very important when you're working with large amounts of data. And with that, this lesson has come to an end. In the next lesson, we'll be talking about converting one data type into another. I'll see you then. Bye for now.
6. Converting Data: Hello, and welcome back to your Java programming course. In this lesson, we'll be talking about Eigen convert one data type into another data type. Now there are many data types that we're going to be working with. Let's first talk about how you can convert a string into an integer. One of the first and most important conversions is converting a string into an integer. So first, I'm going to create a string. Word underscores TR equals and a double quotations are put in number. Now, it is important to remember that when you're converting a string into an integer, that the dots are contained within the string is in fact a number. Otherwise, this will create an era when you try to convert it, because you cannot simply convert a word into a number. So we want to convert this text 15 into an integer 50. Because you'll find that if we were to add, put this and treated as if it were a number. So would underscore STR plus, let's say far, when we run this line of code and outputs 505, which is incorrect, to convert this string into an integer, which is going to create a simple integer variable. And make use of a line of code which will convert this string integer capital R. Be sure to note casing. Pass int capital R. And contained within R have word underscore st are in these parentheses and are invalid of code with a semicolon. It's this line of code that will take whatever string data is based in this parentheses and converted into an integer. So now our place would underscore string over here with the Netherlands called int. And when I run this line of code, it has been converted into an integer and five has been attitudes value. We can actually work with this data now. Now let's talk about how you can convert any data tab into string. And that's right, any data type can be converted into a string with one simple method. So for example, if I was to create an integer value here, and I'll give it the value of 5986 semicolon. I can convert this into a string by simply having two double quotation marks plus sql int. And now it has been converted into a string. As you'll see when I add, put it below here. Five has been added to the string of values. Instead of added to the valley itself, it is important to note that this is very different from our previous conversion. You won't be tapping out string dot pass string, but you'll find that this code is very easy, so not much else needs to change. Now while we are still talking about some text-based data types, let's talk about character data types. Let's suppose we want to convert a character value. Into an integer value. So char CH equals r, give it a value of five in single quotation marks. Notice once again that I am placing a number value in a single quotation marks. As you cannot convert whitespace stiletto symbol into a integer data tab. On small I create an integer hemi, so numb underscore int equals and one small, I'll be using Integer.parseInt. But instead of tapping out CH, Yeah, which will create an error because we cannot simply convert a char data type into an integer data type. What we're gonna do is create a mini conversion within these parentheses to double quotation marks plus CH. This will convert the character data type into a string. And the Integer.parseInt 12 goes convert that string into an integer, just like it did in the previous example. And one small, this is a value we can work with, as you'll see here. And outputs ten when I add five to its value. So the conversion was successful. Now, when it comes to converting data into a char, it becomes a little bit more complex again, as we have to make use of a method to convert any data tab into a chart. So let's just say our crate, a string here. String. I just put the word underscore STR, and output of world as the word and a semicolon. Now as you know, the character data type can only contain a single character. So it cannot place this entire string within the char. But we can still take a single character from the string and place it in a trial. The way we do this is with a char et method. To use it. Simply tap in the name of the variable you are calling. Dot char at parentheses. Notice it's a capital, a pool at. And within these parentheses, I'll place a number value. The reason being is because a number value is assigned to every character in the string, and it will start at 0. So if asked to pay 0 in this parentheses, it would take the very first character that appears in the string, which is w, and place it here in CHS variable. So fast. But one it would put O, two, it would put r, and so on. But let us simply place the first one into CH and our output CH, Like so. And it prints W a bit more complex, but it is still very simple to convert a string into a character. You're also be doing something very similar when you converting an integer or a double value into a character. The way we'll do this is by simply with a parentheses, double quotations again, and whatever the value is, such as 54.8. So as you can see, this is just a many conversion. We converted into a string and we make use of the char admitted. So this should print out five. So we've successfully converted a double value into a character value. And it's just as simple as an integer. Of course, we are just simply takeaway that decimal point. Now with that out the way, let's talk about converting a double into an integer. So I'll create a double now, sort of double underscore DB equals, let's say, 45.8 semi-colon. To convert it into an integer. You'll put a per set of parentheses. You'll tap int within these parentheses and the name of the variable that we will be converting. So this is a little bit different from Integer.parseInt, but it works the same way. It will convert this double value into an integer. And you'll notice when I print out this value, it cuts off the decimal point. So it won't be printing out 46 as not rounded up. And we'll just cut off and ignore the value and just print out the whole value that it has the, which is 45. So that's how you convert a double into an integer. To convert now a string into a double will make use of a similar method that we use to convert a string into an integer. So it underscore STR equals and output once more 45.8 semi-colon. And when we give its value to this double, we simply toughening double dot pass. Very similar to Integer.parseInt int. And one small, this is a value we can work with again, as you see here, when I add five to its value and prints out 50.8. So our conversion from a string into a double was successful. And you will find this is very similar to how we convert a char. So for example, if I was to take a char value of, let's say five. Again. We've converted our Purina small conversion within the parentheses, just like before. We converted into a string and then we will pass it into a double. And as you can see here, an the output, it has converted it successfully. Now for the file conversion will be converting an integer value into a double. The way we do this is by simply placing a value within. There is no need to convert an integer into double as double has the accurate range. There's nothing that needs to be cut off because in fact, double will be converting this basic five into 5. So it simply by assigning this integer value to this double variable, will place that value into a double and converted, as you can see when I put it here, and outputs 10. And with that, we have learned how to convert one data type into another. Be sure to practice these conversions and memorize them, or keep a handy cheat sheet CloSpan. These conversions will be very important in the next lesson, as will be retrieving user.
7. Retrieving User Input: Hello, and welcome back to Java programming course. In this lesson, we're gonna be learning how you can retrieve user input. Now, with most programs today, using input is required for a task to be complete. Let's take a basic example. If you wrote a blog post, an article, or a chapter in a book, you write it in a writing software. And that writing software takes that input and it runs various programs which tell you how many words you've written, how many characters, what words you use the most. And it also checks your spelling and grammar. It wouldn't be running those tasks if there was no data for scan. As a result, this program relies on user input and that is what it's designed for. And you'll find many smaller programs today make use of this as well. Even if you're logging into a basic online service such as Google, it requires your input, in other words, your login details before it lets you in. And if you're managing your email, it requires your input to decide what is spam and what is not, what should be deleted and much to be kept, and so on. Even smartwatches which count your steps require you to step before it adds one to the counter. So as you can imagine, retrieving user input is of utmost importance. But before we can run the code, we need to import a package which contains some basic code we need for retrieving user input. You'll find that when working with many more complex programs that importing packages with certain code is required. When importing packages, we place our imports at the top of our occurred just above the main class. The reason we do this is because we can manage our imports all in one section this way. That way we can see which is in use, sandwich might be missing. And it's very easy to manage, especially if you work for a larger program. The class that we're going to be importing is known as the Java Swing costs. And to do so you simply type in import Java dot, swing dot, asterix, semicolon. Now this works pretty much like a directory, Java x's container full swing class, along with many others. And we are importing over methods contained within the swing class as well. Fire purine, an asterisk symbol. We can call specific methods if we want, but it's far easier just to do it this way. Was that done? We are ready to write code to get the user input. First, it's important to understand that the user input is always going to be a string. Since we're acquire different data from our user, will have to make use of parsing to make sure the data is properly converted to the raw data. Now let's create a basic string variable which will contain our user's input. So that'll be string and Addis close one input, STR equals. And now this is where we write the code to get our user input. Jay, option. Show input, dialogue. Take note of what is in the uppercase J and a capital P for pain, i for input and DB2 dialogue. Now what's contained within these parentheses is simply a message to our user. So for example, enter your first name, colon space. And now when we run this line of code, you'll notice a box appears here was the command or question, and it'll input window. So I can enter a name such as John and press enter, and that value will be stored within input underscore string. And then we can treat the piece of data like it was just a normal string. We can pass it into another data type that we want to use and so on. So for example, I'll create a simple output. Let us make use of the string, such as hello, comma space plus input underscore FTIR. Johnny, it says Hello John. So now we have access to data that the user can enter with ease, thanks to Jay option pane showing put dialogue code. If we also want to pass this when the same land. Let's say if we wanted to get an integer and ask how all these is, how. You will notice that there is an error because we cannot directly place a string within an integer variable. So we will have to pass it with integer dot, parse int and encapsulate this input dialogue in parentheses like so. And we no longer have any era. And we can treat this input as inclusive Reagan a number. So input string plus five. We run this line of code and our enter something like 26. And power is added to the value as it is now treated as an integer value instead of a string, it's that easy to retrieve, uses input and really start working with it to complete a task. So now we can retrieve using input, but we can only do much as process it and output it. But we don't have any code yet that can check it for any specific values, which is exactly what we are going to be learning. In the next lesson, we will be going over if statements. If statements are conditional code, which allows us to decide if a certain tasks should be performed or not based on data. But you will learn more on that in the next lesson. I'll see you then. Bye for now.
8. Basic If Statements: Hello and welcome back to your Java programming course. In this lesson, we're going to be learning how to use if statements to create some conditional code. Now as you can see, I already have the Java exploring package already imported. So we're ready to retrieve some basic user input and then make use of if statements to decide whether a task should be performed or not. But first, let me show you an example of an if statement. An if statement makes use of what is known as a clause to derive a value which decides whether the code that follows will be run or not. For example, if ten is greater than five and this parentheses, I create a set called brackets. Notice there is no single kernel. And then I'll just create a basic output line here for basic message like test complete. This is what a basic if statement will look like. You'll have a set of parenthesis which contains clothes. And within this clause, data is checked. Now, checks can be done many number of ways, but in this particular close, we're just asking the program if Tim is greater than five. And of course it is. So what will happen is this operator will create a boolean value, True or False. Obviously, if it proves true, then the clause is accepted and code that follows and the set of code brackets over here will be executed. So let's just run this line of code analysis test complete. However, if our to switch things around and say ten is less than five and run this LAN code. Nothing is printed. This is because the clause is not met. There are many operators we can use to compare data. We've got greater than and less than, we've got rather than an equal to, less than and equal to, we have equals, equals, which is simply comparing two values to see if they're the same. We don't use a single equal symbol because this is what we used to give a variable its value. And we can't assign the value five to the value of ten, which just wouldn't make sense. So we make use of two equals symbols to perform this function. And to check if they are not equal to each other, we put exclamation point equals, that is a basic if statement. So what I'm gonna do now is retrieve some user input. I'm going to retrieve an integer and ask the user how old are they. I'm then going to make use of the claws to check to see if they're older than 40. And I'll make it inclusive of 40 with greater than and equal to operator. And a message saying something like so. You are 40 or older. So let's just test that out. You'll be testing out your code a lot, especially as you make small adjustments like this, says you're 40 or older. And FINRA anything higher? Let's say 789. It says the same thing. So now we can take some user input and we can compare values. Now let's say we want to message to be shown even if the clause Bruce, false. Now it's very easy to create another if statement in this case and give it the opposite clause. I'll just copy this and change the output text. So now message will be displayed no matter what data the user enters. So fine, contain 23, it's younger than 40. And EPA negative 700. It still says I'm younger than 40, which is all technically correct. But of course, this just requires more adjustment to make it a bit fun tuned program. However, this is a rather clunky way of doing things. As we may not have such an easy close to create an opposite of. So, in which case, we have to make use of what is known as an else. And L is easy to add to an ifStatement. Go to the end of this vast called bracket. In the first if statement. Press enter, tab, press Enter again, and create another set of code brackets. Now this else will contain the code that will be executed if you look close, proves false. So that way we have now code that will execute no matter what values are using Entrez. And we do all that in one if statement. And now before we end this lesson, let's tackle a bit more complex code here. And we're going to be comparing a string with another string. So I'm just gonna change the input type to string. And I'm going to be asking if the user's name is John saw put equals, equals. And I'll put John and the double quotations. Yeah. And if they enter their name and it is drawn, it says Hello, John. And if they don't intend John edges is hello. But you have found that when I entertained, it simply says hello instead of hello John. And this is rather peculiar as we seem to have the exact same data, but it doesn't seem to work. We even have the same case with every letter. This is because when it comes to comparing a string with another string in Java, we have to make use of a message. And as the compare to method. And we create a set of parentheses around the data. We want to compare it to. Like so. And after compared to we tap in equals, equals 0. We can now finally test out this code and get the right result back by simply tapping John again. It says Hello John. But you'll notice that there is a problem if you enter it in with lowercase letters. Not just any other name, such as marriage and so on. That unstress too much about this code. But this is just to show you a problem that you're going to encounter. In the beginning, I will be showing you some methods later that make comparing strings of phi easier. Though before this lesson, I'd like to explain this code all the same. The compare to method does, is take the value of input and a school string and compare it to John. What this will do is add, put a particular value depending on the differences in text. Now, if there are any differences, the value will be below or above 0, which is why we have to make sure that there are no differences. Cert outputs a value of 0, AAA. Explain this. I'm going to copy this line here. And I'm going to remove the if statements. And one of the app wetlands. And I'm simply going to output string.com to John. Now when I run this line of code and I'm going to enter in John, the exact way it is going to be compared to, it prints 0. But f, our printer lowercase John, it has value of 32. Now the reason for this is because there is something known as ascii, which is when a number is a sand to a specific character, every character has a specific number is sand to it. The differences in these numbers now get compared to each other and a value is outputted. You will find that it when our art max and outputs three, or when I output the lioness, for example, puts to these valleys are being compared to each other and the values are polluted. But the only time it will ever equal 0 is if the values they exact same. Of course, we're going to make a more user-friendly program in the future, one way. And a user enters in their name. No matter what the case that is used, the name is still treated as the name that is expected. For example, if our attain to mRNA MSU, but I'd use a lowercase m on accident. All that simply is the way how rat we still wanted to be treated as Matthew. Instead of some other type of data. We'll be talking about this more in the lesson on text methods. For now, however, I want you to experiment with the if statement, create your own clauses and test them out with if statements and elses. There is of course, an exercise in your workbook to practice with. And once you complete, I'll see you in the next lesson where we will be discussing more advanced if statements. I'll see you then. Bye for now.
9. Nested If Statements and Additional Operators: Hello and welcome back to your Java programming course. And this lesson we're going to be discussing nested if statements and additional operators. And the previous lesson I introduced you to the if statement. What we're gonna do now is take those basic if statements and make them a bit more complex. The way we can do this is if they are multiple clauses that need to be met are brought up the example of checking a user's age to see if there was 40 or higher or below with the else. Let's say that we want to check to see if a user's age is between 4050. You'll find it as programs like this that are known as filters. When we go to a SART and we search for, let's say, a specific product or service. They usually provide us with various filters to help fine tune what we are looking for. So what we're doing in essence is fine tuning data to find a specific value, which is of course very necessary if you have to sort through a large amount of data. So once more I am going to get the user's input, and I'm going to put it into an integer variable. I create basic dialogue into your age colon. And now I'm going to create an if statement which will check the age to see if it is above 14 and inclusive of 40. So it's greater than and equal to 40. Like so. And of course our creates an else statement to see if it doesn't fit that. But now I want to check to see if they age is also 50 or lower. So let's say that our first clause proves true, will then create another if statement. Within this if statement, if input and the score is less than or equal to 50. And our creative basic output once more. This is what is known as a nested if statement. It is an if statement. Within an if statement. You can do this indefinitely, having a large sequence of nested if statements depending on tabs of data. But for this example, only one nested if statement should be needed. And I'll create an else if statement as well with another output plan. Saying you are older than 50, because in this case, the user would be, as they've done, fulfill the second clause. And then I'll have a system I print line and the L statement saying you are younger than 14, As they didn't fulfill the first course. So that way if something is outputted all the term. So intensity, that says you are younger than 40, which is correct. Now, let's say I am 60 years old. It prints You're older than 50, which is correct. But let's say I'm 45. It says you are between 4050 years old, which is again correct. So using multiple if statements, we can check this data to look for specific values. Instead of some broad numbers. Of course, we can still into extraordinary large or small values and it will fulfill some clause in this if statement. But once more, that is a problem that can be fine tuned with some nested if statements. All was what we're about to learn next. Additional operators. Additional operators allow us to have more than one clause within a set of parentheses. What this means is we can make sure that two or more clauses need to be met before the code within the if statement will run to make use of an addition operator. How we tap in, in these N symbols after the first clause. And I can now put another clause here straight afterwards. So for this if statement, we're checking to see if they are, although equal to 40 years old. But we also want to make sure that they're not entering in an extraordinary value. So we will have to make sure that their age, let's say, for example, is less than 50. So then we'll have to make sure that the age is less than a 150, so it's not an extraordinary value. So this way, two clauses need to be made before the next if statement can run. If I was to run this line of code, NFL is to maintain 50. You notice that principle between 4050 years old. So it does work. Both clauses were met. But if NT and a 115, it says you're younger than 40. So we've already encountered a problem here. We've checked now to see if the user is less than a 150. And that much is correct. Now we have to now change our else statement because it doesn't make any sense. So to take this program but further, so what we are going to rewriting it is an else if statement where after the else we tap in F. And then we check to see if input and a score int is greater than 0. Now, if statement is starting to look a bit more complex, but also a bit more accurate to avoid any garbage data. So our first if statement is taking these two specific closes. If the closest both proved true. And we'll run the code within a set of brackets that our else statement down below here now has a closed in addition to it. If input is greater than 0, what this code does is make sure that no garbage data is entered. So we'll make sure that a value within a certain range is met before code is executed. I'll add another else statement after this one, and once more, I have another output. Something same, invalid H. Now we have a far larger and more complex program that a far more efficient and accurate one. There's just one more additional operator I would like to add here, which is N symbols input underscore int. And we need to, of course check to see if they value is less than a 150 as well. So let's enter in the code are like so. And our intent, large values such as a 130, it says invalid age. If I enter anything higher, let's say 300, it's his invalid age. And let's say if I enter in negative 30, it says invalid age. So now we've deter the user from entering any value that isn't between 149, store a large range, but it's more realistic range than what we were working with before. Now let's intense specific values where certain conditions will be met. So these conditions have already been made if we entertain anything that is between 4149. And these clauses will always prove true no matter what. And then this clause will be checked. And statement will be given if it's true or false. And our else if statement, we now have to enter in a value that is less than 14. So let's say 39. It says you are younger than 14. If I enter in one, it says the same thing. And any value in between those two, it will say the same message, which is of course correct. So there we have created a complex nested if statements making use of additional operators as well to check for specific data and to avoid garbage data if you're still struggling with the if statement and how it works, I do recommend watching this lesson again, right out the program for yourself and read the conditions as if there were sentences. You'll find that many lines of code in your programming career with Java, we'll read much like an English sentence. So take the first clause, for instance. If input is greater than and equal to 40 and input is less than a 150. And then the code that follows will be executed at simple values like this that will be checked by this clause. Now, before this lesson ends, I'd like to show you the or operator as well, because there are two additional operators we can work with. The first are these N symbols. What these n symbols do is make sure that the crows before and after them have to be met to prove true. But if we wanted only one of the conditions to be met, we would make use of these two vertical lines like so. This is shift backslash on your keyboard. So as I said before, only one of these claws needs to emit for the code in the if statement to run. So for example, if the input is greater than equal to 40 is made, then the code that follows will be R1. However, we also have a code here that says if the input is less than a 150, the code will also run. So this destroys the whole concept of a filter because these two clauses can both be made with any value that the user enters. For example, if I hinted in 5 thousand, the first value would be met. If I enter negative 3 thousand, then the second clause would still be made. And as a result, we'll get data back that makes no sense, such as your between 4050 years old, it will no longer part of the value that we have entered. So of course it comes down to you understanding how these additional operators work, deciding which one to use in specific situations. So there you have nested if statements and additional operators. I do recommend giving this listen a bit more practice than the previous one as we are working with larger, more complex programs. But you'll find that with practice your master, the if statement in no time. And the next video, we'll be going over some text methods. I'll see you then. Bye for now.
10. Beginner Text Methods: Welcome back to your Java programming course. In this lesson, I'll be teaching you some texts methods which you can use to and manage some string data. Now, there are several methods I'd like to show you, but I'll start with the simplest first. First I'm going to create a string variable and assign at the string value of Apple, create a basic output and print that value and is tested to make sure it does print out Apple. So now we can start using some takes methods to adjust it. The first tics methods I'd like to show you are the uppercase and lowercase methods. As you can guess, these methods will change the characters in a string from uppercase to lowercase, a lowercase to uppercase. Take this one I've assigned to the word string, apples capital a, but everything else is lowercase. And I'll make use of the dot to uppercase method and add a set of parentheses. You will find that most methods will have a set of parentheses that follow. But you don't have to place anything in these brackets. Simply Arad dot to advocate and on the program. And as you can see, all the letters and Apple have been converted to the uppercase, excluding a, which was already Day, and vice versa to lowercase, will convert all characters to the lowercase format. So this example is just the letter a. We use methods such as this to create more uniform data. As I showed you when it came to retrieve in user input and comparing string data with other string data, it's important to have all the characters in the right case. Otherwise there'll be considered different types of data. So you will find these two methods incredibly useful to make sure that all that data stays uniform when working with. The next method we'll be learning is simple character methods. I'll create a variable and assign it the value of capital T. And within the output, I wrote the first method. Tapping Character dot is letter. I said the parentheses and replace the variable. Within. What this method does is check a character to see if it is a certain character that is legitimated checks to see if it's a little. So if I run this code, it should print true because the letter t is a letter. But if I was to use something else like just watch space, it would print false or number. It would also print false and so on. But we also have methods to check for that type of data. For example, for taking a number we used is digit, which proves true in this case. And for checking what space we're tapping is what space. So in this case it will print true as well in addition to these checks, whereas I have is uppercase and lowercase. So if r changes back to capital T and run this code, it says true that if I put a lowercase t and ran, it says false. Those are some basic checks were all make sure a character is a character does, helps when processing data and you wanted to maintain a uniform look. So if you want to convert to something else, so you gotta check to see if it needs converting, things like that. So those were some character methods. Returning to string, I'm going to create another one here, and I'm gonna give it the value of Apple again. And the method will be learning is.length method. The length method will count how many characters are in a string and return a number result. So word underscore STR, first dot length, and another set of parentheses. When I run this line of code, it should return five, which indeed it does because there are five characters within this string. However, it includes whitespaces counting, as you'll notice, wanna add whitespace off to Apple and run this code. It outputs six. So this will tell you how many characters there on a specific string. We already have code like this working with some of our software. For example, writing programs will count how many characters have been tapped and they'll use this code to check every character and give you a result that that is the length method. And you'll find the length method very useful when working with index methods. The index method allows us to find a specific character or word in a string. For example, if I wanted to find the number value for the letter D in a string around a spline occurred in outputs one. That is because as you know, there's a number assigned to every character, and one is assigned to a first letter P. I put an L. It returns three. If I was to put it in an entire text such as Apple, You'll notice that returns 0. That's because Apple here starts at the first character that allow us to add a space for Apple and run this code, it will output one, because now the place value has moved up one. So we use the index of two fans, certain words in a string. And in many cases this is to remove or metalloids completely or in some cases to replace them. But the index of method does, is it reads from the left to the right. So as a result, if we have civil mentions of a certain word in text, we'd have to run the code several times if we wanted to replace or mid certain words because we have to find each version of that word in the sentence. But if we wanted to work from the rod to the left, we would make use of the last index of method, which will work from the end of the sentence towards the beginning. But you'll find if I place E here in a string and run this code, it's still outputs the same value that it runs from the right, left. So if I put p in this last index of that will fund the last index of that later and return the value, which in this case is three. Whereas if I use the normal index of it returns two. Because that is the first character of P to be mentioned in a string. So those are the index of methods. We have two more to go through. And I'll start by bringing a familiar one to the table, that.compareTo method, which we discussed in a previous section. But I'd like to explain it further. Now what the compareTo method does is it takes two strings and compares them to each other. And by taking the number values are sand to every character at the Datsun from each other and outputs an integer. It is with these numbers that we can alphabetize text. As I'll show you now. First, I'm going to show you what the output is. If I compare one underscore is the r.compared to two underscore is t off. When I run this line of code and outputs negative one. This is because the value for a is less than B. It is greater than a by only one value. If we replace it with C, will have negative two printed and V negative three printed. With this in mind, we can create an if statement that will run. And Alphabet has these two pieces of text. So if that compareTo method unmanned are create a basic if statement that will take these two strings, compare them to each other, and sort them out alphabetically. So in this case, if one STR.com to STL is less than 0, then we know that the second value in two string needs to be placed after one string. Now, what are un-Islamic code? It should sort them out of vertically as it does here, a b. Now if I add two B's, often, just to make sure Prince AB and then VB. So it is sorted alphabetically after TIA, Robert. And app. It should print out marrying and Robert as it does. So it's a simple programs such as this that we can Alphabet has large amounts of data. If you wanted it to be a bit more uniform about comparing our data, we would make use of the dot uppercase to lowercase method. In this case, I've been taught to uppercase. And up to the case. Just in case a values into such as Mary, but with a lowercase m. Well Robert, with a lowercase m, then the doctor wouldn't be uniform and we cannot properly compare them to each other. But the results would still be the same as you can see here. And now finally, for the last method, we'll be learning with text, that charAt method. But the triad method does is it takes a number place value that you assigned to it at funds, the characters Santa, that value in a string, and an output that character. So for example, I create a basic output and I make use of one underscore STR dot char at, and a set brackets, and I'll place 0 within these brackets. It should print out the first letter in a string, which it does, it prints out an uppercase M. If I wanted. Second place character, that it print out our possess, you know, it starts from 0 with the first character, one mode, the second character, and so on. And that is an as easy note to end this lesson on. Those are some beginner ticks methods that you can use to take string data, process it, and work with it to create some more complex programs and also more interesting outputs. In the next lesson, I'll be teaching you some mathematic methods that you can use to do the same thing, but with number data. I'll see you then. Bye for now.
11. Beginner Math Methods: Hello, and welcome back to your Java programming course. In this lesson, we'll be going over some basic math methods which you might find useful for working with number data. Their very first math method will be working with is math dot square root. First, I'm going to create a basic integer. So I've tracked in num 16 semicolon and I'll create a base. I'd Portland to test out these math methods. So the first one is Math.sqrt route. We do this by simply tapping and mass capital M dot SQRT as the shortcut. And we place a value such as underscore int. And this will return the square root of this value. As you can see, it prints out four. You'll notice it prints out a double just in case we intend a value that cannot be derived down to its square root, such as 15. When I run this, it outputs 3.8, etcetera. This is because 15 dozen I'd have a natural and gt where 16 debt. But this is a very useful math function to have, especially if you're working with some complex programs, detect this further. If we wanted to print something to the power of something else, we would use Math.pow like. So. I'm going to change the value of num underscore int. And to give it a power of something, upward comma after num int and our place in it values such as two. This is for ab squared. What should I put 25. Note just one small edX app puts a double despite me working with an integer. So that's how we're used to the power of something. And its work is something a bit more complex but useful. The mass dot max and the Math.min. But this does, is it compares values with each other and returns the maximum or minimum value. So for example, our leave number's value, like so. And to be here, and it should return five because five is greater than two. This is when we're working with data from the user and we want to compare two values and add one to require some specific if statement or digit or operator as very useful for comparing two values. Now if we change the max to min adore turn the smallest of the two values, as you can see here. So that's the max and min methods. Now let's work with a basic double, double underscore DB equals, and I'll give it the value of, let's say 5.4. The next method that we're gonna be using is the round method. This method will simply take the number value and rounded off to the nearest digit. And this case it will be fast because about 5.4 as the doublet value. But let's say we were to have non simulate edit rounded off to six. So this way we can create a bit more clear data and avoid any decimal numbers. And finally, the last method method for this lesson is math dot random. Math dot random method is often used when displaying images that are meant to be randomized, but I suffered certain parameters. The way we do this is we get a random number and we work with that number to create an image in some cases or present with certain values. So the mass dot random method will generate a number between 0 and 1.00. Now this is an extraordinary range, as well as you might get naught point, naught 375 or nought 0.9, something as simple as that. And which case if we wanted to generate values, let's say from 0 to a 100, we'd put math.pi random and we would times it by 100. So as I run this program, you will see it prints out 20, but I run it again, it prints up 5410 and so on. And this range goes from 0 to 100. We would then go further. If we wanted to run off these numbers are simply encapsulating them in parentheses and tapping mass round for them. And running the program again. Now it's generating clean numbers from 0 to a 100. And there you have some basic math methods. You can use this to work with number data, to come up with values of your own and so on. And the next video, I'll be talking about how you can create repeatable code through loops. I'll see you then. Bye for now.
12. The While and For Loop: Hello, and welcome back to our Java programming course. In this lesson, we're gonna learn how to create repeatable code through loops. Now there are two loops in particular that we'll be talking about. While loops and for loops. And much like if statements, these loops grade sections of code that will run repeatedly and tore clause is proved false. So while it is true, the code will, will repeat over and over and over again until the task is complete or certain condition has been met. So I'm gonna be showing you now a while loop. And to show you that I'm going to create an integer variable and give it the value of 0. And then create a wireless much luck as accurate an ifStatement. While, but now with a set of parentheses are placed the clause in, such as num and a score hint is less than ten and our crate, a basic upward line within us up port land, up, place, the num underscore int, and we're ready to run this loop. Now you'll notice something interesting will happen when we run this loop. First of all, when I could pay your noticed, it is constantly repeating the value of 0. This is because while the condition is true now, it needs to be proven false for the loop to end. As a result, we are stuck in this loop and we are forced to stop it by clicking this little red button here could terminate in the program. And within a few seconds, 0 as being printed thousands of times. So what we need to do is make sure that this clause proves false at a certain point. I already put enough cause here we're numb is less than ten. So what we need to do is increase nums value until it is ten or higher. And we can do this simply by creating a counter through incrementing. Incrementing is simply adding to value each time that's code is run. So it would look something like num Ionesco int equals num and it's caught in plus one. I'll end with a semicolon. And when I run this line of code, you'll notice that prints Zero to none. So that's ten iterations of the loop. We're going to just simplify this, incrementing it by removing this code, yeah, and placing two plus symbols. And it's exactly the same as the code before. But already we have now created a loop that are run ten times so we can go through ten pieces of data or as many times as we wish, depending on the user's input, we can decide how many times this loop will run. So I'm going to now create a basic string, call it Name and a store is T R equals. And I'm going to ask for user input now. She looked dialogue and I've put in a message saying Enter name. And then afterwards in brackets, enter, stop. To end those brackets. Like so. Now I'm going to create a while loop, while. And then a set of brackets, name, and score STR to uppercase dot two. And then in double quotations is TRP, is pulled caps. And to continue the clause. While this is not equal to 0 from they create a basic output line that prints hello. And whichever name that the user enters. And to save time are copied. Islam occurred and pasted here to ask you use a again. So now we've created a loop that will end only when a user wants to end. So now I can enter their names, such as John. But it isn't until I intend stop that the program will actually end. And it doesn't matter which case are useful stopper as well. As we have made sure that our data is uniform with toUpperCase method. If you're not sure how to use the dot toUpperCase method or the.com method. I recommend going over the lesson on text methods. But there we have a more complex while loop that will run repeatedly and without end until the user decides it is time to end. But that is only one of the loops I'll be showing you in this lesson. There is another, which is more common type of loop that will run a certain amount of terms. If you have such a number to work with, this loop would look as follows. For int i equals 0 semicolon, i is less than ten semicolon, again, I said of brackets. And inside the set of brackets are just turn another basic output and our print as a value. Before I run this code, let me explain what this for loop is. That the for loop is used if you have a specific number in mind of how many times a code should run. So I've created a clause that includes the creation of a variable, the clause itself, and an incremental all on one line. So this loop, as you would guess, will run ten times from 0 to nine. If you don't want the hassle of creating a complex clause that will end after certain amount of times that you have a specific number and mud, you'll most likely be using the for loop. However, when it comes to comparing data, you'll find that you'll use the while loop With that said, that is the for loop and it is one of the simplest loops you can use once you understand how loops work. And as with if statements, you can have loops within loops, much like a nested if statement do. You can create a nested loop. In some programs you will find this will be necessary. However, for this beginner course, we won't be working with something so complex. And on that note, I'm gonna end the lesson here. And in the next video, I'll be providing you with an answer to the final project was begin a course. You found this project in your workbook. Be sure to go to the last section on the final project. Finally, instructions and create program with the code that you know. Once you're ready to see the answer, I'll see you in the next video. See you then. Bye for now.
13. The Final Project Answer: Hello and welcome back to Java programming course. And this lesson, I'll be providing you with an answer to the farmer project. As you can see, I've already created the files, the packages, and the main job of file. And I've also import to Java swing as we are going to be using user input. With that demand if you have not completed the final project, I recommend doing so. You'll find it in your workbook in the final section called the final project. You can pause the video here and I'm pose it when you complete the project and I'll provide you with the answer. You can also find this answer at the back of your workbook. Ok. Now I'll show you first of all, all the variables that I'll be creating for this project. I'll be using some double variables to count the entries. This way I get a more accurate percentage of how many have made it into the movie and how many ad not when are converted into percentages later. Now, I'll call it s1 entry db to count the entries. And I'll give it the value of 0 to start off with. To make things easier if you want, you can create the variables of the same top in the same line by simply adding a coma of the variables creation. So I'll be creating a new entry being hit as well. But if you want, you can write this on a new line at will work just the same. After that, I'll be creating the integer variables. So int age, underscore int, and we give it the value 0 as well. Next, I'll create a count variable to count how many people have tried to get into the movie and succeeded and so on. So let's count equals 0. And finally, our have an oldest int which will contain the value of the oldest movie viewer. So I'll give that zeros as well. And in the Islamic semicolon cannot create the string variables will be using. There are three in particular. The one is first, which will contain the firstName, and I give it a blank value like so. And last, which will contain the lastname. And finally, old underscore STR, which will contain the first and last name of the oldest movie viewer. And we are now ready to retrieve user input. The way we're gonna do this is through a new string variable and alcoves on stocked STR equals. And this is where we're going to ask the user if they want to run the program. So Gi option pane dot-dot-dot input. Dialogue. And we can give it a suitable message, such as enter, start to again, or stopped. Just to make things easy, I'm going to zoom out just one bit, just sort of a code converting the screen a bit easier. Also do this bar area in this project managers screen over here. With that input, we're now going to create an if statement. Finishes if statement, we're gonna take start STR, converted to the application to make it a bit more uniform. And of course, who are prepared to start. So equals equals 0. So if the user has entered, the program will begin if they enter, stop or anything else. If statements closer proof false and the code of sin will not run. And I'll be placing all the code that follows within this if statement. As if the user enters stop, I just want the program to terminate and nothing to be displayed. But once it starts from here will create a while loop. First underscore STR to uppercase once more to make it uniform data. Serp fool does not equal 0. So we have now created a while loop which will run until the user enters in stop in the place of the first name. Was that a month the user now needs to enter in values. And a quick first underscore STR equals j option. In dialogue. And the message I will have here will be something like into her name or stop to end. From there, we have another if statement with another complex close, but over the last one we'll need to rapped first underscore HDR. And we simply have to copy this clause up here and pasted with him. We do all this to make assurances that the user has entered in the Datta for this program or if they have entered, stop, that nothing will happen and the program will simply terminate with whatever data it has. Within this if statement, we're now going to ask the user for a last name and age. So I'm gonna take this input lamb and copy it here, and paste it here. And I say enter, last name, like so. Copy this one small. As we are now going to get h, we are going to pass it from a string into an integer. So now we have all the data we need from the user. At this point we have a first name and last name and an age. We need to now check this age to see if it meets the requirement for the movie where it's 18 and hire. And we'll do that with an if statement like Sir, if age underscore, introduce greater than or equal to 18 witness statement, we're going to us and our creates an output that tells the user if they are allowed in the system. Dot print land. So it'll look something like this. Hurst and a score SDR DO2 advocates to make it uniform dot at 0 to get the first letter. Plus periods space plus last underscore, STR has double quotations, colon, backslash t for tab and entry into caps. This viewer is 18 or older, so they are allowed entry. With that in mind, we also need to add to Kant's Valley because we've now got one added to the turtle. And we'll also add two entries, value entry and a school db plus plus semicolon. In addition to this if statement, we need a place, a nested if statement to check if this ages are so one of the oldest. The way we do this is simply placing an if statement here. In which case we will have to now replace the oldest int with the new age. Because we want to make sure that this program works not only of the first viewer. And we needed just the old string arc, so with the new firstname and lastname, because right now all SDR is blank. So let's first go STR plus double quotation space plus last underscore STR, like So. With that Dan, this if statement and nested if statement is complete, but we do need to create an else fall the first if statement here, because if the age is less than 18, we need to also count that and also given output for that. So I'm going to copy this line here and paste it like so. Except now I'll say no entry instead of entry. I was still be counting this entry to the turtles account into plus, plus. And I'll be adding to nerve entries. Values were so no entry and this would be plus, plus semicolon. And that should be it for the else statement. And in fact, this loop, we have all that we need and done all that we needed to, we need only give the final output. Be sure to note that the final output must be contained within this main if statement up here. Otherwise wrote him to give the output even if the user has stopped the program, which shouldn't present you with any errors because we have given values to all of these variables. Even though these values are blanks and zeros. But all the same, It'll be better just to have our final output in the if statement so far. But I'm going to create three system out print lands. You can do all this in one system out print line. But to make sure that the code is neat and easy to understand our sacrificed the two extra lines of code just to make sure it's easier to read. So System.out.print lamb. Firstly, I'm gonna do is start a new line after this because I wanted to be a space between the initial names and the final output. And in this one, we count the entry, so that's entry. The B plus. And now this is where we give the percentage of how many admitted into the program. So I have a bracket here plus another set of records which will contain all math and other secretive brackets in between as well. In a set of brackets. Yeah, I've entry and a school db divided by count underscore MPT, like so. And this should work out because entry is a double. Whereas if it was an integer, we might encounter some problems. And we terms about 100 to get the percentage. Plus double quotations to each sun centered brackets, space, got a ticket or some other dialogue which fits this app, Whitlam. Now I'm going to copy this here as we're going to use similar land. So system.out.print line, like so. I'm gonna paste that line in here and adjusted accordingly. This town will be no entry. So it would be no entry in here as well. Looney and symptom. And with that, we create our final output, which will print out the name and age of the oldest movie viewer. So put old Ionesco SDR plus something like was the oldest. Brackets x. So plus oldest underscore int, which will paste the age of the oldest. Russ. And I ended up with another set of brackets. Those are final outputs. Take a moment to pause the video and have a look at them again, it is a bit thick with code, but with that program has come to an end as well, we're ready to test it out. I'm just going to zoom out the screen a bit more so you can read it, but clear me if at all in screen. So pause here to see the upper half of the code. And pause here to see the lower half of the code. But of course I will be providing this onset the back of the workbook if you are using it as well. With that said, I'm now going to test out this program. I have ten pieces of data to, to start out with. But before that, let's just test out to see if this program stops. Sars happened stop. And nothing is outputted. And when I start running the program, attack to start, and it goes straight to the first input dialogue. So the program has started properly. I'm now getting into n a data. Give this example, Datta and a workbook. You can just add to that or you can make up your own data to, to start the program. And they haven't Harrington Starr this program i n to the n ten pounds of data. I'm just going to assume as well so you can see it a bit better. And this is the final output. So our first started retransmits who'd be the oldest and as you can see, they were allowed entry into the program. However, for Robert's chances at Ingram over here, they were not charged entry as they were too young. The race did meet the age requirements, so made it into the program received ticket. And as you can see in the final output, I have counted all these applicants. I have yes, seven, so 70% got a ticket to a movie, while three of the ten or 30% did not get a ticket. And John Smith's being the oldest, was 78, and he is stated here below. So the program worked successfully. I hope tools to this well, and if you had any troubles are seen as answer many things but easier or helped clear up some points. Now before in this video, I want to talk about optimization and other ways of doing this program because there are many ways any programmer can complete this project. How many lines of code and variations? Syringe stress, if you're few lands or o perhaps many Lorenzo, and your program is still works. The fact of the matter is you completed your task and you've done so with yearn logical understanding of code. There are many ways we can simplify or improve this program. For example, we can remove lands that we don't need. For example, these two lands below here, I added here for neatness sake, but I could add them into the same system out print line and save myself two lines of code. Even though one of those lands will be incredibly long, or I could create a while loop around the age variable here. So that way the user has to enter in an age between 050, like we've done previously in this course. For simplicity sake, I don't wanna ask this much of you. And for this project you earlier to complete these tasks. If your program looks similar to man or has completed the same tasks successfully, then congratulations, you've completed your final project. I'll see you in the final video. We'll conclude to what you have learned in this course and talk about where to go from here. I'll see you then. Bye for now.
14. Conclusion to Beginner Java: Hello and congratulations. Having reached the end of this course and completing your exercises, you now have a beginner's understanding of Java programming. With practice, the code you have learned in this course will give you fantastic of logical understanding of how to program. It has this logical thinking that will help you solve problems when encountering errors, or better yet, avoid them altogether. It will help your creativity as well. Purging your ideas for programs into action with sound code. But now we're to go from here. At this point in your studies, you are ready to move on and study more difficult code. This beginner course has given you an understanding of how code fits together. But there is more to learn than loops and if statements. However, I cannot understate your achievement. You have taken the first and hardest step into the world of programming. Continue your studies, develop ideas for programs, and use them to put your knowledge to the test. Thank you for joining me in this course and happy programming.