If there is one prayer that you should pray/sing every day and every hour, it is the
LORD's prayer (Our FATHER in Heaven prayer)
- Samuel Dominic Chukwuemeka
It is the most powerful prayer.
A pure heart, a clean mind, and a clear conscience is necessary for it.
For in GOD we live, and move, and have our being.
- Acts 17:28
The Joy of a Teacher is the Success of his Students.
- Samuel Dominic Chukwuemeka
I greet you this day,
For My Students, please do the following:
First: Download and install the NetBeans Integrated Development Environment (IDE), or any suitable IDE for Java.
Second: Review the notes for each week including the Student-Teacher scenarios.
Third View the videos for each week as applicable.
Fourth: Complete the weekly DB (Discussion Board) assignments.
Fifth: Assess your understanding for each topic.
Sixth: Begin to work on your midterm project, final project, and final exam.
Seventh: Review the midterm exam and final exam study guides.
Eighth: Should you have any questions, comments, concerns, areas of improvement, and constructive criticisms;
please contact me via the school's email system.
Ninth: If you are majoring in any IT (Information Technology) field
(especially for women and minorities),
you may want to check the Financial Aid section in any of my websites:
Scholarships or
Scholarships
For My Students and Visitors:
Comments, ideas, areas of improvement, questions, and constructive criticisms are welcome.
For All Those who Seek Peace:
Thank you for visiting!
Samuel Dominic Chukwuemeka (SamDom For Peace) B.Eng., A.A.T, M.Ed., M.S
(1.) Please review the
Rules of Nettiquette
(2.) Please be creative.
Please paraphrase in your words as applicable.
(3.) No two posts should discuss the same thing.
Each post should be unique.
This implies that you should review any previous posts before you submit your own post.
(4.) The initial post is due on Thursday of the week for which it is required.
(5.) At least one response to the initial post is due on Saturday of the week for which it is required.
(6.) Only one thread per student is allowed.
Please do not create more than one thread.
Please respond to my comments (as applicable) in the same initial thread.
Please make any repost in the same initial thread.
Besides the Introduction DB (where I am required to welcome each student); usually, I make comments to some posts and some
responses submitted by Thursday of the week that a DB assignment is due.
If I make any comment to your initial post and/or response (submitted by Thursday); then it is very important you address any
concern in my comments.
If you do not understand my comments, please send an email to me and ask for clarification.
I do not go back-and-forth (responding more than one time) to a student in DB forums.
The essence of DB forums is mainly for student communication and collaboration.
The professor only facilitates and makes few comments as necessary.
Typically, if I make any comment to your post and/or response for any DB assignment besides the Introduction DB,
it means that you need to fix some issues.
It is important you fix those issues to avoid deduction of points.
(7.) You may not do any of the same examples that I did for either a DB post or DB response.
(8.) You may do any of the questions in the Discuss tab as
a substantive post and/or substantive response.
(9.) You may make up your own substantive post and/or substantive response
if it is actually substantive.
If you do not know if your own post or response is substantive, please contact me via email,
and ask me for prior approval.
(10.) You may solve the problems in the Assess tab as a DB assessment (post and response).
Questions in the Assess tab count for both DB post and DB response.
Each question in the Assess tab is to be uniquely done by only one student.
This means that it can be done by more than one student.
However, each post must be unique.
Further: For Textbook Questions in the Assess tab:
(a.) Please submit a clear screenshot of the Question Number and the Question.
(b.) Any question from the textbook in the Assess tab should be done by only one student.
(11.) Sources must be cited accordingly.
You may use: APA (American Psychological Association) style, MLA (Modern Language Association) style, or the
Chicago Manual of Style.
(12.) For all applicable DB posts and responses, please use the Insert/Edit Image icon on the
Blackboard editor and insert screenshots of your code and the output.
Please submit clear screenshots.
This is because your colleagues and I should be able to see your code and the output clearly.
Line numbers and all necessary details are also required.
You may need to increase the font size of your IDE so it is very clear.
You may need to take the screenshots of only the relevant window (the code window).
You may need to take several screenshots.
Also, please ensure you use a clear format for your writings.
Avoid any background colors in the Blackboard Editor.
(13.) Please do not submit an attachment for any DB assignment.
If you do, it will not be clicked. It will not be read. It will not be graded.
Your colleagues and I should be able to see your work directly without opening any attachment.
Any response to such post will not be counted.
Hence clear screenshots are required.
(14.) For all DB responses, please mention the first name of your colleague.
(15.) Provide a substantive response to your colleague.
A substantive response is the response that provides constructive criticism,
alternative approach that gives the same correct output, addtional helpful information that will improve the post,
and the correction of any incorrect step and/or output among others.
How would you improve the initial post?
Did you find any errors in the initial post? If you do, please correct the error. Teach your colleague about the error, and
explain to him/her how to fix it. Provide screenshots as applicable.
What new knowledge can your colleague acquire from you based on your response?
Can you solve the initial post using an alternative approach that will give the same correct output?
What real-world examples/applications can you provide based on the initial post? Cite your sources accordingly.
Did your colleague learn anything meaningful from you based on your response to the initial post?
Please focus on the initial post. Do not deviate from the concept/topic in the initial post.
Do not bring up your own unrelated topic/concept.
Teach/Show your colleague something new and meaningful based on the initial post.
Write code examples of as applicable, run them, and explain to your colleague.
Substantive responses should include screenshots as applicable.
(16.) Please use at least a size of $14$ ($4$ pt) in your writings.
(17.) Please proof-read your writings for mechanical accuracy errors.
Any use of "i" attracts deduction of points.
Multiple mechanical accuracy errors will lead to deduction of points.
I understand that this is not an English class. However, you are expected to write well.
(18.) Please make sure that you write comments for any program you submit.
Rule of Thumb for Comments (for academic purposes): Anyone (including those with little or no programming knowledge) should be
able to read your comments and have a basic idea of your program.
Do you read my comments? Of course, you should. I provide explanations in my comments.
Does it make sense? Yours should not be different.
Course using Java introducing concepts of software development, object-oriented event-driven programming, testing and debugging, simple and complex data types, language syntax and semantics. Prerequisite: None.
By the end of this course, you should be able to do the following:
(1.) Demonstrate best practices for designing end-user computing interfaces.
(2.) Discuss software development methodologies.
(3.) Use a programming or a scripting language to solve a problem.
(4.) Discuss significant trends and emerging technologies and their impact on our global society.
machine language, assembly language, low level language, high level language, IDE (Integrated Development Environment), text editor, compiler, development toolchain, linker, program,package, white space, braces, curly brackets, semicolon, variable, object, function, main function, integer, GUI, Graphical User Interface, Swing, Swing components, API, Application Programming Interface, NetBeans IDE, JFrame, application logic, program code, JavaFX, AWT, Abstract Window Toolkit, Event, Event Handler, Code,
Students will:
(1.) Download and install the NetBeans IDE or any suitable IDE for Java.
(2.) Discuss an overview of the Java programming langauge.
(3.) Write a simple program (Console Application) in Java
(4.) Write a simple program (Desktop Application) in Java
(1.) Textbook Chapter
(2.)
Lesson: Object-Oriented Programming Concepts: Practice the Questions and Exercises. Review the answers.
by Oracle
(3.) Java Intro;
Java Syntax; and
Java Comments
by W3Schools
(4.) Designing a Swing GUI in NetBeans IDE
by Apache NetBeans
(5.) Learning Swing with the NetBeans IDE
by Apache NetBeans
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(6.) Type Java in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(7.) Type Java in the search bar and view the results.
$00000$ | $10011110$ |
$00001$ | $11110100$ |
$00010$ | $10011110$ |
$00011$ | $11010100$ |
$00100$ | $10111111$ |
$00101$ | $00000000$ |
Teacher: Please look at the code above.
Do you understand that code?
Student: The bunch of zeros and ones?
I have no idea what those mean.
int num1 = 3, num2 = 7;
System.out.println(num1 + num2);
Teacher: What about this code?
Do you understand it?
Student: I do not fully understand it.
However, it makes much sense than the first code?
Teacher: Both codes execute the same tasks.
Ask the user to input those numbers. Add those numbers. Output the sum.
Which code is better?
Student: The second code of course.
Teacher: The first code is the machine code.
It is the machine language.
It is a low level language.
It is the language the computer understands directly without translation.
The second code is the high level language.
It is the language humans can read and understand better.
Hence, there is the need to compile or interpret the high level language to
the machine language
so that computers would do what we want them to do.
There are four platforms of the Java programming language.
They are:
(1.) Java Platform, Standard Edition (Java SE)
(2.) Java Platform, Enterprise Edition (Java EE)
(3.) Java Platform, Micro Edition (Java ME)
(4.) Java FX
For this course, we shall only focus on writing Java programs using the Java Platform, Standard Edition (Java SE)
For information regarding these platforms: please review:
The Java Programming Language Platforms
(https://docs.oracle.com/cd/E19798-01/821-1770/gcrkk/index.html)
Java is one of the high level languages that we can use.
It is a compiled language.
This means that it is translated into machine language that can be understood directly by the
system.
In that regard, a set of tools are needed.
The set of tools is known as development toolchain
The core of the development toolchain are a compiler and its linker.
The best way to compile and run Java programs is to use an Integrated Development Environment
(IDE).
An IDE typically has several development tools including a text editor and tool to compile Java
programs directly.
For this course, the NetBeans IDE (it is free) is highly recommended.
However, you may choose to use any IDE that you wish.
What You Need:
(1.) Java Development Kit (jdk) of the Java Standard Edition (Java SE) Downloads
As at today: 08/27/2020; the latest Java SE is Java SE $14$:
Java Development Kit
(www.oracle.com/java/technologies/javase-downloads.html)
Click the JDK Download link.
For Windows users, select the Windows x64 Installer.
It has the executable file (the file that has .exe extension): jdk-14.0.2_windows-x64_bin.exe
Click the executable file, download and install it on your computer.
(2.) NetBeans IDE (Integrated Development Environment)
As at today: 08/27/2020; the latest version of NetBeans is the Apache NetBeans:
NetBeans IDE
Click the Download click on Download link.
If you do not know how to download and install any of these, please view the video.
Other ways to download, install, and run java programs:
(1.) Oracle
Tutorials
(2.) Java Get Started
If you are using the NetBeans IDE:
Please:
(1.) Review the screenshots of Module $1$ to increase the font size of your code in the IDE
(2.) Review the screenshots of Module $3$ to increase the font size of the output of your program in the IDE
Let us review each of these features.
If you do not get it now, no worries. You will get it later as you begin to work with it.
Let us begin with the Projects menu tab
So, we have created our first project named Module1
Note that it starts with an uppercase letter. The naming is either an uppercase or a Pascal case.
No worries, we shall discuss naming systems in the next module.
The java file in the project is Module1.java
It has the name of the project with the extension, .java
So, all java files has the .java file extension attached to the project name.
Analyzing Module1.java:
Lines $1 - 5$: Notice the words in those lines are blurred.
Those words are comments.
The comments are multi-line comments
So, you write a multi-line comment in Java by starting with a forward slash and an
asterisk and ending with an asterisk and a forward slash in that order.
Lines $8 - 11$ and Lines $14 - 16$ are also multi-line comments.
A multi-line comment is also known as a block comment.
Notice also that the words in Line $18$ is blurred.
However, Line $18$ is a single-line comment
You write a single-line comment in Java by writing two forward slashes before writing the
comments.
This is the same way we write single comments and multi-line comments in C++, C# and some other programming
languages.
Comments are required for any Java program you write in this course.
Rule of Thumb for writing comments (for academic purposes): Any person reading your comments should at a minimum, understand your
program and what your program is expected to do; regardless of the technology level proficiency of the person.
Please keep that in mind.
Please ensure you review the comments we write in our programs
Typically, every Java application program is inside a package.
A package is a namespace for organizing classes and interfaces.
Every code that runs in Java must be inside a method.
That method must be inside a class.
That class, typically should be inside a package.
We use the package to organize classes.
As we add more functionalities to our program, we may need to create more classes.
The package is used to organize all those classes.
In lay terms: The package of classes in Java is similar to the folder of several files in your
computer.
In programming terms: The package of classes in Java is similar to the namespace of classes in C#.
The name of the package is lowercase of the name of the Java file.
It could also something like com.samuelchukwuemeka (Notice it is the reversed order of the website
name: samuelchukwuemeka.com)
You should notice this naming for some IDEs. However, with the NetBeans IDE we are using; the package is
module1
As mentioned earlier, every code in Java must be in a method.
That method must be in a class.
This implies that every code in Java must run inside a class
A class is used for creating objects.
An object is an instance of a class.
This implies that whenever we call a class, an object is created.
It can also be defined as a software bundle of related state and behavior.
So, the Java programming language is an object-oriented programming language because it uses classes
to create objects.
If you do not understand these terms now, do not worry.
As we progress through the course and use them, it will begin to make sense...hopefully :-)
The name of the class must be the same as the name of the Java application or the file name
(without the extension).
This implies that the name of the class must be uppercase or Pascal case (as we mentioned earlier regarding the file
name).
In our case, it is Module1
Notice the public keyword before the Module1 class.
The public keyword is an access modifier
This means that that class can be used by other classes.
Student: Do we have private classes?
Teacher: Good question.
Our main class, the top-level class that has the same name as the file name must be public
However, we can have other classes inside that class (inner classes) that we can declare as private
Student: Are those the only two types of classes we can have?
Teacher: I guess the correct term would be: are those the only two access modifiers we have in Java?
We have another one: protected
We shall discuss these in details as we make progress.
So, we know that:
(1.) The name of the Java application must be uppercase or Pascal case.
(2.) The file name must be the name of the Java application with the .java extension.
So, the file name must be uppercase or Pascal case.
(3.) The package name must be lowercase or Camel case.
Typically, it is the lowecase form or the Camel case of the Java application.
(4.) The class name must be the same as the file name (without the extension, .java)
This implies that the class name must be uppercase or Pascal case.
Back to the comment in Line $18$: // TODO code application logic here
Any code we write inside that section will run.
That section begins from Line $17$ and ends on Line $19$.
It is known as the main method...Notice the bold italicized word in Line $17$, main
Any code inside the main() method will be executed.
So, we shall write our first code here.
We shall delete those default comments, write our own comments; and write our code.
To output our code/print the outout, we shall use the function
System.out.println("the output goes in here");
Our first code is THANK GOD
To print it, we write: System.out.println("THANK GOD");
Before we write our first code, I think it is better we change the font size of what se see now.
Let us make it bigger.
You can also change the comments, foreground color, and background color among others.
So, here are the steps to do that.
Let us go ahead and write code, and debug it.
If it passes debugging, then we run our it.
Example 1:
Student: It ran while you debugged it.
You did not click the Run menu.
Teacher: That is correct.
Student: So, does it matter if we run it right away?
Teacher: Yes, it does.
The essence of debugging is to check for errors.
If there are errors, you fix those errors before you run the program.
If there are no errors, then you run the program.
Student: So, what is the difference if we just run it?
Teacher: There will be no debug in the output.
Let's do it.
Example 2:
Example 3:
It will be nice to always put a new line or two new lines after our output.
This is done to separate the output.
We use the escape sequence, \n to insert a new line.
We can also click the green right arrow, the Run icon to run our program.
Example 4:
Example 5:
Let us review more code examples. Run the codes to see the output.
// Example 1: Write two different sentences on the same line
package module1
public class Module1{
public static void main(String[] args) {
System.out.println("Java is a programming language. It was developed by Oracle.\n\n");
}
}
// Example 2: Write two different sentences on two different lines using two System.out.println commands
package module1
public class Module1{
public static void main(String[] args) {
System.out.println("And now these three remain: faith, hope, and love. \n");
System.out.println("But the greatest of these is love.\n");
}
}
// Example 3: Write two different sentences using one System.out.println command
package module1
public class Module1{
public static void main(String[] args) {
System.out.println("And now these three remain: faith, hope, and love.\nBut the greatest of these is love.\n");
}
}
// Example 4: Write two different sentences using one System.out.println command
// But insert a blank line between the first line and the second line.
package module1
public class Module1{
public static void main(String[] args) {
System.out.println("And now these three remain: faith, hope, and love.\n\n"
+ "But the greatest of these is love.\n");
}
}
Please review the Teacher-Student scenario
Student: Mr. C, why do we need to develop desktop application?
Can't we just focus on console applications?
Teacher: Desktop applications are required for several DB assessments and for your Midterm Project.
It is optional for your Final Project.
It is important you learn to develop them.
Student: But, why?
Teacher: These are the reasons:
(1.) GUIs (desktop applications) cover a significant aspect of Number (1.) of the Student Learning Outcomes of the
course.
They also cover some aspects of Numbers (2.), (3.), and (4.)
(2.) You can run the executable JAR (.jar) file of a desktop application in any desktop/laptop that has
Java installed in it (both Windows and Mac)
Student: What are executable JAR files?
Teacher: Good question.
When you develop a Java program with Swing components such as the one we shall develop in a moment,
an executable file can also be developed. It is a file that is run on your computer to execute (do) something on your computer.
When you download and install a program on your computer (Windows users), it is normally seen as install.exe,
setup.exe or other "something".exe with the word, Application used to describe it.
In our case, it is going to be a standalone file with the jar extension described by
Executable Jar File that when downloaded in any desktop, can run when double-clicked.
Usually, you will get a warning from your computer not to download it because it can destroy your computer.
If you do not know the source/origin of the executable file, do not download it.
But in this case, we shall develop the program so we know it is safe.
When we develop the program, we need to follow these steps to locate the executable file.
Double-click: Application folder $\rightarrow$ dist $\rightarrow$ Application.jar
That Application.jar file is the executable file.
You can download it (no worries, it is safe), save it on your desktop, and run it on your desktop whenever
you want to.
Student: If I copy it to another desktop, will it run?
Teacher: Yes, it will run on any desktop provided that Java is installed on that computer.
That is the nice thing about it.
Student: Just that file?
It will run with all the functionality?
Without copying the entire folder?
Teacher: That is correct.
Click these links and review some of the desktop applications done by my students:
VB desktop applications and
C# desktop applications
These will run without any additional download.
Desktop applications are much better than console applications.
If you click the PROJECTS tab of this website and review the console applications done by my students,
you will realize that you need to type at least one command in the console before you can run the application.
If you review the PROJECTS (console applications) done by my C++ students,
it may require some program downloads to run on your machine (laptop/desktop).
You do not have to worry about typing commands or extra downloads when running desktop applications.
Student: Pretty cool.
Teacher: Yes, it is.
(3.) Assume you are working in a developing country (in Nigeria for example), you have a computer but no
internet service, and you really need to develop applications for the projects you are working on;
developing desktop applications is highly recommended in such cases because you do not need the Web/Internet
to run them. All you need is a laptop or desktop.
Student: But, I'm not working in Nigeria.
Neither do I intend to work there.
Teacher: What if you work for a multinational company and your compnay transfers you to work there?
What if you decide to join your church or organization on a charity mission trip?
(4.) Have you heard that the only thing that is not safe is anything on the Web?
Well-developed desktop applications minimizes your use of web and mobile applications, thereby minimizing cyber crimes.
There are limitations with desktop applications.
But, there are advantages too.
One of the advantages of Java is the developement of Desktop aplications.
Let me welcome you, my dearest students with a desktop application. 😊
As is the case for development of desktop applications, the three basic things to do are:
(1.) Create the user interface
(2.) Set the properties.
(3.) Write the program code.
The Swing API (Application Programming Interface) is used with the NetBeans IDE to develop Java desktop
applications.
JavaFX or AWT (Abstract Window Tookit) can also be used with NetBeans for GUI programming.
However, we shall be using the Swing API for this module.
JFrame Form
The form consists of:
(1.) Source Area (Source Window or Source View): This area contains the source code/program code/application
logic for the form.
(2.) Design Area (Design Window or Design View): This area contains the form.
I prefer Absolute Layout for the form because it implements a proportional positioning and sizing of the form
elements. Hence, I right-clicked on the form and selected Absolute Layout
However: please do not select any layout for your Midterm Project and Final Project
Student: Mr. C, you selected a layout for your application.
But, you asked us not to select any layout.
Hmmmm...why?
Teacher: I shall delete the layout later.
I just wanted to teach you about layouts.
Student: But why?
Teacher: Good question.
Layouts besides the Free Design layout require libraries.
When you publish an executable JAR file, the file will not work without the library.
I want a single executable file that anyone can click and run.
(3.) Palette: This area contains the tools/form elements.
It is similar to the Toolbox in the Microsoft Visual IDE. It consists of:
(I.) Swing Containers
(II.) Swing Controls
(III.) Swing Menus
(IV.) Swing Windows
(V.) Swing Fillers
(VI.) AWT: This is also used for GUI programming. It is Java's original GUI toolkit. We shall not use it for any of
our
tools. We shall be using Swing components/tools.
(VII.) Beans
If you point your mouse on any element/component/tool, a pop-up information regarding that tool is displayed.
(4.) Property Editor: This area contains the properties of each component.
We can change several porperties of each component such as the name property, title property, font property,
background
color property, and foregraound color property among others.
The Property Editor also contains Events (including Event Handlers) menu and Code menu.
(5.) Inspector: The Inspector provides a graphical representation of the components.
Let us review what we have discussed so far.
Please review the screenshots.
Create the User Interface and Set the Properties
(1.) Click the [JFrame] in the Inspector
Change the title in the Property Editor by clicking the ellipsis icon and typing Welcome to
our
Java Programming Class
(2.) Click on the form.
Let us change the background color.
I prefer Bisque background color.
The hexadecimal value of bisque is #FFE4C4
(a.) Right-click on the form and click Properties
(b.) Change the background property to the Color Code: #FFE4C4 under the RGB menu.
Teacher: It did not work.
The background color of the form has not changed.
Why is that?...speaking like an American lol
Student: Mr. C, you are asking me...seriously?
Teacher: Yes, I am asking you.
So, you can Bing it or Google it
Student: Okay Sir.
What should I type?
Teacher: Jframe form Swing NetBeans IDE background color not working
Look for any result from Stack Overflow
Student: What is Stack Overflow?
Teacher: It is Question-and-Answer forum for Computer Science.
The link is among the resources on the course website.
Student: Wow...pretty surprised you didn't answer me back with a set of questions.
Teacher: The questions I ask is meant to help you... to review all the resources I provide and to be a
problem solver and encouraging independent learning.
Programmers are problem solvers, you know.
Please do not take it in a bad way or rude way. The questions are meant to ensure that you understand all the
course
requirements and expectations.
Student: Whatever Mr. C
Teacher: What did you find? 😊
Student: There are several options I see here.
Teacher: Which option do you prefer?
Student: I think I prefer this one: adding a panel to the form and then changing the background color of
the
panel.
In this case, I think we should cover the entire form with the panel.
Teacher: Cool. Let's go for it.
Student: But, what is a panel?
Teacher: We'll see.
Just point your mouse to the Panel component to see what it is.
Then, click and drag it into the form and cover it.
(c.) Click the Panel component found in the Swing Containers and Drag it inside the form.
(d.) Adjust it to cover the entire form.
(e.) Right-click inside the panel and select Properties
(f.) Change the background property to the Color Code: #FFE4C4 under the RGB menu.
(3.) Adjust the size of the form and the panel as well.
This is necessary to accommodate our application.
I would like to introduce myself to my students and welcome them to our class.
But, I want it to be a surprise.
You like surprises?
(a.) When the form loads, there should be nothing in the form but only three buttons: Display, Clear
and
Exit buttons.
When the user clicks the Display button, my Picture and the Welcome Message should be displayed
in
the form.
When the user clicks the Clear button, my Picture and the Welcome Message should be removed
from
the form.
When the user clicks the Exit button, the application should be closed.
(b.) So, I shall put my picture.
We do not have a Picture Box at the time of writing this application.
But, the Label in the Swing Controls can accept images.
So, we shall use the Label.
Adjust the size and display as you wish.
(c.) I have to write a Welcome to welcome them to our class, and also introduce myself.
The message will be written in multiple lines.
So, we shall use the Text Area
The Text Area is a multi-line area that displays plain text.
We shall change the font to Times New Roman and font size to $16$
Change the name to welcomeTextArea
(d.) We need the three buttons:
Change the name of the Display button to displayButton and the text to Display
Change the name of the Clear button to clearButton and the text to Clear
Change the name of the Exit button to exitButton and the text to Exit.
These buttons will perform some action when the user does an event such as the click event
For the three buttons: change the font to Times New Roman, the font size to $18$ and the background
color
to white
The hexadecimal value for white is FFFFFF
Select all three buttons using clicking on one and using the CTRL (Control key) to select the other two.
Set them to have the same width and height
Please review the steps in the screenshots.
Student: Mr. C, I hope you know the background colors of the three buttons did not change to white.
Teacher: No worries my dear. We changed it. You will see the change in the form when we run it.
Student: Is this not WYSIWYG? (What You See Is What You Get)?
Teacher: So, I clicked on each button (in the Design Area) and noticed that each of them has a white background.
When we run the program, we shall see the white background.
Program Code (Application Logic)
Now onto the functionality of the program.
This would be done in the Source Area
Please review the screenshots and the comments.
Remember we unchecked the Main Class when we created this project.
This is because our GUI program will be the Main Class.
We shall now select it as the Main Class.
Source Code
This includes my code and the auto generated code.
Do not worry about the auto generated code.
Focus on my codes and my comments.
My comments explained the codes.
Run the program
Click events by the User
Publish our GUI as a Desktop Application
This means that we have to create an executable JAR (Java ARchive) file.
To do this, we need to Clean and Build Project (Clean and Build the Introduction project) or press the
Shift + F11 keys on
your keyboard.
When this is done, the dist folder is created.
That dist folder contains the Executable JAR file.
Please review the screenshots.
This is the Introduction.jar executable file
You may click the link to download and run it. No worries, it is safe.
It is a desktop application.
If you have Java on your computer (PC or Mac desktop/laptop), click the file and run the application directly on your desktop.
Student: I have a question.
If I decide to make some changes to the code, will those changes be automatically reflected in the app
even though the app has been published?
Teacher: Good question.
Whenever you make changes to your program code, then you will need to Clean and Build Project again.
An updated executable jar file will then replace the previous one.
So, you will need to re-download the new file.
When you run the file, did you notice my picture is not diplayed even when you click the Display
button?
This is one of the reasons why I ask you not to include pictures in your desktop applications for the
Midterm Project and the Final Project.
Please do not include any picture in your Midterm Project and Final Project applications.
(1.) Discuss a brief history of Java.
(2.) Discuss the versions of Java including any significant change made for each version.
(3.) Discuss any console application developed with Java.
(4.) Discuss any desktop application developed with Java.
(5.) Discuss any web application developed with Java.
(6.) Discuss any mobile application developed with Java.
(7.) Discuss any IDE for Java including the advantages and disadvantages.
(8.) Explain using appropriate examples, any three new terms learned this week.
(9.) Compare any three features of Java with any similar object-oriented language.
(10.) Contrast any three features of Java with any similar object-oriented language.
(11.) Write two different sentences on two different lines.
Insert a blank line between the first line and the second line.
Do NOT use the escape sequence.
(1.) Include any "missing gaps" in the history of Java.
(2.) Include any "missing gaps" in the versions of Java.
(3.) Discuss an additional console application developed with Java.
(4.) Discuss an additional desktop application developed with Java.
(5.) Discuss an additional web application developed with Java.
(6.) Discuss any mobile application developed with Java.
(7.) Discuss any IDE for Java. Include the advantages and disadvantages.
(8.) Add to the post of the student who explained any three new terms learned this week.
(9.) Add to the post of the student who compared three features of Java with another
object-oriented langauge.
(10.) Add to the post of the student who contrasted three features of Java with another
object-oriented langauge.
(11.) Provide any of these if it is lacking in any DB post that solved any question in the
Assess tab of this module: Well-written comments; another approach/method to solving the
question; any additional relevant details; etc.
(1.) Develop a desktop application titled: Introduction
The application should include three buttons: the About button, the Clear button, and the
Exit button.
When a user opens the application, it should display a blank page and the three buttons.
When the user clicks the About button, these information should be displayed:
(a.) Your picture
(b.) A brief summary of you. Write at least three sentences about yourself.
(c.) One sentence about the course and your major/program.
(d.) One sentence about the course expectations/accomplishments. What is your expectation about the course? What
do you intend to accomplish at the end of the course?
(e.) Any other thing you would like us to know about you.
When a user clicks the Clear button, the page should be blank.
When a user clicks the Exit button, the application should close.
I am more interested in the functionality.
However, I am also interested in the design/graphics/aesthetics.
Make a good design.
vary, variable, identifier, data type, data value, value, container, ASCII (American Standard Code for Information Exchange), character (char), primitive data type, non-primitive data type, object, method, class, dot access operator, new line, size, storage, precision, type casting, widening casting, narrowing casting
Students will:
(1.) Discuss the meaning of variables in Java
(2.) Discuss the data types in Java
(3.) Discuss the rules for using identifiers.
(4.) Write Java programs that involves the use of variables and data types.
(1.) Textbook Chapter
(2.) Java Variables, Java Data Types, and Java Type Casting by W3Schools
(3.) Operators by Oracle
(4.) Conversions and Contexts by Oracle
(5.) Designing a Swing GUI in NetBeans IDE
by Apache NetBeans
(6.) Learning Swing with the NetBeans IDE
by Apache NetBeans
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(7.) Type Java Variables and/or Java Data Types in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(8.) Type Java Variables and/or Java Data Types in the search bar and view the results.
A Variable is a portion of computer memory for storing a data value.
Because a variable stores a data value, it is important to identify the type of data value it
stores.
This implies that any variable is associated with a data type.
The data type describes the type of data value stored by the variable.
What type of data is being stored? Are they numeric (numbers), non-numeric
(letters/characters/words), etc.?
As noted with the word: variable, any value stored by it can vary (can
change).
A variable is created/declared in Java by specifying the data type associated with it and
assigning it to a value.
We declare a variable this way:
datatype variable = value
The equal sign is the assignment statement.
In other words, you assign something in Java using the equal sign.
Let us review the data types in Java.
Data types in Java are:
(1.) Primitive data types
(2.) Non-primitive data types.
A primitive data type is the data type that specifies the size and type of the values
of the variable.
It is predefined in the Java language. This means that it is already defined in the Java language.
It always has a value. It cannot be null.
When a primitve data type is declared, it always begins with a lowercase letter.
Primitive data types have various sizes depending on the data type. The sizes are not the same.
It cannot be used to call methods.
As of today: 09/03/2020; there are eight primitive data types in Java.
They are:
Primitive Data Type | Declaration | Size | Description |
---|---|---|---|
(1.) Integer (Byte) | byte | $1$ byte ($8$ bits) | Integers from $-128$ to $127$ are stored |
(2.) Integer (Short) | short | $2$ bytes ($16$ bits) | Integers from $-32,768$ to $32,767$ are stored |
(3.) Integer (Integer) | int | $4$ bytes ($32$ bits) | Integers from $-2,147,483,648$ to $2,147,483,647$ are stored |
(4.) Integer (Long) | long | $8$ bytes ($64$ bits) |
Integers from $-9,223,372,036,854,775,808$ to $9,223,372,036,854,775,807$ are stored NOTE: End any integer declared with the long data type with an uppercase L |
(5.) Floating Point (Float) | float | $4$ bytes |
Up to $7$ decimal places are stored. NOTE: End any decimal declared with the float data type with a lowercase f |
(6.) Floating Point (Double) | double | $8$ bytes |
Up to $15$ decimal places are stored. NOTE: End any decimal declared with the double data type with a lowercase d |
(7.) Boolean | boolean |
$1$ bit $0$ = false, $1$ = true Make the connection with electronic devices. $0$ = Off; $1$ = On |
Only false and true values are stored Displays as $0$ and $1$ respectively |
(8.) Character | char | $2$ bytes |
Only a single character/letter is stored. The decimal values of ASCII characters/values are also stored. NOTE: If you intend to use the decimal values of ASCII characters/values, you must declare it with the char data type and the decimal value should not be included in quotation marks. |
Student: You have talked about size. But, you said it cannot call methods.
May you please explain?
Teacher: We shall discus it later.
Let us look at non-primitive data types.
Student: That is the issue.
I get lost when you keep going.
Is it not better to explain any concept you mention? Also give examples.
Teacher: No worries.
Let us look at the non-primitive data types.
The non-primitive data types can call methods/functions.
Then, we discuss variables.
Then, we can review some examples.
Student: Now, you mention functions
Teacher: A method is a function
There are some concepts we shall mention, but not discuss immediately.
We shall discuss those concepts in later modules.
Some of those concepts would be discussed in the next course.
A non-primitive data type is the data type that refers to objects.
Because it refers to objects, it is also known as a reference type.
When a non-primitve data type is declared, it always begins with an uppercase letter.
Non-primitive data types have the same size.
They are used to call methods.
Besides the String data type, all other non-primitive data types are not predefined in the Java language.
They are defined by the programmer. This implies that the String data type is the
only non-primitive data type that is predefined in the Java language.
Non-primitive data types may or may not have a value. They can be null.
Examples of non-primitive data types are: Strings, Arrays, Classes, and Interface
among others.
Let us review the variables in Java.
Java variables are identified with unique names known as idenfiers.
It is important to use identifiers that are meaningful and descriptive.
Anyone reviewing your program should not have to guess the meaning of your variable.
As you can see (based on the image below: Variables, Data Types, Values:)
The variables I used in that example are meaningful and descriptive
Those variables are:
state to denote the State of Ohio, OH
numState to denote the number of the State of Ohio in an alphabetical listing of the
state names
povertyRate to denote the poverty rate of Ohions according to the $2000$ census data
landArea to denote the land area of the Ohio according to the $2000$ census data
motto to denote the motto and seal of the Great State of Ohio
ismottoTrue to denote the Boolean data type if the motto is true
Even without the comments, you already have an idea of the meaning of my variables.
I should not have to guess the meaning of your variables.
Variable names:
(1.) Can be single letters (please avoid unless if used in loops)
(2.) Can contain a combination of letters, digits, and underscores but must not begin
with a number.
It may begin with a letter or an underscore.
(a.) Please avoid underscores
Avoid underscores even if the variable name does not begin with an underscore.
(b.) Use a combination of letters and digits such as:
num1 to represent the first number
variable1 to represent the first number
(3.) Can contain only letters but must not be any of the reserved keywords.
The reserved keywords that are still in use are:
abstract, assert, boolean, break, byte, case, catch, char, class, continue, default, do, double, else, enum,
extends, final, finally, float, for, if, implements, import, int, interface, long, native, new, package, private,
protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient,
try, void, volatile, while
The reserved keywords that are not in use are:
const, goto
The const keyword is replaced with the final keyword.
NOTE: You cannot use any of the reserved keywords as an identifier/variable name regardless of whether
they are in use or not in use.
(a.) The letters can be Camel case (similar to the hump of a camel) such as:
firstVariable...the V is the hump
In Camel casing letters: two letters are merged as one; the first letter of the second word is
an uppercase letter while all other letters are lower case letters.
In firstVariable, V is uppercase; all other letters are lower case
(b.) The letters can be Pascal case such as FirstVariable
In Pascal casing, two letters are merged as one; the first letter of the first word and the
first letter of the
second word are uppercase letters while all other letters are lower case letters.
In FirstVariable, F and V are uppercase; all other letters are lowercase.
(c.) uppercase letters (please avoid...it denotes someone who is yelling)
(d.) lowercase letters (okay, but try to avoid)
Student: What if you have three words?
How do you write it in Camel case? Pascal case?
Teacher: Say we want to write the variable, first arithmetic sequence
Camel case: firstArithmeticSequence...A and S are the only uppercase
Pascal case: FirstArithmeticSequence...F, A, S are the only uppercase
In this course, for all applicable variables; please use:
(i.) A combination of letters and digits such as num1 OR
(ii.) Camel case letters such as firstNumber OR
(iii.) Pascal case letters such as FirstNumber
***We shall use single characters when we write conditions for Iteration statements/Loops
because it is
easier to use single characters in such cases. We shall see examples when we discuss loops.
However, feel free not to use it if you wish.***
(4.) Can contain only letters but must not be these literals: true, false, null
(5.) Cannot contain whitespaces or special characters.
The special characters are all the non-numeric and non-alphabet characters on your keyboard such
as ~ (tilde), !(exclamation), @ (asperand), # (hash), $ (dollar), % (percent), ^ (caret), & (ampersand), *
(asterisk).
A whitespace is a horizontal or vertical space.
For example: myNum has no whitespace; but my Num has a whitespace.
Variable names cannot contain whitespaces.
Hence: myNum is acceptable, but my Num is not acceptable.
Declaring Read-Only Variables: Use the final keyword (constant keyword)
As we have learned, a variable vary. The value changes.
However, read-only variables do not change.
Sometimes, we need these kind of variables.
We have to create/declare them using the final keyword.
For example, if we want to use the approximate value of pi as $3.142$ rather than using the
exact value, we can declare it as:
final int $piValue = 3.142$
This means that the variable, piValue is a read-only variable
It will not change it's value.
Student: May you please give code examples?
Teacher: Sure.
Let us review these two examples.
We shall create a new project, Module 2
So, we have two projects: Module 1 and Module 2
Before you run Module2.java, you will need to:
(1.) Close Module1.java from the code window.
(2.) Open only Module2.java in the code window.
(3.) Click the Run menu tab. Then, click Clean and Build Project (Module 2)
Do these steps whenever you create and want to run a new project without deleting any previous projects.
Go ahead and run it anyway to see the output for the value of piValue2 (just for this case. Please do not run any program that compiles with any error).
As you can see, the variable $piValue2$ cannot be changed because it was declared as a read-only
variable (using the final keyword)
Teacher: As you see: for the new value of piValue1, we can modify the value of any variable we create, by specifying another value for that same variable name.
Student: But, why do we need to do this?
Can't we just create another variable with that second value?
Teacher: Good point.
Yes, it is much better to create another variable with the new value.
However, when we work with statements and sorting techniques among others; it may be more efficient to just assign the new value to the same variable; rather than create another variable and assign the new value to it.
For example: if you are sorting through a loop also known as an iteration statement; we can create a variable, and write a conditional statement that when you compare an element in the array with the next element; assign the value of the greater element to the variable.
Rather than create a new variable, assign any greater value to the variable as you compare elements in the array.
There are some terms I just used, that we shall discuss in later modules.
(6.) Are case sensitive.
These are all different variables:
firstresult (lowercase), firstResult (Camel case), FirstResult (Pascal case), Firstresult,
FIRSTRESULT (uppercase),
first_result (snake case)
Let us review more variable examples in Java
A variable can store the number, say $5$ in a line of code; and the same variable can store a
different number, say $7$
in another line of code.
So, the values stored by a variable can change.
An example with integers:
An example with strings:
Teacher: Back to your question regarding a method
Did you notice we used the println() method and the lineSeparator() method?
We used the System class to call those methods using the dot access operator.
The period punctuation mark is known as the dot access operator.
Student: So, the method belongs to that class?
Teacher: That is correct.
Hence we were able to call it.
Student: So, what is a class? Also, you mentioned object initially?
Teacher: We create a class in Java.
When we want to use that class, we have to call it.
Calling that class means creating an object.
We shall discuss these terms later.
Student: So, what you are saying is that primitive data types cannot call a method, but non-primitive data types can?
Teacher: That is correct.
Student: May you show me an example?
Teacher: Please wait. When we discuss Strings, we shall review examples.
Student: What is the red vertical line in the code window?
It also appears in the screenshots.
It seems to be a problem with the NetBeans IDE.
Teacher: That vertical line is the Right Margin.
Let us remove it.
Tools --> Options --> Editor --> Formatting --> Uncheck All Languages Settings --> Change the Right Margin to 0 --> Apply --> OK
Please see the images.
Remove the vertical red line in the NetBeans IDE:
Variables, Data Types, Values:
Type Casting is the conversion of a value from one primitive data type to another
primitive data type.
Type casting in Java can be:
(1.) Widening Casting is the conversion of a value from a smaller primitive data type to a
larger primitive data type.
byte to short byte to char byte to int byte to long byte to float byte to double short to char short to int short to long short to float short to double char to int char to long char to float char to double int to long int to float int to double long to float long to double float to doubleThis is done automatically.
double to float double to long double to int double to char double to short double to byte float to long float to int float to char float to short float to byte long to int long to char long to short long to byte int to char int to short int to byte char to short char to byte short to byteThis is done manually.
As usual, we shall develop desktop applications that involves the use of variables and data types.
Let us develop desktop applications for the console application we did for the State of Ohio
We shall use several toolboxes (Palette tools).
Remember that the Midterm Project is a desktop application.
Hence, it is necessary to start getting familiar with GUI programming.
Please review the desktop application we did in Module $1$ to understand the basic steps.
We shall give appropriate names for our projects.
JFrame Form: Adjust and Align
title property: State of Ohio: Labels and Buttons
Palette | Property |
---|---|
Panel Adjust and Align to cover entire JFrame Form |
background: RGB $\rightarrow$ Color Code: F5DEB3 (This is for the color: Wheat) font: Font: Times New Roman; Font Style: Plain; Size: 24 Change Variable Name: ohioPanel |
Label 1 (LHS): Adjust and Align |
text: State font: Font: Times New Roman; Font Style: Plain; Size: 24 |
Label 2 (RHS): Adjust and Align |
border: Etched Border Please see image below the table for illustration (Setting the border should be done first) Adjust and Align again font: Font: Times New Roman; Font Style: Plain; Size: 24 Change Variable Name: stateLabel |
Right-click the State label and Duplicate Please see image below the table for illustration |
text: Number |
Right-click the Label 2 and Duplicate Please see image below the table for illustration |
Change Variable Name: numberLabel Adjust and Align the Number text label to be in line with the numberLabel name label |
Select both the Number text label and numberLabel name label by: Clicking on them, holding
the CTRL key on your keyboard, and clicking on the other one. How do you know if it was done well? The Properties Area indicates Multiple Objects. Right-click Duplicate Both labels are duplicated. Please see image below the table for illustration Click on each label and make changes as noted below. Adjust size and Align as necessary. Do this for the rest of the labels. |
|
Duplicate Label |
text: Poverty Rate Change Variable Name: povertyRateLabel |
Duplicate Label |
text: Land Area Change Variable Name: landAreaLabel |
Duplicate Label |
text: Motto Change Variable Name: mottoLabel |
Duplicate Label |
text: Is Motto true? Change Variable Name: booleanLabel |
Button |
text: State of Ohio font: Font: Times New Roman; Font Style: Plain; Size: 24 background: RGB $\rightarrow$ Color Code: FFFFFF (This is for the color: White) Change Variable Name: ohioButton |
Duplicate Button |
text: Clear Change Variable Name: clearButton |
Duplicate Button |
text: Exit Change Variable Name: exitButton |
Set the border of the RHS Labels
Duplicate Labels
Duplicate both Labels at the Same Time
We discussed the other tasks in Module 1.
(1.) Run the program and select OhioFlashcard1 as the main class.
Close the application and let us code the program.
(2.) In the Design Area, double-click the State of Ohio button.
This leads to the Source Area
Scroll all the way to the top and begin to ...
(3.) Write the code.
Please review the screenshots.
Review the comments.
Design Area
Program Code
Run the Program
In the previous application, I closed the Palette (Toolbox) Area and the Properties Area so I can have
more space for the interface.
I used a laptop and I needed more space in the Design Area
To view the Palette and the Properties Area, please click: $Window \rightarrow IDE\;\;Tools \rightarrow Palette$ and
$Window \rightarrow IDE\;\;Tools \rightarrow Properties$
It is also shown in the screenshots below.
Please review the previous GUI applications.
JFrame Form: Adjust and Align
title property: State of Ohio: Text Area and Buttons
Palette | Property |
---|---|
Panel Adjust and Align to cover entire JFrame Form |
background: RGB $\rightarrow$ Color Code: FFF8DC (This is for the color: Cornsilk) font: Font: Times New Roman; Font Style: Plain; Size: 24 Change Variable Name: ohioPanel |
Text Area: Adjust and Align |
font: Font: Times New Roman; Font Style: Plain; Size: 24 Change Variable Name: ohioTextArea |
Button: Adjust and Align |
text: State of Ohio font: Font: Times New Roman; Font Style: Plain; Size: 24 background: RGB $\rightarrow$ Color Code: FFFFFF (This is for the color: White) Change Variable Name: ohioButton |
Duplicate Button: Adjust and Align |
text: Clear Change Variable Name: clearButton |
Duplicate Button: Adjust and Align |
text: Exit Change Variable Name: exitButton |
(1.) Run the code and select OhioFlashcard2 as the main class.
Close the application and let us code the program.
(2.) In the Design Area, double-click the State of Ohio button.
This leads to the Source Area
Scroll all the way to the top and begin to...
(3.) Write the code.
Please review the screenshots.
Review the comments.
Design Area
Program Code
Run the Program
We shall explore more Palette tools (toolbox controls) in subsequent modules.
(1.) Using at least five complete sentences and at least five different variables and data types,
write a program of the summary of what you learned in this module.
(2.) Write a program of a short story, a poem, or drama using at least five sentences and at least five different variables and data types.
(3.) Write a program that displays examples of all the Primitive data types and the String data type.
(4.) Write a program that demonstrates at least ten examples of Widening Type Conversions
Use the data types listed in this Module.
(5.) Write a program that demonstrates at least ten examples of Narrowing Type Conversions
Use the data types listed in this Module.
(6.) Write a program of a short story, a poem, or drama using at least five sentences, the same variable,
and at least three different data types.
For Question (7.)
Please review: Conversions and Contexts
(https://docs.oracle.com/javase/specs/jls/se10/html/jls-5.html) for the other conversions.
Specific type conversions in the Java programming language are divided into 13 categories.
(I.) Identity Conversion
(II.) Widening Primitive Conversion
(III.) Narrowing Primitive Conversion
(IV.) Widening and Narrowing Primitive Conversion
(V.) Widening Reference Conversion
(VI.) Narrowing Reference Conversion
(VII.) Boxing Conversion
(VIII.) Unboxing Conversion
(IX.) Unchecked Conversion
(X.) Capture Conversion
(XI.) String Conversion
(XII.) Forbidden Conversions
(XIII.) Value set Conversion
(7.) Using at least five complete sentences and at least five different variables and data types,
discuss any of the conversions that we did not discuss in this module.
(8.) We have discussed several ways of displaying the output in a new line.
Please review all the comments in the screenshots.
Do you know of any other way/ways we can display the output in a new line besides what we discussed?
What are those ways?
Write them. Run your code and display the output.
(9.) We have discussed at least two ways of printing a decimal with a % (as seen in the povertyRate variable).
Please review all the comments in the screenshots.
Do you know of any other way/ways we can print a decimal with the percent sign besides what we discussed?
What are those ways?
Write them. Run your code and display the output.
Textbook Questions
(10.) Question $4$ on Page $106$
(11.) Question $6$ on Page $106$
(12.) Question $8$ on Page $106$
(13.) Question $10$ on Page $107$
(1.) Provide any of these details if they are lacking in any DB post:
Well-written comments; another approach/method to solving the question; any additional relevant details; etc.
(2.) Other substantive responses.
(1.) Develop a Graphical User Interface (GUI) of a short story, a poem, or drama using at least five sentences and
at least five different variables and data types.
At least three buttons: the button that displays the information, the Clear button and the
Exit button should be included.
Include access keys for the three buttons.
(2.) Develop a Graphical User Interface of a short story, a poem, or drama using at least five sentences,
the same variable, and at least three different data types.
At least three buttons: the button that displays the information, the Clear button and the
Exit button should be included.
(3.) Develop a GUI flashcard of all the Primitive data types and the String data type.
A brief definition of each data type should be displayed when the user performs an event
(such as pointing the mouse or clicking) on each data type.
Use whatever palette (toolbox controls) you prefer.
operator, operation, operand, operator precedence, assignment operator, arithmetic operators, addition operator, subtraction operator, division operator, remainder operator, modulo operator, compound assignment operators, unary operators, unary plus operator, unary minus operator, increment operator, decrement operator, increase, decrease, logical complement, logical operators, bitwise and bit shift operators, conditonal ternary operator, equality and relational operators, comparison operators, conditional operators, format specifier, input-output feature,
Students will:
(1.) Discuss the operators in Java
(2.) Perform operations on variables/values
(3.) Write Java programs involving the use of operators.
(1.) Textbook Chapter
(2.)
(A.) Operators by Oracle
(B.) Summary of Operators by Orcale
(C.) Questions, Exercises, and Answers by Oracle
(3.) Java Operators and
Java Math by W3Schools
(4.) (A.) Java User Input by W3Schools
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(5.) Type Java Numbers and/or Java Operators in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(6.) Type Java Numbers and/or Java Operators in the search bar and view the results.
Operators are special symbols that perform specific operations on one or more operands,
and returns an output.
An Operand is the variable/value on which an operation is done.
Operators | Symbols | Description | Code Examples |
---|---|---|---|
Assignment | $=$ | Equal sign |
int num1 = 7;
|
Arithmetic Addition Subtraction Multiplication Division Remainder (Modulo) |
$+$ $-$ $*$ $/$ $\%$ |
Add Subtract Multiply Divide Remainder after a division |
int num1 = 6, num2 = 2;
|
Compound Assignment Plus equal Subtract equal Multiply equal Divide equal Modulo equal |
$+=$ $-=$ $*=$ $/=$ $\%=$ |
Add, then equal to Subtract, then equal to Multiply, then equal to Divide, then equal to Remainder after division, then equal to |
int num1 = 5;
|
Unary Unary plus Unary minus Increment Decrement Logical complement |
$+$ $-$ $++$ $--$ $!$ |
The unary operators require only one operand. Unary plus operator example $+=1$ means Increase by one Unary minus operator example $-=2$ means Decrease by two The increment, ++ and decrement, -- operators can be: prefix or postfix (suffix) Prefix Increment (evaluate the value, after it is increased) Postfix (Suffix) Increment (evaluate the value, before it is increased) Prefix Decrement (evaluate the value, after it is decreased) Suffix Decrement (evaluate the value, before it is decreased) Logical complement operator inverts(negates) the value of a boolean |
int num1 = 9;
|
Conditional Ternary |
$?$ |
The Conditional ternary operator evaluates an expression amidst two results. If the expression is true, it returns the first result. If the expression is false, it returns the second result. The two results are separated by a colon : The expression is separated by the two results using the conditional tenary operator (question mark) ? The syntax is:
expression ? result1 : result2
|
int num1 = 5, num2 = 2;
|
Equality and Relational Equal to Not equal to Greater than Less than Greater than or equal to Less than or equal to |
$==$ $!=$ $\gt$ $\lt$ $\ge$ $\le$ |
Equality and Relational Operators are used to compare two expressions. The result is a Boolean (either true or false) |
int num1 = 5, num2 = 2;
|
Please review the rest of the Operators
Before we proceed: let us change the color of the comments
It is dull as it is
I want my students to read the comments clearly
Tools --> Options --> Fonts & Colors --> Category: Comment --> I need it to be Dark Green.
Dark Green is not an option.
However, so I click Custom --> RGB --> and put a value of $0, 100, 0$. That is the RGB value for darkgreen color
Please see the images.
Let us reduce the font size of the output to $16$.
Remember we increased it to $18$ in Module $2$
But, I think size $16$ is better.
Please see the images.
Let us review more examples of Arithmetic Operators and Math Functions.
A Simple Arithmetic Operation of Two Integers:
Teacher: Did you notice the quotient?
Student: Yes, Sir. I did.
That result is incorrect.
Teacher: Yes, it is.
Any suggestions?
Student: I think it is because it was declared as an integer.
Teacher: Correct.
How do we fix it?
Student: Declare it as a float?
Teacher: Let's see
Teacher: We ran into another problem.
Student: What problem?
Are those answers not correct?
Teacher: They are correct.
However, the sum, difference, and product are not really floats.
They are integers.
Student: Does it really matter?
$12.0$ is the same thing as $12$
Teacher: But, we want to display it as an integer.
What should we do?
Student I have no idea.
Teacher: We discussed it in last module.
Student Wait...let me check
Type casting?
Teacher: What type?
Student: Narrowing Casting
Teacher: Because?
Student: We want to convert from a larger type (float) to a smaller type (integer)
Teacher: That is correct.
Let's do it.
Student: That fixed it.
Teacher: It did.
But, not really.
Student: What do you mean by "not really", Sir?
Teacher: The floating type.
The precision of the floating data type...
is less than that of the double data type
Teacher: What if I do not want you to round?
Or what if I want more precision?
What should we do?
Student: Use the double data type?
Teacher: That is correct.
Let's do it.
Teacher: Is that not better?...in terms of
better precision...greater number of decimal places?
Student: But, would you require our answers like this?
How do we know what format the output will be?
Student: Would you take off points for something as minor as $12.0$ rather than $12$?
Teacher: Here is my advice.
If you know the answer of the output, then declare the input variables with the appropriate data type.
For example: we know the sum is $12$.
So, if we were to find only the sum, we would just declare both num1 and num2 as integers because the output
will
give us an integer.
However, if we do not know the format of the output:
Begin with the double data type because it has more precision.
If your output turns out to be an integer, narrow cast that double data type to an integer
If the output is an integer, but your output is a float or double; I shall deduct points.
One of the nice things about the NetBeans IDE is that it will help you with the type casting.
If you see a red line and you point your mouse at it, it will ask you to press the Alt and Enter
key
to show hints. When you do that, one of the hints will be to type cast/do the conversion. Click it and
the IDE will do it for you.
We have reasons for rounding numbers. We also have reasons for not rounding numbers.
Let us solve more questions.
NOTE:
Jave recommends that we should never use the float or double data type for precise values, such as
currency. (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html)
It recommends that we use the java.math.BigDecimal class instead.
When we begin our study of classes (in the next course), we can review that class and other APIs (Application
Programming Interface).
For this course, we shall use the double data type.
Let us review more examples.
Please visit my website on Numbers
(www.numbersandnotations.appspot.com/numbers.html)
Let us solve Question $10$ on that website
First Approach
We used the Java Math Functions in this approach.
Please see the complete list of the Java Math Functions
(https://docs.oracle.com/cd/E17904_01/apirefs.1111/e12048/functmath.htm#CQLLR412)
Second Approach
Let us review a case where the answer needs to be rounded.
Please visit my website on Percent Applications
(www.fractions-decimals-percents.appspot.com/percentApplications.html)
Let us solve Question $1$ on that website
We can round any value to any number of decimal places in Java.
Let us discuss at least two ways we can do it.
Both approaches involves String variables.
(1.) Importing the Java class: import java.text.DecimalFormat;
I listed this approach first because it is popular with programmers.
I prefer the third approach, but you can use whatever you prefer.
(2.) Using the String.format() method.
(3.) Using the Print Formatted method System.out.printf() method.
This is my preference.
To see the examples where I used this approach, please view the screenshots of Piecewise Functions in
Module $5$.
For example:
System.out.printf("$%.2f\n", costOrder);
$ puts the dollar sign
%.2f rounds the value to two floats (two decimal places)
\n inserts a new line
Please review the screenshots and the comments for explanations.
We can solve the same question using only one variable.
In this case, we have to use Compound Assignment Operators
Question $1$ on Percent Applications
Using Compound Assignment Operators:
Please review the screenshots and the comments for explanations.
Student: Mr. C, I do not want to be confused by what you do.
Teacher: What is it my dear?
Student: You did not put d in the previous examples.
Then, you put d in this example.
That is confusing...you do something for one and you do another thing for another.
Teacher: I understand.
It is recommended that you put d when you declare a double data type for a variable
However, by default; any decimal in Java is seen as a double data type.
That is also another reason to use the double data type rather than the float data type.
The first reason is because of the precision.
Another reason is that any decimal number in Java is a double data type by default.
So, if we forget to include the d after the decimal, that is not a problem.
It is better to include it.
But, it is not a problem if you forget to include it.
Student: Okay.
What if I write: final float salesTax = 0.12
Will it work?
Teacher: No, it will not work because the decimal number is a double data type in Java by default.
If you want to use a float for that, you will need to include the f after the decimal number
Like final float salesTax = 0.12f will work as a float.
However, keep in mind that the rest of the variables will have to be floats as well. Otherwise you will have to convert them to floats.
It is much better to use the double data type.
Nice observation!
In the formatted methods (String.format() and prinf()) that we used: the format specifiers:
For example in:
System.out.printf("$%.2f\n", costOrder);
$ puts the dollar sign
%.2f rounds the value to two floats (two decimal places)
\n inserts a new line
One of the nice features of the Java langauge is the Input/Output feature.
This feature is interactive.
You use this input/output feature in several applications.
A common application is an application that verifies one's identity by inputting the first name, last name, date of
birth, etc.
To use the Input/Output feature, the Scanner is used.
In other words: write import java.util.Scanner; directly under the package.
Let us demonstrate the input/output feature with numbers so we see how it works.
Please review the screenshots and the comments.
Java Input/Output Feature for Arithmetic Operations and Math Functions.
Let us do another example.
Input/Output Feature: Example $2$
Let us do a real-world application for this example.
Onto the ...
Please review the BMI information on these two government websites [from the Center for Disease Control and Prevention (CDC) and the National Heart, Lung, and Blood Institute of the National Institutes of Health (NIH)]
About Adult BMI | Healthy Weight, Nutrition, and Physical Activity | CDC and
Calculate Your BMI - Standard BMI Calculator
As at today, the 3rd day of September, 2020; the BMI information on both websites are:
NIH website
Calculate Your BMI - Standard BMI Calculator
CDC website
About Adult BMI | Healthy Weight, Nutrition, and Physical Activity | CDC
$ BMI = \left(\dfrac{weight}{height * height}\right) * 703 \\[5ex] weight\:\:is\:\:in\:\:pounds (lb) \\[3ex] height\:\:is\:\:in\:\:inches (in) $
$ BMI = \left(\dfrac{weight}{height * height}\right) \\[5ex] weight\:\:is\:\:in\:\:kilograms (kg) \\[3ex] height\:\:is\:\:in\:\:meters (m) \\[3ex] $ If you need help with conversion of units, please review the Tables and Examples in Measurements and Units
Teacher: What do you notice in both websites?
Student: They both have the information on the BMI.
In addition, the CDC website has information for both Adult BMI and Child & Teen BMI among others.
The NIH website has recommendations among others.
Teacher: That is correct. What else?
Student: They have the BMI calculator.
Teacher: Did you notice any difference in the calculator on both websites?
Student: The NIH website has BMI calculator for both Standard and Metric versions.
The CDC website has the BMI calculator for only the Metric version.
Teacher: Did you notice any issue/concern about the BMI information?
Student: Not really. Why?
Teacher: So, this is what we are going to do.
We are going to develop the BMI calculator.
That calculator will calculate the BMI.
Then, we shall interpret that BMI, and make a recommendation.
.
The CDC website gave us the formula for calculating the BMI. So, we shall use it.
As you can see, our calculator would have to use conditional statements for the interpretation and recommendation.
But, here is the issue.
Student: Wait, I think I see the issue.
The issue is with the domains.
Teacher: Correct!
Anyone having a BMI between $18.5$ and $24.9$ both endpoints included has a Normal weight.
This is: Normal weight: [18.5, 24.9]. It is a closed interval (relate with Mathematics).
So, the Overweight range for the BMI should be the weight greater than $24.9$, (rather than beginning from $25$) and ending at $29.9$
For the Overweight range, the first endpoint is not included, but the second endpoint is included.
This is: Overweight: (24.9, 29.9]. It is a half-open half-closed interval (relate with Mathematics)
Teacher: Do you know why this would be a problem if the programmer does not fix these issues before developing the calculator?
Student: Yes. Because there would not be any interpretation for anyone whose BMI is between $24.9$ and $25$
But, I do see that the BMI information is for values rounded to one decimal place.
Teacher: That is correct.
And we shall develop our calculator to round to one decimal place.
But, it is important we fix the issues.
What if we do not want to round?
Look at the two examples on the CDC website. The BMI values were rounded to two decimal places.
If we developed our calculator to round to two decimal places with the information on those websites "as is"; then we would not have the interpretation and recommendation for those two examples ($24.98$ and $24.96$) because those values are greater than $24.9$ but less than $25$.
Student: That makes sense.
So, the last one: Obese should be BMI greater than $29.9$, rather than greater than $30$?
Teacher: That is correct.
We are going to apply what we learned so far.
We shall develop a console application and a desktop application for the Body Mass Index (BMI) calculator.
I do the console application.
You do the desktop application.
We are yet to cover Statements (covered in Module $5$). However, do not worry.
I explained my comments very well. You will understand the comments.
Please ask questions if you do not understand any of the comments.
We shall use part of Module $5$ (Decision-making statements) in the program.
Please review the screenshots and the comments.
(1.) The program should accept user inputs of:
(I.) First name
(II.) Last name
(III.) Weight
(IV. Height
(2.) The program should output the:
(A.) BMI value
(B.) Interpretation
(C.) Recommendation
(3.) The program should address user-input errors of non-positive numbers for the weight and the height.
Inform the user.
Then, exit the program. Do not allow the program to continue.
To exit the program, we use the command: System.exit(0)
And in Java is represented by the double ampersand symbol &&
Or in Java is represented by the double pipe symbol ||
Code:
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Student: I have several questions, Mr. C
Teacher: Please go ahead
Student: First Question: Why did you initialize those variables?
The interpretBMI and the adviceBMI...you initialized them to empty quotation marks: ""
Teacher: Good question.
Assume we did not initialize them
We only defined them within the block of code: the If Statement
Then, we want to print them/output them outside the block of code
The program "will not be happy"
Compare it to this scenario.
A student registered to attend a school.
We did not register the front office registration desk.
But we sent the student to a classroom and the classroom teacher registered that student.
The parents come, looking for their child.
Where will the parent go first?
Student: At the front desk of course
Teacher: Good.
The front desk will first keep a record of the student before sending the student to the class.
We have to first assign the string to something before we send it to the blocks of code, and then output it.
We cannot just declare it without an assignment, then send it to a block of code to be used within that block of
code only, and then want to output it outside the block of code.
Does it make sense?
Student: Yes, it does.
But what if we do not want to print the value outside the block of code?
What if we want to print the value inside each block of code where it is used?
Teacher: I am impressed by your questions.
Yes, we can do that.
But you know what that means...right?
Student: We have to write it each time for each of the conditional statement.
Teacher: That is correct.
Student: Second Question: How did you get the blue color for the heading on the console window?
Teacher: Console Log Formatting:
You can find the commands on my website: American Standard Code for Information Exchange (ASCII)
We have done several console applications.
Now onto desktop applications.
Let us apply the knowledge we acquired in this module to develop a desktop application.
Which application comes to mind right away...a desktop application that deals with Numbers and Operators?
It's the Standard Calculator. Let's develop it. 😊
Please review the desktop applications we developed in previous modules beginning from Module $1$
Let us begin with the desktop calculator on your Windows PC/Laptop
Please see the screenshots
Let us develop the function buttons as seen in the red rectangle.
We are yet to cover Statements (covered in Module $5$). However, do not worry.
I explained my comments very well. You will understand the comments.
Please ask questions if you do not understand any of the comments.
We shall use part of Module $5$ (Decision-making statements) in the program.
JFrame Form: Adjust and Align
title property: Standard Calculator © 2021 SamDom4Peace Designs
Palette | Property |
---|---|
Panel Adjust and Align to cover entire JFrame Form |
background: RGB $\rightarrow$ Color Code: FFF5EE (This is for the color: SeaShell) font: Font: Times New Roman; Font Style: Plain; Size: 24 Change Variable Name: calculatorPanel |
Label: Adjust and Align |
border: Etched Border (do this first) text: Delete jLabel1 horizontalAlignment: RIGHT (because we want to align the $0$ to the right) font: Font: Times New Roman; Font Style: Plain; Size: 24 border: Etched Border Change Variable Name: calculatorLabel |
Text Field: Adjust and Align |
text: $0$ (because we want $0$ to be the default) horizontalAlignment: RIGHT (because we want to align the $0$ to the right) font: Font: Times New Roman; Font Style: Plain; Size: 24 border: Etched Border Change Variable Name: calculatorTextField |
Button: Adjust and Align |
text: $1/x$ font: Font: Times New Roman; Font Style: Plain; Size: 24 background: RGB $\rightarrow$ Color Code: FFFFFF (This is for the color: White) Change Variable Name: reciprocalButton |
Duplicate Button: Adjust and Align |
text: $7$ Change Variable Name: sevenButton |
Duplicate Button: Adjust and Align |
text: $4$ Change Variable Name: fourButton |
Duplicate Button: Adjust and Align |
text: $1$ Change Variable Name: oneButton |
Duplicate Button: Adjust and Align |
text: $+/-$ Change Variable Name: plusMinusButton |
Duplicate Button: Adjust and Align |
text: $x^2$ Change Variable Name: squaredButton |
Duplicate Button: Adjust and Align |
text: $8$ Change Variable Name: eightButton |
Duplicate Button: Adjust and Align |
text: $5$ Change Variable Name: fiveButton |
Duplicate Button: Adjust and Align |
text: $2$ Change Variable Name: twoButton |
Duplicate Button: Adjust and Align |
text: $0$ Change Variable Name: zeroButton |
Duplicate Button: Adjust and Align |
text: $\sqrt{x}$ Change Variable Name: squareRootButton |
Duplicate Button: Adjust and Align |
text: $9$ Change Variable Name: nineButton |
Duplicate Button: Adjust and Align |
text: $6$ Change Variable Name: sixButton |
Duplicate Button: Adjust and Align |
text: $3$ Change Variable Name: threeButton |
Duplicate Button: Adjust and Align |
text: $.$ Change Variable Name: decimalButton |
Duplicate Button: Adjust and Align |
text: $\div$ Change Variable Name: divideButton |
Duplicate Button: Adjust and Align |
text: $\times$ Change Variable Name: multiplyButton |
Duplicate Button: Adjust and Align |
text: $-$ Change Variable Name: minusButton |
Duplicate Button: Adjust and Align |
text: $+$ Change Variable Name: plusButton |
Duplicate Button: Adjust and Align |
text: $=$ Change Variable Name: equalButton |
Duplicate Button: Adjust and Align |
text: Clear Change Variable Name: clearButton |
Duplicate Button: Adjust and Align |
text: Exit Change Variable Name: exitButton |
(1.) Run the code and select standardcalculator.StandardCalculator as the main class.
Close the application and let us code the program.
(2.) In the Design Area, double-click the $1/x$ button.
This leads to the Source Area
Scroll all the way to the top and begin to...
(3.) Write the code.
Let us use a top-down approach. So, let us write the code for each toolbox (Palette tool) in the order as seen in
the Design Area.
Please review the screenshots.
Review the comments.
Design Area
Program Code
Student: Mr. C, you used the same name variable: newNumber for different events.
Is that allowed?
Teacher: Very good observation.
We can do that because we defined that variable locally.
This means that the variable: newNumber is only recognized within that event.
If we use it outside that event, it will result in an error because we did not define it in the class.
Notice that we did not have issues with the variables we defined in the class such as firstNumber
We can use those variables anywhere within the class.
Run the Program
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() NaN means Not a Number It is not a real number. But it is an imaginary number. It is covered under Complex Numbers in Algebra) This calculator deals with only with real numbers. |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Let us design another calcuator using more toolbox controls.
For this calculator:
(1.) We want two textfields for user-input.
The two textfields will receive user-input for two numbers (the operands).
Remember that textfields accept only strings.
But we want them to accept numbers.
We shall define those numbers using the double data type (to accomodate decimals).
Then, we shall convert those numbers as strings so that the textboxes will accept them.
(2.) We want a ComboBox.
The ComboBox will contain a dropdown list of items: the operations.
We shall expand our list of operations. So, this calculator will be more of a scientific calculator.
I shall do some functions.
You do the rest of the functions (just as we did for the Standard Calculator).
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
(3.) We want four buttons: the Calculate, Clear Some, Clear All, and Exit buttons.
We shall use access keys with these buttons.
(4.) When we run our program, we want the cursor to be focused on the first textfield.
Then, we want the user to be able to use the Tab key on the keyboard to perform any operation without using a mouse.
This is an important software design concept to accommodate users with disabilities.
It is known as the Tab Order Property.
Once the user enters the first number in the first textbox; move to the ComboBox and select an operation from the
dropdown list and press the Tab key; use the Tab to move to the second textbox (as applicable), enter the second number and
press the Tab key (as applicable); move to the Calculate button and hit the Enter key to get the result.
The Tab Order property controls that ability for the Tab to move in that order.
We shall set the Tab Order properties of the toolbox controls accordingly.
For operations that involve two numbers such as calculating the sum, difference and the like: we want it to be:
$first\;\;number \rightarrow operation \rightarrow second\;\;number \rightarrow calculate$
For operations that involve only one number such as calculating the reciprocal, square root and the like: we want to
disable the second textbox so that the user would not enter a second number.
The Tab Order property determines the order in each pallete tool receives focus when the user presses the Tab key
while an application is running.
The Tab Order property is zero-indexed. This means that the first one begins with a 0, the next one is a 1, the next is a 2
among others.
The Tab Order is set in the order that each pallete tool is added to the form.
It is important to run the GUI (without the code) and use the Tab key to ensure that each palette tool receives cursor
focus accordingly.
If the Tab Order is not set in the way you want it, you can adjust it by moving each tool up or down.
Please review the screenshots.
Recap:
Assume the user is working with only the keyboard (software design to accommodate users who cannot use the mouse)
(1.) When the user runs the application, the cursor focus should be in the first textfield waiting for user input.
The user enters a number and presses the tab key
(2.) The next focus should be the ComboBox waiting for the user to make a selection.
The user selects an operation.
If the operation involves only one number, the second textfield is disabled so the focus moves to the Calculate
button.
The command used to disable the textfield is: TextField.setEditable(false);
As you can see, to disable a TextField; the editable property of the TextField is set to the Boolean value: false
If the operation involves two numbers, the cursor focus moves to the second textfield waiting for the user to enter the
second number. The user enters the second number and presses the tab key.
The next focus would be the Calculate button.
The user presses the ENTER key and the calculation is done. The result is displayed in the textarea: ResultTextArea.
(3.) The user presses the tab key and the focus should be the Clear Some button.
The user presses the ENTER key and the entries in the textfields and the textarea are cleared.
(4.) The user presses the tab key and the focus should be the Clear All button.
The user presses the ENTER key and all entries (all items in the ComboBox) are cleared.
(5.) The user presses the tab key and the focus is the EXit button.
The user presses the ENTER key and the application is closed.
Let us work on the design: the form and the palette tools.
JFrame Form: Adjust and Align
name: frame1 (by default. Leave as is)
title: Scientific Calculator © 2021 SamDom4Peace Designs (Sample)
Font: Times New Roman;
Font Style: Plain;
Size: 24
resizable: Uncheck the box
We unchecked the resizable property of the JFrame Form because we do not want the user
to change the size of the application.
We want the interface to have a consistent look.
Palette Tools | Property |
---|---|
Label: Adjust and Align |
text: First Number: Font: Times New Roman; Font Style: Plain; Size: 24 |
Text Field: Adjust and Align |
Font: Times New Roman;
Font Style: Plain;
Size: 24 text: Delete jTextField1 horizontalAlignment: RIGHT Change Variable Name: FirstNumberTextField |
Label: Duplicate the first label Adjust and Align | text: Operation: |
ComboBox: Adjust and Align |
Change Variable Name: OperationComboBox Font: Times New Roman; Font Style: Plain; Size: 24 background: RGB: Color Code Scientific Calculator: FFFFFF (means the White color) model: Delete Item 1 Item 2 Item 3 Item 4 and for teaching purposes type: Please select an operation Addition (+) [2 numbers] Subtraction (-) [2 numbers] Multiplication (*) [2 numbers] Division (÷) [2 numbers] Modulo (mod) [2 numbers] Exponent (xⁿ) [2 numbers: x is the base; n is the exponent] Log_{x}n [2 numbers: x is the base; n is the number] nth Root of x [2 numbers: x is the radicand; n is the index] Reciprocal (1/x) [1 number] Percent (%) [1 number] Absolute Value (|x|) [1 number] n! [1 number] Tangent in DEG (tan) [1 number] Sine in RAD (sin) [1 number] Cosine in GRAD (cos) [1 number] |
Label: Select the first label and the first text field and Duplicate Adjust and Align | text: Second Number: |
Text Field: Select the first label and the first text field and Duplicate Adjust and Align | Change Variable Name: SecondNumberTextField |
Label: Duplicate the label for the Second Number: Adjust and Align | text: Result: |
Text Area: Adjust and Align |
Change Variable Name: ResultTextArea Font: Times New Roman; Font Style: Plain; Size: 24 background: RGB: Color Code Scientific Calculator: FFFFFF (means the White color) editable: Uncheck the box We unchecked the editable property of the Text Area because we do not want the user to edit the result. Further, we want the user to be able to use the Tab key and move on to the Calculate button. |
Button: Adjust and Align |
Change Variable Name: CalculateButton Font: Times New Roman; Font Style: Plain; Size: 24 background: RGB: Color Code Scientific Calculator: FFFFFF (means the White color) text: Delete jButton and write Calculate Horizontal Size: 160 |
Button: Copy and paste the previous button Adjust and Align |
text: Clear Some Change Variable Name: ClearSomeButton Horizontal Size: 160 |
Button: Copy and paste the previous button Adjust and Align |
text: Clear All Change Variable Name: ClearAllButton Horizontal Size: 160 |
Button: Copy and paste the previous button Adjust and Align |
text: Exit Change Variable Name: ExitButton Horizontal Size: 160 |
A JComboBox
is a palette tool that allows the user to select items from the a list.
(https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html)
It can have two very different forms: the editable Combobox and the uneditable ComboBox.
There are several properties of the ComboBox.
We shall discuss only one property in this module: the SelectedIndex
property.
The SelectedIndex property gets or sets the index of a selected item.
The ComboBox items are zero-indexed just like arrays.
This means that the first item has index: $0$, the second item has index $1$, and the third item has index $2$ among others.
The command used to specify a selected item in the ComboBox is: ComboBox.getSelectedIndex() == Index
Based on the items in the ComboBox in our program:
ComboBox Items | Index |
---|---|
Please select an operation | $0$ |
Addition (+) [2 numbers] | $1$ |
Subtraction (-) [2 numbers] | $2$ |
Multiplication (*) [2 numbers] | $3$ |
Division (÷) [2 numbers] | $4$ |
Modulo (mod) [2 numbers] | $5$ |
Exponent (xⁿ) [2 numbers: x is the base; n is the exponent] | $6$ |
$Log_{x}n$ [2 numbers: x is the base; n is the number] | $7$ |
nth Root of x [2 numbers: x is the radicand; n is the index] | $8$ |
Reciprocal (1/x) [1 number] | $9$ |
Percent (%) [1 number] | $10$ |
Absolute Value (|x|) [1 number] | $11$ |
n! [1 number] | $12$ |
Tangent in DEG (tan) [1 number] | $13$ |
Sine in RAD (sin) [1 number] | $14$ |
Cosine in GRAD (cos) [1 number] | $15$ |
(1.) Click the Source Area.
Scroll a little bit to the top, write the comments, and begin to...
(2.) Write the code.
What should happen when the user clicks the Calculate button?
Please review the screenshots.
Review the comments.
Design Area
Program Code
To clear all the items in a ComboBox, we use the command: ComboBox.removeAllItems();
Student: Mr. C, you used these variables: firstNumber, secondNumber, result for different events.
Is that allowed?
Teacher: Very good observation.
Yes, we can do that.
Here is the reason: we used it within each event (each conditional statement).
We defined it as a class member variable. But remember we did not specify any value for it.
Hence, we are free to use it as local variables.
We can use those variables anywhere within the class.
But you are very welcome to use different variables for the different events if you choose.
Run the Program
For Questions (1.) and (2.); please review the other Java operators
(https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html)
Using code examples and well-written comments for each operator, discuss any of these operators.
(1.) Conditional Operators
(2.) Bitwise and Bit Shift Operators
(3.) Visit my website on Numbers
(www.numbersandnotations.appspot.com/numbers.html)
Choose any applicable question and write a Java program to solve it.
Please make sure that the output of your program gives the same result as the solution of the
question on my website.
You may use Arithmetic Operators, Math Functions, or both.
(4.) Visit my website on Percent Applications
(www.fractions-decimals-percents.appspot.com/percentApplications.html)
Choose any applicable question and write a Java program to solve it.
Please make sure that the output of your program gives the same result as the solution of the
question on my website.
You may use Arithmetic Operators, Math Functions, or both.
(5.) Program to determine your age
***Because your age is a PII (Personal Identifiable Information), you may use a fictitious age.
However, you need to test it (privately) with your actual age to make sure it works.***
Develop a Java program to determine your age based on these instructions.
ONLY one variable must be used.
(Hint: If only one variable must be used, this implies that you need to use Compound
Assignment operators)
The user wants you to note that these instructions would only work for ages determined this
year, and wants you
to specify it in the program.
(a.) Pick an integer between $0$ and $10$ ($0$ and $10$ exclusive).
(b.) Multiply the integer by two.
(c.) Add five to the result.
(d.) Multiply the result by fifty.
(e.) If you already had your birthday this year, add the result to one thousand, seven hundred
and seventy one.
If you have not had your birthday this year, add the result to one thousand, seven hundred
and seventy.
(f.) Subtract your four digit birth year from the result.
Run the code and display the output.
Explain your result.
(6.) A client wants you to develop a program to calculate the age of his child.
The instructions for the previous question still applies to this question.
However, in this case; the program will give the instructions to the child, and the child will
respond.
This program is an Input/Output program.
Develop a Java program for this child.
(7.) Program to determine your date of birth.
***Because your date of birth is a PII (Personal Identifiable Information), you may use a
fictitious age. However, you need to test it (privately) with your actual age to make sure it
works.
Develop a Java program to determine your date of birth based on these instructions.***
ONLY one variable must be used.
(Hint: If only one variable must be used, this implies that you need to use Compound
Assignment operators).
(a.) Pick the integer that is your month of birth.
(b.) Multiply the integer by two hundred.
(c.) Add three hundred and eighty two to the result.
(d.) Divide the result by two.
(e.) Add your day of birth to the result.
(f.) Multiply the result by 100.
(g.) Add thirteen thousand, eight hundred and forty to the result.
(h.) Add the last two digits of your year of birth to the result.
(i.) Subtract thirty two thousand, nine hundred and forty from the result.
Run the code and display the output.
Explain your result.
(8.) A client wants you to develop a program to calculate the date of birth of her child.
The instructions for the previous question still applies to this question.
However, in this case; the program will give the instructions to the child, and the child will
respond.
This program is an Input/Output program.
Develop a Java program for this child.
(9.) Develop a Body Mass Index (BMI) desktop application using the United States System.
Test each condition just like we did in our example for the United States System.
Address user-input errors.
(10.) Develop a Body Mass Index (BMI) console application using the International System.
The formula is on the screenshot.
Test each condition just like we did in our example for the United States System.
Address user-input errors.
(11.) Develop a Body Mass Index (BMI) desktop application using the International System.
The formula is on the screenshot.
Test each condition just like we did for the United States System.
Address user-input errors.
Questions (12.) and (13.) are meant to prepare you for the Midterm Project.
For Questions (12.) and (13.)
Develop a VB program that meets these requirements.
(I.) Consider any concept/scenario that uses conditional statements.
It will be great if you find a real-world application. However, you can make up your own.
If you decide to make up your own, please explain the scenario and the conditions well.
If you use a real-world application, please cite your source(s) accordingly. Explain the scenario and the conditions well.
Use at least two (two or more) different conditions.
The BMI Calculator has four different conditions.
But, please use any application that has at least two different conditions.
(II.) Accept user input(s).
(III.) Address user input errors.
(IV.) Test your program and display the result/output for each condition.
(V.) Test your program for user-input errors.
(VI.) Submit all the screenshots accordingly.
(12.) Develop a console application for your concept.
(13.) Develop a desktop application for your concept.
Textbook Questions
(14.) Question $12$ on Page $107$
(15.) Question $14$ on Page $107$
(16.) Question $16$ on Page $107$
Java Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) Java Math: Exercises, Practice, Solution
(B.) Java Basic Programming - Part 1: Exercises, Practice, Solution
(C.) Java Basic Programming - Part 2: Exercises, Practice, Solution
(D.) Java Data Types: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(17.) Please focus only on Questions that deals with Numbers and Operators.
Write the Question as a comment in your program. Include the Title and the Question Number.
Write clear comments for each line of code in the Solution.
Run the program.
Submit clear screenshots.
For those who do not mind messing around with several languages at the same time
Student: Excuse me, Mr. C
This course is only for Java
What do you mean?
Teacher: You are correct.
But, these subsequent questions are not for everyone.
That is the reason I am putting them at the end.
I have a question for you.
Have you ever seen any IT/Computer Science position that requires the knowledge of only one programming language?
Student: I have not checked, Sir.
Teacher: If you intend to be in the IT/Programming field for the long run, at least four (four or more)
languages are required.
If you look for IT positions at Indeed.com or other career/job websites, you will realize what I mean.
Search for java programmer, you might be surprised that even for entry level positions
for a Java Programmer; they require you to have a working knowledge of several other programming languages.
Mr. C is preparing you for that...if you intend to work in the programming field for a long time.
Besides, this is a critical thinking approach.
I am required to develop and promote critical thinking questions for my students.
A programmer is basically a problem-solver irrespective of the programming language used to solve the problem.
Yes, we are working with Java.
However, if you find out that C# would be better in solving a particular problem in your workplace,
then you need to use C# unless your employer says otherwise.
The knowledge of several languages is a good asset. It makes you highly valuable.
Further, anyone who attempts any of the subsequent questions will still have to write the program in Java and get the same
result.
The questions and solutions are in another language.
But the student will have to write the program in Java and come up with the same solution. So, we are still on track.
It is critical thinking...multiple approaches to solving a question.
Be it as it may, these subsequent questions are not required.
It is okay even if you do not look at them. 😊
C# Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) C# Basic Declarations and Expressions : Exercises, Practice, Solution
(B.) C# Basic Algorithm: Exercises, Practice, Solution
(C.) C# Data Types : Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(18.) Please focus only on Questions that deals with Numbers and Operators.
Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in Java
Run the program. Please make sure your program output is the same solution
Submit clear screenshots.
C++ Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) C++ Basic: Exercises, Practice, Solution
(B.) C++ Basic Algorithm: Exercises, Practice, Solution
(C.) C++ Math: Exercises, Practice, Solution
(D.) C++ Numbers: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(19.) Please focus only on Questions that deals with Numbers and Operators.
Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in Java
Run the program. Please make sure your program output is the same solution
Submit clear screenshots.
(1.) Provide any of these if it is lacking in any DB post that solved any question in the
Assess tab of this module: Well-written comments; another approach/method to solving the
question; any additional relevant details; etc.
For Questions (5.) and (6.) in the Substantive Posts
Student: Mr. C, the instructions in Questions (5.) and (6.) are not correct.
The result is not my age.
How can you ask us to write a program that does not work?
(2.) Explain the result to the Student. (Answer this question only if any of your colleagues made a similar statement in the initial post.)
(3.) The Student wants only his/her age to be the result.
Without modifying any of the instructions (but using all of them) and one more instruction, extend the
program to display only the Student's age.
What is the extra instruction that you would include to work for all ages?
Write it. Run it. Submit clear screenshot(s).
For Questions (7.) and (8.) in the Substantive Posts
Student: Mr. C, I want the date of birth to display properly.
Teacher: Use a delimiter.
Student: What is a delimiter?
Teacher: A delimiter is a sequence of chararcters that specifies limits/boundaries of characters
in a text, expression, word, etc.
A good example is the forward slash that you can use to separate that DOB in the form of: mm/dd/yyyy.
The forward slash is a delimiter.
Another example is the pipe delimiter: mm | dd | yyyy.
Another example is the hyphen delimiter: mm-dd-yyyy.
Student: Okay, how do I display the result in that format?
(4.) Explain how you would display the result for the Student.
Write the code. Run it. Submit clear screenshot(s).
(5.) Other substantive responses.
This is the NumbersOperators.jar Standard Calculator
(1.) Please review the Functionalities of the Calculator and the Limitations of the Calculator as explained in
the Learn tab.
Maintain all the functionalities of the calculator.
Address the first three limitations.
You may use my code if you wish (in this case because you are extending the functionlities of my program) and/or your code.
(2.) The first standard calculator we programmed did not contain all the functions.
This is what we did.
This is what you should do.
Develop a calculator that contains all the functions.
Due the scope of this module, you may work with only the integer data type.
However, your calculator should handle quotients that are decimals (division of integers that results in decimals)
Your calculator should also handle percentages (for those integers whose percentages gives decimals).
Because you are working with only integers, you may remove the decimal function button and replace it with any
function you prefer.
Please note:
The C function is the Clear function. It deletes everything.
It clears the first number, operation, and the second number.
The CE function is the Clear Entries function. It deletes "some" things.
It clears only the second number. You can replace the second number and continue with the calculation.
It does not clear everything.
This is used when the entire calculation does not need to be deleted.
The BS (backspace) function (you may use alt+174 key if you prefer) is the backspace function.
It deletes part of the first number or the second number.
This is also used when the entire calculation does not need to be deleted.
Let us look at an example. You may test it.
$
\underline{Example} \\[3ex]
25 + 32 \\[3ex]
\color{red}{C} \;\; deletes\;\;everything \\[3ex]
\color{red}{CE} \;\; deletes\;\;only\;\;32 \\[3ex]
\color{red}{BS} \;\; deletes\;\;only\;\;2 \\[3ex]
$
This is the executable Numbers.jar Scientific Calculator
(3.) We developed the scientific calculator.
However, it does not contain all the functions.
Develop the scientific calculator GUI that contains all the functions.
You may extend my application by adding the missing functions if you wish, or you may develop your own with all the functions.
You may use my Code Scientific Calculator if you wish (in this case because you are extending the functionlities of my program) and/or your Code Scientific Calculator.
(4.) Develop a console application for an extension of the Body Mass Index (BMI) application example.
We did the application for the United States System (Customary System).
Extend the application by developing the calculator for the International System (Metric System).
The formula is on the screenshot.
Ask the user which system he/she wants to use to calculate the BMI.
Based on the user's selection, display the appropriate units for the weight and the height, as well as the output.
Test all the conditions for both systems.
This is the BodyMassIndexApplication.jar executable file
You may click the link to download and run it. No worries, it is safe.
It is a desktop application.
If you have Java on your computer (PC or Mac desktop/laptop), click the file and run the application directly on your desktop.
(5.) Develop a desktop application for an extension of the Body Mass Index (BMI) application example.
We did the application for the United States System (Customary System).
Extend the application by developing the calculator for the International System (Metric System).
The formula is on the screenshot.
Ask the user which system he/she wants to use to calculate the BMI.
Your desktop application should have the dropdown list for both systems, but should be null be default.
Based on the user's selection, display the appropriate units for the weight and the height, as well as the output.
Test all the conditions for both systems.
Question (6.) is meant to prepare you for the Midterm Project.
Develop a VB program that meets these requirements.
(I.) Consider any concept/scenario that uses conditional statements.
A real-world application is required. You may not make up your own.
Please cite your source(s) accordingly. Explain the scenario and the conditions well.
Use at least two (two or more) different conditions.
The BMI Calculator has four different conditions.
But, please use any application that has at least two different conditions.
(II.) Accept user input(s).
(III.) Address user input errors.
(IV.) Test your program and display the result/output for each condition.
(V.) Test your program for user-input errors.
(VI.) Submit all the screenshots accordingly.
(6.) Develop a console application and a desktop application for your concept.
character, string, Boolean, bool, function, argument, dot member access operator, concatenator operator, string literal, empty string, date, time
Students will:
(1.) Discuss the Java string data type.
(2.) Discuss the Java Boolean data type.
(3.) Discuss Date and Time in Java.
(4.) Write programs that involves the String data type.
(5.) Write programs that involves the Boolean data type.
(6.) Write programs that involves Date and Time.
(1.) Textbook Chapter
(2.) Java Strings and Java Booleans
(Java Strings: www.w3schools.com/java/java_strings.asp) and (Java Booleans: www.w3schools.com/java/java_booleans.asp)
(3.) Java SE 8: Getting Started with String Processing: Invoking the String Class Methods
(Java SE 8: Getting Started with String Processing: Invoking the String Class Methods: www.oracle.com/webfolder/technetwork/tutorials/obe/java/String/String.html#section2)
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type Java Strings and/or Java Booleans and/or Java Date and Time in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(5.) Type Java Strings and/or Java Booleans and/or Java Date and Time in the search bar and view the results.
A String is a sequence of ordered characters.
It is built out of characters.
It is enclosed in matching single or double quotation marks.
Remember the first C++ program we wrote, the output...the message, THANK GOD.
That is an example of a string.
Let us review more examples of what we could do with Java strings.
Join strings.
Let us discuss several ways of joining strings.
Please review the screenshots and the comments.
First Approach: Concatenator operator
Teacher: There is an issue here.
Student: There is no space between your first and last name.
Teacher: That is correct.
How do we fix it?
Student: Include a space between the names.
Teacher: There are several ways we can do this.
We can include an empty string in between the names.
Join two strings using Concatenation operator (Space included between the strings)
Teacher: We can also use the StringBuffer class with the Append method
The Append method does not automatically include a space between the strings.
So, we have to include the space appropriately.
Second Approach: StringBuffer class with the Append method
Student: In the Second Approach: StringBuffer class with the Append method
You did not use the string variables: firstName and lastName
Teacher: That is correct.
Student: What if I want to use the string variables with the append method?
Instead of using strings?
Do you understand what I mean?
Teacher: I do.
Nice question.
We can do it.
We shall have the variable: firstName as the argument of the object
We append an empty string
Then, we append the lastName.
Student: So, we can use two append methods with a string?
Teacher: Yes.
We shall use those append methods accordingly with the dot member access operator (the period, .)
Let us do this with the Third Approach.
However, you can still do it with the Second Approach.
But, let us see another approach.
Third Approach: StringBuilder class with the Append method
Student: What is the difference between the StringBuffer class and the StringBuilder class?
Which one should we use?
Teacher: Good question.
We shall discuss the differences in Advanced Java course.
But, I prefer you use the StringBuilder class because it is more efficient than the StringBuffer class.
However, it depends on what you want to do with the string.
We shall discuss the String class, the StringBuffer class, and the StringBuilder class in Advanced Java course.
Backslash Escape Sequence, \
Sometimes, we write sentences that has the single quotation marks and the double quotation marks.
How do we display these sentences in a Java program?
We have to use the backslash escape sequence
It turns special characters into string characters.
Please review the screenshots and the comments.
Insert single quote, double quote, backslash in sentences
Teacher: I do not want to scroll all the way to the right to see the entire results.
What should I do?
Student: Insert a new line?
Teacher: That is correct....insert a new line escape sequence.
The third quote: the quote by St. Jerome is okay.
But, let us add new lines to the first quote: the quote by St. Francis of Assisi and the second quote: the quote by
Maya Angelou.
In the previous module, we reviewed some examples of the Input/Output with Numbers.
In this module, let us demonstrate the Input/Output feature with Strings.
As we did with Numbers, we have to import the import java.util.Scanner class.
Input/Output Feature with Strings
Teacher: What are you looking at?
You already know.
Student tries to hide it.
Teacher: I want to ask you something.
Look at it.
Please turn it off...remember the course syllabus.
Before you turn it off, do you see two numbers in the Power off button?
Student: Numbers?
I do not see numbers.
It's an icon.
Teacher: Yes, they are numbers.
The numbers are: $0$ and $1$
$1$ is inside the $0$ in most devices.
Student: Interesting.
Teacher: $0$ represents OFF
$1$ represents ON
You see these two numbers in almost all electronic devices (tablets, smartphones, computers) including some
electric switches.
In Logic, $0$ represents FALSE
$1$ represents TRUE
We use true and false Boolean values in Statements including conditional statements and
iterative statements. We shall cover Statements in the next module.
The use of these two numbers: $0$ and $1$ in Mathematics and Computer Science to repesent FALSE and
TRUE values is known as Boolean Algebra
It was developed by George Boole, an English mathematician/philospher/logician.
We can also use these Boolean numbers $0$ and $1$ to represent choices/options of NO and YES
A Boolean is a fundamental data type in Java that:
(1.) is declared with the keyword, bool
(2.) can represent only one of two states: true or false
(3.) gives an output of only one of two values: true or false
(4.) is used for comparison (in relational and comparison operators) to compare expressions.
(5.) is used in statements (conditional statements and iterative statements) to make decisions.
A Boolean Expression is an expression that returns a Boolean value.
Let us demonstrate some examples of the use of Booleans.
Booleans: Example 1
Booleans: Example 2
Date and time stamps are needed for: transactions, receipts, appointments, agreements, events, rules/laws, and
tickets (by cops and troopers) among others.
Besides, we shall use the date and time functions in the midterm project.
Let us discuss date and time.
Teacher: The date and time is interesting in the sense that I would not classify it as a string or as an
integer.
Student: What data type would you call it?
Teacher: It is a data type by itself.
However, you can treat it as a string and use certain string functions to slice it.
You can also treat it as an integer by adding or subtracting days and years.
There are several approaches to display date and time in Java.
Let us discuss two appraches.
First Approach: java.time package
To display date and time in Java, we need to import the java.time package.
The java.time package includes several classes to access date and time.
Some of the classes included in the java.time package are:
(1.) LocalDate: This displays the date in the format: yyyy-MM-dd (year, month, day format)
(2.) LocalTime: This displays the time in the format: HH-mm-ss-ns (hour, minute, second, nanosecond
format)
(3.) LocalDateTime: This displays the date and time in the format: yyyy-MM-dd-HH-mm-ss-ns (year,
month, day, hour, minute, second, nanosecond format)
These classes use the now() method to get the current date and time.
(4.) DateTimeFormatter: This uses the ofPattern() method to format the date and time objects and
display them in several formats.
However, we have to create a String variable that formats the LocalDate or LocalTime or LocalDateTime object with
the object of the DateTimeFormatter using the .format method.
Please review the screenshots and the comments.
Date and Formatted Date
Time and Formatted Time
Date and Time, and Formatted Date and Time
You may use strings not written in English language. However, if you use any language other than English language,
it is important you translate it. Your colleagues and I need to understand your code.
Insensitive words, or any words deemed inappropriate to any race, gender, religion are unacceptable. Any violation
will not yield any point.
If you are not sure of the words/string to use, please contact me first.
Please review the:
Java String methods
(www.w3schools.com/java/java_ref_string.asp) and/or
Java String methods
(www.beginnersbook.com/2013/12/java-strings/) and/or
Java String methods
(https://docs.oracle.com/javase/9/docs/api/java/lang/String.html)
(Scroll down till you see the tab: All Methods)
(1.) Review the methods and the examples.
Pick any five methods besides the ones I discussed.
Write the code examples for each of the five methods and implement each of them.
Run your codes.
Display the results.
Submit clear screenshots of your code examples of each of the five methods and the corresponding results.
Please review the:
Java StringBuffer class
(www.tutorialspoint.com/java/lang/java_lang_stringbuffer.htm) and/or
Java StringBuffer class
(https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html)
(Scroll down till you see the tab: Method Summary)
(2.) Review the methods and the examples.
Pick any five methods besides the ones I discussed.
Write the code examples for each of the five methods and implement each of them.
Run your codes.
Display the results.
Submit clear screenshots of your code examples of each of the five methods and the corresponding results.
Please review the:
Java StringBuilder class
(www.tutorialspoint.com/java/lang/java_lang_stringbuilder.htm) and/or
Java StringBuilder class
(https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html)
(Scroll down till you see the tab: Method Summary)
(3.) Review the methods and the examples.
Pick any five methods besides the ones I discussed.
Write the code examples for each of the five methods and implement each of them.
Run your codes.
Display the results.
Submit clear screenshots of your code examples of each of the five methods and the corresponding results.
Textbook Questions
(4.) Question $2$ on Page $362$
(5.) Question $4$ on Page $362$
(6.) Question $6$ on Page $363$
Java Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) Java Strings: Exercises, Practice, Solution
(B.) Java Date and Time: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(7.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write clear comments for each line of code in the Solution.
Run the program.
Submit clear screenshots.
For those who do not mind messing around with several languages at the same time
Student: Excuse me, Mr. C
This course is only for Java
What do you mean?
Teacher: You are correct.
But, these subsequent questions are not for everyone.
That is the reason I am putting them at the end.
I have a question for you.
Have you ever seen any IT/Computer Science position that requires the knowledge of only one programming language?
Student: I have not checked, Sir.
Teacher: If you intend to be in the IT/Programming field for the long run, at least four (four or more)
languages are required.
If you look for IT positions at Indeed.com or other career/job websites, you will realize what I mean.
Search for java programmer, you might be surprised that even for entry level positions
for a Java Programmer; they require you to have a working knowledge of several other programming languages.
Mr. C is preparing you for that...if you intend to work in the programming field for a long time.
Besides, this is a critical thinking approach.
I am required to develop and promote critical thinking questions for my students.
A programmer is basically a problem-solver irrespective of the programming language used to solve the problem.
Yes, we are working with Java.
However, if you find out that C# would be better in solving a particular problem in your workplace,
then you need to use C# unless your employer says otherwise.
The knowledge of several languages is a good asset. It makes you highly valuable.
Further, anyone who attempts any of the subsequent questions will still have to write the program in Java and get the same
result.
The questions and solutions are in another language.
But the student will have to write the program in Java and come up with the same solution. So, we are still on track.
It is critical thinking...multiple approaches to solving a question.
Be it as it may, these subsequent questions are not required.
It is okay even if you do not look at them. 😊
C# Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) C# Strings : Exercises, Practice, Solution
(B.) C# Date and Time: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(8.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in Java
Run the program. Please make sure your program output is the same solution
Submit clear screenshots.
C++ Programming Exercises, Practice, Solution by W3Resource
Please review:
(A.) C++ Strings: Exercises, Practice, Solution
You are provided with the Questions and the Solutions.
No more than one student may do any specific question.
(9.) Write the Question as a comment in your program. Include the Title and the Question Number.
Write the program in Java
Run the program. Please make sure your program output is the same solution
Submit clear screenshots.
Review the post of your colleague.
Use a different string method to work on the same string used by your colleague.
(1.) We are yet to do Statements (in the next Module), but you can give this question a try.
A string palindrome is a word, phrase, clause or sequence of characters that is
spelled and read the same way backward and forward.
In other words, when one reads it as is, reverses it and reads it again; the pronunciation is the same.
Examples include the:
Words: HANNAH, BOB, madam, level, civic, racecar, rotor
Phrase: never odd or even
Clause: nurses run
Sentence: Was it a car or a cat I saw?
Write a Java program that asks for user input.
Determine if the user input is a string.
If the user input is not a string, ask the user to enter only a string.
If the user input is a string, determine if it is a string palindrome.
Inform the user whether it a string palindrome or not.
Test all conditions.
Submit clear screenshots of the code and the results.
(2.)
statement, expression, block, expression statement, declaration statement, control flow statement, decision-making statements, conditional statements, decision, selection statements, looping statements, branching statements, branches, repetitive statements, iteration statements, loops, for loop, while loop, do-while loop, jump statements,
Students will:
(1.) Discuss Statements in Java programming language.
(2.) Write decision-making statements.
(3.) Write looping statements.
(4.) Write branching statements.
(5.) Write programs that solve real world problems using statements.
(6.) Complete the Midterm Project on Piecewise Functions.
(1.) Textbook Chapter
(2.) Expressions, Statements, and Blocks
(https://docs.oracle.com/javase/tutorial/java/nutsandbolts/expressions.html)
Begin from Expressions, Statements, and Blocks to Questions and Exercises
(3.) Java If...Else
(www.w3schools.com/java/java_conditions.asp)
Begin from Java If...Else to Java Break/Continue
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type Java Statements and/or Java Conditional Statements in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(5.) Type Java Statements and/or Java Conditional Statements in the search bar and view the results.
Expression
An expression is a construct made up of variables, operators, and method invocations, which are constructed
according to the syntax of the language, that evaluates to a single value.
// Expression
// We covered this statement in Module 3
double result = 7 * (5 - 2);
Statement
A statement is an individual instruction of a program.
It ends with a semicolon.
It forms a complete unit of execution.
It is equivalent to a sentence in a language.
There are three kinds of statements in Java.
They are:
(1.) Expression Statements
These are statements that are made from expressions.
They include:
(I.) Assignment statement
// Assignment statement
// We covered this statement in Module 3
int num1 = 7;
(II.) Increment and Decrement statements
// We covered this statement in Module 3
// Increment statement
num1++;
// Decrement statement
num1--;
(III.) Method invocation statement
// Method invocation statement
// We have been using this statement since Module 1
System.out.println("THANK GOD");
(IV.) Object creation statement
// Object creation statement
// We used this statement in Modules 3 and 4
import java.util.Sacnner; // Import the Scanner class
// Create the object: userInput of the Scanner class
Scanner userInput = new Scanner(System.in);
(2.) Declaration Statements
A declaration statement declares a variable.
// Declaration statement
// We covered this statement in Module 3
int num1 = 7;
(3.) Control Flow Statements
Generally, statements in Java are executed from top to bottom, in the order that they appear.
However, control flow statements control the order in which statements are executed.
In other words, they break up the flow of the execution of statements by using decision making, looping, and
branching; thereby allowing a program to exceute particular blocks of code conditionally.
They include:
(I.) Decison-making Statements
The decision-making statements are the: if statement, if-else statement, if-then statement,
if-then-else statement, Multiple ifs statement, and the switch statement
These statements are also referred to as Conditional statements or Decisions or Selection statements
(II.) Looping Statements
The looping statements are the: for loop, while loop, and the do-while loop
These statements are also referred to as Repetitive statements or Iteration statements or Loops
(III.) Branching Statements
The branching statements are the: break statement, continue statement, and the return statement
These statements are also referred to as Jump statements or Branches
Block
A block is a group of zero or more statements between balanced braces that can be used where a single statement is allowed.
In Example 3 (If-else statement) as seen in the screenshot below; the if statement is the
first block of code and the else statement is the second block of code.
Decision-making statements are statements that execute an action based on some condition(s).
They are also known as Conditional Statements or Decisions
These statements are the:
(1.) If statement
This statement is used when there is only one condition.
If some condition is met, execute a given task.
The If statement is written as:
if (condition) { statement; }Java ignores whitespaces so you can also write it this way:
if (condition) { statement; }
if (condition 1) { statement; } else { statement; }Java ignores whitespaces so you can also write it this way:
if (condition) { statement; } else { statement; }We can also write simple If-else statement using the Ternary operator
variable = if (condition) ? statement if true : statement if false;(3.) If-else if - else statement
if (condition 1) { statement; } else if (condition 2){ statement; } else if (condition 3) { statement; } else { statement; }Whitespaces are ignored in Java. Therefore you can also write it this way:
if (condition 1) { statement; } else if (condition 2) { statement; } else if (condition 3) { statement; } else {statement; }Keep in mind that we do not specify condition 4 in the code for the else statement because we already know that statement for the else statement would only be executed if all the other prior conditions are not met.
if (condition 1) { statement; } if (condition 2){ statement; } if (condition 3) { statement; } if (condition 4) { statement; }Whitespaces are ignored in Java. Therefore you can also write it this way:
if (condition 1) { statement; } if (condition 2) { statement; } if (condition 3) { statement; } if (condition 4) { statement; }Review the Definitions of Numbers
A good application of Java Conditional Statements are seen in Piecewise functions.
Please review the Story
on Piecewise Functions
(www.piecewise-functions.appspot.com/#story)
We are going to write several Java programs that will solve the Piecewise function problem in
that story.
Piecewise Function: Conditional Statements using Multiple Ifs statements
Conditional Statements: Example 6 (Multiple conditions: Multiple ifs)
Student: Can we write the same Piecewise function using the If-else if-else
statements?
Teacher: Nice question.
What do you think?
Student: I think we can.
Teacher: Yes but we need to include the last elsestatement
Student: Must we include it?
Teacher: Highly recommended...yes
However, the program will work even if you do not include it.
But my recommendation is that whenever you use if-else statement, make sure you include the last elsestatement
The last elsestatement has a statement but does not have a condition.
It is executed when all prior conditions are not met.
So, let us write a statement that will display a message to the user if the user enters any value
out of range.
Student: You mean something like a negative number?
Teacher: That is correct.
Typically, the program will display errors which might crash the system if the user enters a negative number
or if the user enters any positive number greater than the upper bound of the last piece.
In this case (for the Story on Piecewise Functions): if the user enters a negative number or zero or any number
greater than $1000$, the program should display a message that the user entered something out of range, and
then exit without interrrupting the system.
It is one way to handle that exception.
Student: What do you mean by "handle the exception"?
Teacher: It is one of the ways we can prevent the system using that program from crashing.
We shall discuss Exceptions in detail in the Advanced Java course.
We shall write the message for the user, then include the System.exit(0) method to exit the program.
Let's do it.
Piecewise Function: Decision-making Statements using If-else if-else statements
Conditional Statements: Example 7 (Multiple conditions: If-else if-else statements)
What if the user enters $2500$?
What if the user enters $-3$?
Student: Mr. C, you have a warning on Line #17
Teacher: I see it...
Student: Did you do something wrong?
Teacher: We did not.
The warning reads: The assigned value is never read
To remove it, click the light bulb on that line
A message: Configure Unused Assignment Hint will be shown
Then, you can uncheck that box so that the warning will not be shown
But, I would just suggest you leave it that way.
Student: It's not me, Sir.
It is you.
You are usually picky with stuff like this.
Teacher: I am not picky with this one.
The NetBeans IDE is the one complaining about it.
Those variables were actually used in the conditional statement.
However, because they are not used "directly", the IDE thinks they are ununsued.
Let us ignore that warning.
But, please do not ignore warnings generally.
Specifically, for this case; you can ignore it.
(5.) Switch statement
Another selection statement is the switch statement or switch block.
The general syntax of the switch block is:
int variable // This variable must be declared as an integer switch (variable){ case 1: statement; break; case 2: statement; break; case 3: statement; break; default: statement; }Case 1
Looping statements are:
(1.) For Loop
(2.) While Loop
(3.) Do-While Loop
The general syntax of a for loop is:
for (initialize; condition; increment/decrement){ statement; }The general syntax of a while loop is:
initialize; while (condition){ statement; increment/decrement; }The general syntax of a do-while loop is:
initialize; do { statement; increment/decrement; } while (condition);Example 1: Print the first ten positive integers using the three types of loops
Branching statements are statements that control the flow of a program by branching or performing jumps
to specific locations.
They include:
(1.) The Break statement
(2.) The Continue statement
Branching statements are not standalone statements.
They are usually embedded in/used with conditional statements and looping statements.
Break Statement
The break statement breaks/stops a loop even when the loop is still running.
In other words, even if the conditions for a loop has not been satisfied, introducing the break statement
at any point in the loop stops the loop and ends the program.
A good advantage of the break statement is that it can be used to end an infinite loop.
Continue Statement
The continue statement causes the program to skip a portion of the loop, and continue
the loop.
In other words, using the continue statement does not run the entire loop. It skips some part of the
loop and then allows the loop to continue.
Let us demonstrate these branching statements.
Please review all the screenshots and all the comments.
Branching Statements: Break Statement, Continue Statement
Let us redo one of the examples we did using Looping statements.
Let us redo the Example (2.) in Looping statements, with Looping and Branching statements.
Redo Example 2 in Iteration Statement using Iteration statement and Jump statement
Let us solve Question (34.) on Arithmetic Sequences
(www.samuelchukwuemeka.com/Sequences/arithmeticSequences.html) using
selection statements, iteration statements, and jump statements.
We shall use iteration statements: for loop, while loop, and do-while loop to solve the question.
Then, we shall use iteration statements, jump statements and selection statements to solve the question.
Application of Statements: Calculate the sum of the $n$ terms of an arithmetic sequence.
Iteration Statements, Selection Statements and Jump Statements
Student: Mr. C, I understand the initialization of the number of terms...as given by the syntax for the loops.
But, why did we initialize the sum to 0?
Teacher: We initialized the sum to 0 because we have to increment each number and add.
$1 + 2 + 3 + 4 + ...$ is the same as saying $0 + 1 + 2 + 3 + 4 + ...$
Student: Why did we initialize?
Why can't we just declare the variable and keep adding the numbers?
Teacher: We have to use "something" to hold the sum.
Because we need to keep adding to "something", we need to initialize "that thing".
"That thing" is the "sum"
Student: The solution on your website used a formula to solve that question.
If we were using formula to solve it, do we need to initialize the sum?
Teacher: Good question.
We do not.
However, some compilers are picky and would insist that you do.
It is a good practice to initialize variables.
Student: Do we always have to intialize to $0$?
Teacher: We do not.
If we were going to multiply (rather than add) numbers...say we declare product as the variable rather than sum, then we have to initialize that variable to $1$ because we shall be multiplying numbers to it rather than adding numbers to it.
The number you use to initialize a variable is to just hold a value to that variable...more like a placeholder.
It does not determine or influence the final result of that variable.
The midterm project is designed to assess your knowledge of Statements in solving real-world problems.
It is a Piecewise Function application.
Any other application will not considered.
Please:
(1.) Visit my website on: Piecewise Functions
(2.) Read the Story to understand the idea of Piecewise functions.
(3.) Read the Overview of Piecewise Functions for more understanding of Piecewise functions.
(4.) Study the Applications of Piecewise Functions
(5.) Review the Project Examples. Ensure you follow all the instructions and directions.
(6.) Complete the Midterm Project for your course.
(7.) Ask questions. I can advise.
(8.) Upload your draft project (clear screenshots of all your Math work and the .exe file) in the Midterm Project Drafts forum of the course on Blackboard.
I shall review and provide feedback.
You may also submit your draft to me via email. I shall review and provide feedback.
(9.) Upload your actual completed entire project (clear screenshots of all your Math work and the project with all the files) in the
Midterm Project course area of the course.
Please submit all these information as a zip file in the Final Project folder of the Blackboard course.
NOTE: Any actual project submitted to me via email will not be graded.
If you wish to save some time for research:
Please review the Piecewise Function projects done by my previous students.
The direct link of the verifiable websites are included.
(I.) VB Projects
(II.) C# Projects
(III.) C++ Projects
(IV.) Java Projects
You may not do any same application done by any of my previous students for Java
You may do any Piecewise Function application not done by any of my previous students for Java.
If you are not sure what project you may or may not do, please contact me via the school email.
method, function, pre-defined method, user-defined method, method overload, parameter, argument,
Students will:
(1.) Discuss methods.
(2.) Write methods that solves real world problems.
(3.) Overload methods.
(1.) Textbook Chapter
(2.) Java Methods
(www.w3schools.com/java/java_methods.asp)
Begin from Java Methods to Java Recursion
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(3.) Type Java Methods in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(4.) Type Java Methods in the search bar and view the results.
Teacher: Guess what?
Student: We have been using a method since we wrote our first C++ program.
What is that method called?
Student: You mean the main method?
The int main()
Teacher: That is correct.
As we mentioned in the first module, every C++ program is written in the main
method.
Any code written in that main method is expected to run.
The main method is a system pre-defined method
We shall discuss methods (user-defined methods) in this module.
It is the only method that is called automatically regardless of the order in which it is
written.
In other words, whether you write the main method before or after the
user-defined method, it does not matter.
The main method is called first by the Java program.
This implies that any other user-defined method should be called in the main method
directly or indirectly.
Note that we cannot use the reserved word, main as the name of any method we define
(user-defined method).
The methods that we shall discuss in this module are user-defined methods
A method is a group of statements (block of code), that allows for reusability of those
statements/code, and performs some action when called.
Student: We just discussed Statements in the previous module.
Teacher: That is correct.
Let us deal with a group of statements in this module.
It is also known as a function.
Usually, a method takes in parameters.
Parameters are normally variables, and we declare them as we declare variables.
They method as local variables to the method that takes them.
Parameters allow us to pass arguments to the method from the location where it is
called from.
Student: To be honest, I have no idea what you just said.
What are parameters? arguments?
Teacher: Let me explain with an example.
Assume we have this method:
int sumNumbers (int num1, int num2) { return num1 + num2; } sumNumbers (5, 7) // The result will be 12In that example:
return-data-type method-name ( data-type1 parameter1, data-type2 parameter2, ...) {
statements;
}
Please submit clear screenshots of your program (all codes and the output).
For any question from the textbook, please include a clear screenshot of the question number and the
question.
(1.) Using Example $5$, include a condition that asks the user if the quadratic trinomial
is in general form.
If the user says no, ask the user to arrange the quadratic trinomial in general form before
prceeding. Then, quit the program.
If the user says yes, proceed to run the program.
Arithmetic:
Review the Definitions of Numbers on my website: Numbers and Notations
Please make sure you indicate the type of number in your comments.
(2.) Write a method that prints any of those types of numbers between one and thirty ($1$ and
$30$ are included)
(3.) Write a method that prints the first thirty numbers of any of those types of numbers.
Focus on the first positive thirty numbers of those kind of numbers.
(4.) Write a method that asks for the user to input two values (those values could be
positive, zero or negative)
The method should print all the numbers for any of those types of numbers between those two
values.
Those two values should be included if they are part of those type of numbers.
(5.) Write a method that asks the user to put in a value (that value could be positive, zero,
or negative)
The method should print thirty values of those types of numbers up to and including the
user-input value.
Geometry:
Please make sure you indicate the type of figure/shape in your comments.
(6.) Write a method that asks the user to input the required parameters for any
two-dimensional figure.
The method should return the area and perimeter of that figure.
Geometry:
(7.) Write a method that asks the user to input the required parameters for any
three-dimensional figure.
The method should return the surface area and volume of that figure.
(8.) Arithmetic:
Question (4.) on Page $165$ of your textbook.
(9.) Acturial Science:
Question (9.) on Page $165$ of your textbook.
(10.) Algebra:
Question (5.) on Page $165$ of your textbook.
Strings/Quotes:
Find a quote from any of your favorite authors or your favorite quote.
If you do not have any favorite author or a favorite quote, make up a quote yourself, and
indicate that it is your own quote.
(11.) Write a method that prints all the vowels in that quote, and returns the count.
(12.) Write a method that prints all the consonants in that quote, and returns the count.
Please submit clear screenshots of your program (all codes and the output).
For any question from the textbook, please include a clear screenshot of the question number and the
question.
Review any initial post of any of your colleagues.
(1.) Did you notice any errors in the program? Did you notice any errors after you ran the
program?
If so, constructively criticize in a respectful tone and advise your colleague.
(2.) Can you write the program using another statement?
For example: if your colleague used a for loop, you can use a while loop or do while loop
Please do and explain.
(3.) What can you add to improve the initial post of your colleague?
Comments? Alternative approach that will display the same output? Any noticeable error(s) and the
correction of those errors?
What can your colleague learn from you based on your response to the initial post?
Algebra:
Please review the Roots of a Quadratic Equation on my website: Quadratic Equations
There is a calculator I developed that calculates the roots of a quadratic equation and displays a message.
(1.)
(I.) Write a method that requests the user to input the three values: (as seen on my calculator), and
display the same message that is displayed by my calculator.
In other words, the output and message from your calculator should be the same as the output and
message from my calculator when the user inputs those three values.
Test your program for each of the four cases of the discriminant regarding the nature of the roots
of a quadratic equation as seen in Numbers $1a.$, $1b.$, $2.$ and $3.$ on my website.
(II.) Submit clear screenshots of your program.
(III.) Submit clear screenshots of the output of your program for the four cases.
(IV.) Submit clear screenshots of the output of my calculator for the four cases.
(III.) and (IV.) should display the same messages.
(2.) Geometry:
Question (8.) on Page $164$ of your textbook.
array, list, ArrayList, index, position, element, size, length,
Students will:
(1.) Discuss arrays.
(2.) Sort arrays.
(3.) Write programs that use arrays.
(4.) Pass arrays as function parameters.
(1.) Textbook Chapter
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(2.) Type Java Array in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(3.) Type Java Array in the search bar and view the results.
Simply put: An array is a list or data container that contains the
values of the same data type.
This means that an array holds or contains data values of the same data type.
So, an array can contain five integers or five strings or five floats or five doubles among
others.
Notice that the values have to be the same data type.
Why are we learning arrays?
Assume you want to work with five different integers; rather than declare five different
variables for the five integers, it is much better to declare a single integer array that will contain all five
integers.
When we declare an array in Java:
(1.) We must declare the data type of the array.
(2.) We may or may not not indicate the size of the array.
Declare an array with the size
int arrayName[] = new int[arraySize]
arrayName[] = {integer1, integer2, integer3, ...up to the size of the array}
Declare an array without the size
String arrayName[] = {"string1", "string2", "string3", ...}
Say we have:
int numbers[] = {1, 3, 7, 9, 10};
Notice that:
The elements of the array (array elements or array members) are enclosed within
curly brackets or braces
By default, the index or position of an array (array index) begins with zero index or
zero position
This is very important to note. We start counting the position/index of the elements from
zero rather than
one.
This means that:
The index of element, $1$ is $0$
The index of element, $3$ is $1$
The index of element, $7$ is $2$
The index of element, $9$ is $3$
The index of element, $10$ is $4$
We can output the index/position of an array by:
array[index] = element
This means that:
numbers[0] = 1
numbers[1] = 3
numbers[2] = 7
numbers[3] = 9
numbers[4] = 10
So: For an array of size, $n$;
the index of the first element of the array is $0$ and
the index of the last element of the array is $n - 1$
So far, what we discussed is a one-dimensional array
Let us do some examples.
Example $1$: Given an array of the first seven negative integers
Print the third element of the array
Determine the length of the array
Print the array.
Review the two approaches: print the array using: for loop and for-each loop
Compare them.
Which approach is better?
In the previous module, we learned the for loop
In printing the array using for loop, we had to loop through each element of the array using a counter.
In other words, the length of the array was needed.
In printing the array using for-each loop, we still had to loop through each array element but without using
a counter.
We used a colon, : (similar to a range-based loop in C++)
The length of the array is not needed.
I prefer using the for-each loop. So, I shall be using it more often as necessary.
But, you may choose to use whichever approach you prefer.
Example $2$: Declare an array and the size (size is known)
Student: What if we want to keep adding elements to the array?
Teacher: Very good question.
In that case, we need to use an ArrayList
We shall cover ArrayList in details in the Advanced Java course.
However, let us review an example.
Student: Mr. C
Why did you change the for-each loop?
That was not the way you used to print integers.
I do not like the one you just used.
Teacher That is fine.
The approach I used is a functional operation
It is a for-each loop
But you may use the for-each loop that we used for the integers.
This is what I did.
Initially, I used the for-each loop for the integers.
Then, I saw the light bulb warning by the side on the line.
I clicked it and clicked the option to use functional operation.
I do not like to see warnings in my code.
Hence, I used it.
One of the important topics in Data Structures and Algorithms is Sorting
Techniques
C++ has a sort already. We shall be using it.
However, you are expected to write functions for several sorting techniques.
You will be given the algorithm and pseudocode for each technique; then expected
to write a function
that will sort an array using that technique.
Please submit clear screenshots of your program (all codes and the output).
For any question from the textbook, please include a clear screenshot of the question number and the
question.
Each textbook question is to be done by only one student.
Each W3 resource exercise is to be done by only one student.
(1.) Question $(1.)$ on Page $409$ of your textbook.
(2.) Question $(2.)$ on Page $409$ of your textbook.
(3.) Question $(3.)$ on Page $409$ of your textbook.
For (4.) and (5.); Review these Sorting Techniques and Algorithms
(4.) Write a function that sorts an array in ascending order using any of the techniques.
(5.) Write a function that sorts an array in descending order using any of the techniques.
For Question (6.), please review:
Java Programming Exercises and Solutions from W3Resource
Click the Array link
Review the Exercises and the Solutions
(6.)
(I.) Select any exercise and the solution. Write the question.
(II.) Write comments for every major code block and/or line in the program.
(III.) Run the program.
(IV.) Submit clear screenshots of your program (all codes and the output).
(1.) If your collegue used a for-loop in the program, please rewrite the same program to give the same
output using a while loop or do-while loop or foreach loop
foreach loop is an enhanced for loop
(2.) If your colleague did not use a function in the program, please use a function with the array and rewrite
the same program to give the same output.
(3.) If your colleague used a function but did not use array as a parameter, please use the function and the
array as a parameter, and rewrite the same program to give the same output.
(4.) Any other substantive response.
How can you improve the initial post of your colleague?
What new knowledge can your colleague acquire from you based on your response to the initial post?
(1.) Write a function that divides an even-sized unsorted array into two equal halves, sorts the
first half in ascending order, and sorts the second half in descending order. Use any even size of at least 8 (array
size $\ge 8$).
(2.) Write a function that divides an even-sized unsorted array into two equal halves, sorts the
first half in descending order, and sorts the second half in ascending order. Use any even size of at least 8 (array size
$\ge 8$).
(3.) Question $(4.)$ on Page $409$ of your textbook.
(4.) Question $(5.)$ on Pages $409$ and $410$ of your textbook.
Students will:
(1.)
(2.)
(1.) Textbook Chapter
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(2.) Type Java Multidimensional Array in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(3.) Type Java Multidimensional Array in the search bar and view the results.
(1.)
(1.)
There are two options for your Final Exam.
Please choose only one option.
This exam is designed to assess your understanding of the Java language.
You have reviewed several topics and several concepts in each topic for eight modules.
Pick at least $1$ concept in at least $1$ topic in each of the $8$ modules.
That gives at least $8$ concepts in $8$ different topics in $8$ modules.
Find two more concepts in any topic in any module.
That gives $10$ concepts.
For each concept:
(1.) Write at least three sentences about that concept.
(2.) Develop a program about that concept.
In other words, write at least one code example about the concept.
Run the code.
Display the output.
Submit clear screenshots of your program (code and output)
Deliverables:
(1.) $10$ concepts in $10$ different topics for $8$ modules
Please write the: Module number, the Topic, and the Concept
(2.) Three sentences for each concept.
(3.) Code for each concept.
(4.) Output for each concept.
Please submit all these information as a zip file in the Final Exam folder of the Blackboard course.
This exam is designed to assess your understanding of the Java language.
Please review all the questions and answers of the
Advanced Placement (AP) Computer Science Exams
Student: Mr. C, you are giving us a final exam with the answers?
How nice of you?
Teacher: Yes of course, I am nice. 😊
But, please read on.
First-come, first-served basis
A particular question may NOT be done by more than one student.
In other words, no two or more students are permitted to do the same question.
Please:
(1.) Pick any five questions from any of the years.
(2.) Go to the Final Exam Questions forum of the Blackboard course.
(3.) Write the year and the question numbers in that forum only if it has not been written by any other student.
In other words, you need to review any year and questions posted by your colleagues and make sure that you do not attempt
the same question.
For each question:
(4.) Write it or take clear screenshots.
(5.) Develop the Java program for the solution.
The answers are already provided for you.
However, please write detailed comments in your program that explains the solution.
(6.) Run the program.
Submit clear screenshots of the code and results.
(7.) Submit clear screenshots of the: numbered questions, the Java program (including comments) of the solutions,
and the results of the five questions in the Final Exam folder of the Blackboard course.
(8.) Make your work easy for me to grade.
In other words, write detailed clear specific explanations.
Do not give me any avenue to deduct points.
For example:
First Task: Notify your colleagues of the questions you intend to do.
In the Final Exam Questions forum of the Blackboard course: you may write:
Hey guys, I am doing $2006$ Question ($2$.), $2010$ Question ($3$.), ... etc.
Second Task: Do the questions.
(1.) $2006$ Question (2.)
Write the question or take screenshots of the question.
Develop the Java program. Write detailed comments.
Run the program.
Submit clear screenshots of the code and results.
(2.) $2010$ Question (3.)
Write the question or take screenshots of the question.
Develop the Java program. Write detailed comments.
Run the program.
Submit clear screenshots of the code and results.
Third Task: Submit all deliverables.
Submit clear screenshots of the: numbered questions, the Java program (including comments) of the solutions,
and the results of the five questions in the Final Exam folder of the Blackboard course.
Should you have any questions, please let me know.
Thank you.
You are not allowed to do any of the questions in these Samples.
Please find your own set of questions.
(1.) Option $2$: Sample 1
There are two options for your Final Project.
Please choose only one option.
It is important you communicate with me for approval prior to doing this project.
The final project is designed to assess problem-solving skills using the knowledge you have acquired in the
course.
In that regard, solving at least a real-world problem using the knowledge gained in the course is expected.
(1.) Think about any of these companies: our Institution: Kent State University; your local campus; your work place; public and
private schools (excluding home schools); organizations, firms, and businesses
(excluding controversial firms and the like).
Any company you choose should have a verifiable website.
The direct link of the company's website is required.
(2.) Identify a problem on the website that you want to solve.
The problem must be solved by programming using the knowledge acquired from any of the course
topics/concepts/description/learning objectives.
Think about your Midterm Project. You solved a problem: calculating bills, federal taxes, etc.
(3.) Develop the computer program to solve the problem.
Test the program to ensure that it works.
Write detailed comments as applicable.
(4.) Prepare a Documentation Manual/Reflection for the project.
Please cite your sources accordingly.
What is the company?
What is their website?
What problem did you identify?
Did you solve the entire problem or part of the problem?
What course topics/concepts/description/learning objectives did you apply in solving the problem?
How did you solve the problem?
Did you encounter any issues while trying to solve the problem?
Are there any limitations to the project?
Are there any recommendations to the company?
Deliverables:
(1.) Program (all files)
(2.) Clear screenshots of your program (code and output)
(3.) Project Reflection/Documentation Manual
Please submit all these information as a zip file in the Final Project folder of the Blackboard course.
The final project is designed to assess your understanding and analysis of data using the knowledge you have
acquired in the course.
Please:
(1.) Visit my website on: Descriptive Statistics
(2.) Review the information for a good understanding of Descriptive Statistics.
It is highly likely that you have a prior knowledge of this topic. Is that right?
(3.) Click the Project link.
(4.) Review the Project Examples. Ensure you follow all the instructions and directions.
(5.) Complete the Final Project for your course.
(6.) Ask questions. I can advise.
(7.) Upload your draft project (clear screenshots of all your Math work and the .exe file)
in the Midterm Project Drafts forum of the course on Blackboard.
I shall review and provide feedback.
You may also submit your draft to me via email. I shall review and provide feedback.
(8.) Upload your actual completed entire project (clear screenshots of all your Math work
and the project with all the files) in the Midterm Project course area of the course.
Please submit all these information as a zip file in the Final Project folder of the Blackboard course.
NOTE: Any actual project submitted to me via email will not be graded.
Course using Java abstract data types and objects, object-oriented, event-driven design, file organization and access, and systems programming concepts. Prerequisite: IT 20011.
By the end of this course, you should be able to do the following:
(1.) Demonstrate Advanced Inheritance Concepts including Abstract Classes, Dynamic Method Binding Arrays of
Subclass Objects, Software Design and Interfaces.
(2.) Perform Exception Handling and Debugging.
(3.) Demonstrate the use of File Input and Output.
(4.) Explain the role of Multithreading.
Students will:
(1.) Discuss the terms used in object-oriented programming.
(2.) Create a class.
(3.) Create a constructor.
(4.) Implement different constructors.
(5.) Overload constructors.
(6.) Create a destructor (destroy a constructor).
object-oriented programming, class, object, namespace, access modifier, public, private,
(1.) Textbook Chapter
(2.) Java Classes: From Java OOP to Java Modifiers by W3Schools
(3.) Object-Oriented Programming Concepts by Oracle
(4.) Designing a Swing GUI in NetBeans IDE
by Apache NetBeans
(5.) Learning Swing with the NetBeans IDE
by Apache NetBeans
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(6.) Type Object-oriented Programming in Java or OOP in Java in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(7.) Type Object-oriented Programming in Java or OOP in Java in the search bar and view the results.
If you are using the NetBeans IDE:
Please:
(1.) Review the screenshots of Module $1$ to increase the font size of your code in the IDE
(2.) Review the screenshots of Module $3$ to increase the font size of the output of your program in the IDE
Teacher: So, we discussed data types and variables
We did some work/calculations with the data types and variables.
Our project started to grow.
We needed to lessen codes and reuse codes. Simply put, we wanted to do more with less.
We introduced functions to achieve that goal.
Functions included the data types, variables and the work/calculations done with
them.
The project started getting large and popular. It needed to serve more clients.
What should we do?
Can we join data types, variables and functions as a package? Can we reuse that package as
much as we want?
The answer is Yes!
Welcome to Classes
Student: Where did the object-oriented come from?
Teacher: Good question.
Remember how we call a function any time we wanted to use that function?
We shall 'call the class', well create a new instance of the class anytime we want to use that class.
So, whenever we create an instance of the class because we want to use that class, we have created an
object
That means that an object is an instance of the class.
Student: So, what you are saying is that an object is simply calling the class in order to use it?
Just like we do in functions?
Teacher: That is correct.
Simply put, creating an object means calling the class.
We can create as many objects as we want by calling a class anytime we want.
The class is a package of data types, variables and functions.
Actually, a class is a package of fields, methods, and properties.
Creating and using objects to develop computer programs is known as object-oriented
programming.
Encapsulation is the combination of fields, properties, methods, and events of an object
in a class(capsule).
In other words, keep all the data and program logic in one place.
Student: You introduced some words.
Teacher: Yes, I did.
No worries you will get used to them.
The field is the data type and variable.
The field is often referred to as an attribute.
The method is a function
The property allows us to change the fields.
The fields, properties, and methods are referred to as the class members
Recall how we write out first application in Module $1$ of the Beginning Java class
As seen from the screenshots, a public main class is created anytime a Java project is created.
The name of the public main class is the same as the name of the Java file.
Class names are written in uppercase or Pascal case.
What is my first greeting to my students?
Welcome to our IT 36311: Advanced Java Programming class!
So, let us create a class called ComputerScience
Example 1: Welcome to our IT 36311: Advanced Java Programming class!
Notice we used the keyword, new
And we greeted the student object, student1 with the greeting we defined in the ComputerScience
class by joining the object with the variable using the member access expression, . (the
period punctuation mark).
Student: This is what I don't get.
Why use public?
Teacher: We used public so we could access that variable, greeting outside the
class that it was defined.
If we used private, we would not be able to access the variable outside that class.
No worries, we shall discuss that later in this module.
Example 2: Let us greet two students.
In this case, we have to create two objects.
The teacher should greet the student.
Create a class that has three members: three fields and one method.
Student: Mr. C, you used the same name for the field and for the main method
Is that not a bad programming practice?
Teacher: My dear, you are correct.
It is better to use different names.
Please correct it on your end.
Teacher: What happens as our project expands?
If we want more functionalities (fields and methods), do we have to keep writing them in the same program?
Can we write this using another approach?
Student: I think so...since you talked about it.
Teacher: Sure...we can.
Let us create another Java file.
We shall leave the initial class in the Java file...the file where it is.
Let us create another Java file and put the main method in it.
Both files should be in the same project folder.
This means that both files will have the same package.
The second file that we will create will be a new Java class named Greeting
Because this file will have the main method, we shall use it as the main class.
Student: I guess this is similar to what we did in C++...with header files.
where we create a header file, write our programs, then include it (by referencing it) in another file that
has the main method.
Teacher: That is correct.
Let's do what we just discussed.
Cut the entire main method in the ComputerScience class and Paste it in the Greeting class
Go ahead and run it.
Wait. Before we run it, let us give another name for the String, "greeting". Let's call it "welcome".
Also, modify the comments in both classes.
As you can see, we have the same output.
This is known as using Multiple Classes
It is necessary for better organization of classes.
We can have as many classes as we want, provided all those classes are under one package.
Student: What if students want to greet their fellow students?
Teacher: Good question.
We want students to greet themselves.
We already know that Chukwuemeka is the teacher and Samuel is the student.
Let's say we want another student, Dominic.
The teacher would greet the two students, Samuel and Dominic.
Each student will greet the other as well.
In other words:
Chukwuemeka will greet Samuel
Chukwuemeka will greet Dominic
Samuel will greet Dominic
Dominic will greet Samuel
So, we have four greetings of "Welcome to our Class!"
Static Methods
If we do not want to create an object and use the object to call the method, we can just use a static method
In that case, the keyword, static is used with the name of the method.
The use of a static method also allows us to call the method directly
Let us review an example.
Student: There's much limitation with the static method.
We might as well just write the statements directly under the class.
I have a question.
What if we have different names for the teachers and students?
Do we need to keep defining each name as a field when we have a new teacher and new students?
Teacher: Good question.
More functionalities means that we should find a way of achieving the same output with less code.
This leads to...
What we can do to address your question is to create a constructor.
A constructor in Java is a special method that:
has the same name as the class; used to initialize objects; and
does not return values.
Hence, whenever we create an object (the instance of the class), the constructor is called.
The constructor is a method. So, it needs to have an access modifier.
Note that it should have the same name as the class name.
So, you can say that is a special method because it has an access modifier, has the same name as the
class name, may or may not have parameters that would be defined as initial variables or values of the class
members, and does not return any value.
There is always at least one constructor in every class.
If a class is created without a constructor, the compiler creates a default constructor for that class.
Java constructors are:
(1.) Default Constructor (also known as a Parameterless Constructor or No-argument Constructor)
(2.) Parametized Constructor
A default constructor is a constructor that has no parameter.
It is a parameterless constructor.
The syntax for a default constructor is:
access modifier ClassName() { statement; }Let us implement a default constructor
A parametized constructor is a constructor that has at least one parameter.
The syntax for a parametized constructor is:
access modifier ClassName(parameter1, parameter2, ...) { statement; }We shall use parametized constructors frequently in the course.
We can overload constructors, just as we overload methods
This implies that we can create two or more constructors with the same name but different parameters.
Let us overload a default constructor and a parametized constructor.
Let us overload two parametized constructors.
(1.) Write a program for a scenario/case/example where you would:
(I.) Implement any of the constructors that we discussed.
(II.) Use a combination of at least two different data types for the class fields.
This implies that you should have at least two class fields of different data types.
(2.) Write a program that overloads at least two constructors.
(1.) Write a different constructor that will give the same output as the constructor used in the initial post.
For Questions $(1.)$ and $(2.)$
The questions involve Desktop Applications
If you would like to know how to develop desktop applications with Java and Swing, please review
Module 1 of the Beginning Java course.
Even if you do not attempt these questions, it is important to learn that module because desktop applications would be
required for your Midterm Project and your Final Project.
No worries, Mr. C is here to help.
(1.) Develop a desktop application titled: Object-oriented Programming Basics
The application should include at least one button that:
(I.) Implements any of the constructors that we discussed.
(II.) Use a combination of at least two different data types for the class fields.
This implies that you should have at least two class fields of different data types.
(2.) Develop a desktop application titled: Object-oriented Programming Basics
The application should include at least one button that overloads at least two constructors.
I am more interested in the functionality.
However, I am also interested in the design/graphics/aesthetics.
Make a good design.
(3.) Textbook Question: Question $(12.)$ on Page $165$ of your textbook.
(4.) Textbook Question: Case Problem: Question $(13.)$ on Pages $166$ of your textbook.
Students will:
(1.) Discuss the concept of Encapsulation.
(2.) Discuss the properties of a class
(2.) Implement the various properties in a class.
(3.) Develop a console application that implements classes, objects, constructors, and properties.
(4.) Develop a desktop application that implements classes, objects, constructors, and properties.
get, get accessor, getter, set, set accessor, setter, void, parametized constructor, exceptions, throw an exception, encapsulation, reference, dependency, event, event handler, backing store, solution, container, event, event handler, tuple, trigger, behavior
(1.) Textbook Chapter
(2.) Java Modifiers and Java Encapsulation by W3Schools
(3.) Object-Oriented Programming Concepts by Oracle
(4.) Designing a Swing GUI in NetBeans IDE
by Apache NetBeans
(5.) Learning Swing with the NetBeans IDE
by Apache NetBeans
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(6.) Type Object-oriented Programming in Java and/or OOP in Java in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(7.) Type Object-oriented Programming in Java and/or OOP in Java in the search bar and view the results.
We used the public access modifier in Module $1$
We have other access modifiers.
By default, codes are only accessible in the same package.
Access Modifier | Accessibility Level |
---|---|
public | Access is not restricted. The class member can be assessed outside the class that it was created. |
private | Access is limited to the containing type. The class member can only be assessed within the class it was created. |
protected | Access is limited to the containing class or types derived from the containing
class. The class member can be assessed within the class it was created, or in a class that is inherited from the class that it was created. |
Let us do some examples.
We shall demonstrate the use of private access modifier.
Say I want to greet a specific student in my class with my mother tongue: the Igbo language.
If you point your mouse at the error, it reads: greeting() has private access in Encapsulation
You also see the message at the bottom left corner of your IDE (as seen in the screenshot).
If you click the light bulb at the beginning of that line, and double-click on the "recommended message", you
will notice that the IDE has removed the private access modifier in the method: greeting
Go ahead and run the program.
Teacher: Notice the error?
Student: Yes. I guess it's because the welcome attribute is private?
Teacher: That is correct.
The greeting method cannot access the private welcome
Student: So, we have to remove the private modifier
Also what is the meaning of the greeting?
Teacher: The greeting means: Welcome to our School
Yes we can remove the private modifier and the program will run.
However, every student will hear the greeting and some students will not understand the language.
Some may have issues with it.
Student: Well, just explain the meaning. Translate it for all the students.
Teacher: I want to greet only the student with the Igbo language.
What should I do?
Also, have you heard of Cryptology?
Cryptology is the science of secret messages.
If you don't want everyone to access that message, you encode the message with a private key, and give the key to
any person you want to decode the message.
So, in this case; this is what we can do.
Welcome to ...
Encapsulation
Encapsulation is the combination of fields, properties, methods, and events of an object in a class (capsule).
In other words, keep all the data and program logic in one place.
It is used to hide sensitive data from users.
An important part of Encapsulation is the use of properties.
A property is typically a public class member that can read, write, or
compute the value of a private field.
Just like a constructor, a property is also a method.
So, it needs an access modifier.
That access modifier typically, must be public.
The accessors are the: get accessor and the set accessor.
In other words, the get and set parts of a property are called accessors.
The main objective of using Properties is for encapsulation in terms of hiding sensitive data from users.
Properties in Java:
(1.) Typically have a public access modifier.
(2.) Comprises of the get and set accessors.
The get accessor is also known as the getter
The set accessor is also known as the setter
The get property accessor is used to: read, compute; then return the property
value.
It gets and returns that private field/class member.
The set property accessor is used to perform some data validation, compute; then
write or assign that private field/class member to a value.
(3.) Can be read-write if it has both the get and set accessors.
(4.) Can be read only if it has only the get accessor.
(5.) Can be write only if it has only the set accessor.
Write-only properties are mostly used to restrict access to sensitive data.
Recall:
(1.) Constructor has the same name as the Class.
(2.) Class names are uppercase or Pascal-case.
(3.) Field names are lowercase.
In that regard, it is recommended that Property names be uppercase of the field names.
The syntax for the Getter is:
public dataType propertyName() { return privateAttribute; }The syntax for the Setter is:
public void propertyName(dataType newName) { privateAttribute = newName; }So, let us solve this problem by using Properties.
Please review the BMI information on these two government websites [from the Center for Disease Control and Prevention (CDC) and the National Heart, Lung, and Blood Institute of the National Institutes of Health (NIH)]
About Adult BMI | Healthy Weight, Nutrition, and Physical Activity | CDC and
Calculate Your BMI - Standard BMI Calculator
As at today, the 3rd day of September, 2020; the BMI information on both websites are:
NIH website
Calculate Your BMI - Standard BMI Calculator
CDC website
About Adult BMI | Healthy Weight, Nutrition, and Physical Activity | CDC
$ BMI = \left(\dfrac{weight}{height * height}\right) * 703 \\[5ex] weight\:\:is\:\:in\:\:pounds (lb) \\[3ex] height\:\:is\:\:in\:\:inches (in) $
$ BMI = \left(\dfrac{weight}{height * height}\right) \\[5ex] weight\:\:is\:\:in\:\:kilograms (kg) \\[3ex] height\:\:is\:\:in\:\:meters (m) \\[3ex] $ If you need help with conversion of units, please review the Tables and Examples in Measurements and Units
Teacher: What do you notice in both websites?
Student: They both have the information on the BMI.
In addition, the CDC website has information for both Adult BMI and Child & Teen BMI among others.
The NIH website has recommendations among others.
Teacher: That is correct. What else?
Student: They have the BMI calculator.
Teacher: Did you notice any difference in the calculator on both websites?
Student: The NIH website has BMI calculator for both Standard and Metric versions.
The CDC website has the BMI calculator for only the Metric version.
Teacher: Did you notice any issue/concern about the BMI information?
Student: Not really. Why?
Teacher: So, this is what we are going to do.
We are going to develop the BMI calculator.
That calculator will calculate the BMI.
Then, we shall interpret that BMI, and make a recommendation.
.
The CDC website gave us the formula for calculating the BMI. So, we shall use it.
As you can see, our calculator would have to use conditional statements for the interpretation and recommendation.
But, here is the issue.
Student: Wait, I think I see the issue.
The issue is with the domains.
Teacher: Correct!
Anyone having a BMI between $18.5$ and $24.9$ both endpoints included has a Normal weight.
This is: Normal weight: [18.5, 24.9]. It is a closed interval (relate with Mathematics).
So, the Overweight range for the BMI should be the weight greater than $24.9$, (rather than beginning from $25$) and ending at $29.9$
For the Overweight range, the first endpoint is not included, but the second endpoint is included.
This is: Overweight: (24.9, 29.9]. It is a half-open half-closed interval (relate with Mathematics)
Teacher: Do you know why this would be a problem if the programmer does not fix these issues before developing the calculator?
Student: Yes. Because there would not be any interpretation for anyone whose BMI is between $24.9$ and $25$
But, I do see that the BMI information is for values rounded to one decimal place.
Teacher: That is correct.
And we shall develop our calculator to round to one decimal place.
But, it is important we fix the issues.
What if we do not want to round?
Look at the two examples on the CDC website. The BMI values were rounded to two decimal places.
If we developed our calculator to round to two decimal places with the information on those websites "as is"; then we would not have the interpretation and recommendation for those two examples ($24.98$ and $24.96$) because those values are greater than $24.9$ but less than $25$.
Student: That makes sense.
So, the last one: Obese should be BMI greater than $29.9$, rather than greater than $30$?
Teacher: That is correct.
So far, we discussed:
(1.) Methods (Functions) in Java Programming
(2.) Introduction to Object-oriented Programming (Classes, Constructors, and Objects) in Module 1.
(3.) Encapsulation in this module: Module 2.
We are going to apply what we learned so far.
We shall develop a console application and a desktop application for the Body Mass Index (BMI) calculator.
(1.) The program should accept user inputs of:
(I.) First name
(II.) Last name
(III.) Weight
(IV. Height
(2.) The program should output the:
(A.) BMI value
(B.) Interpretation
(C.) Recommendation
(3.) The program should address user-input errors of non-positive numbers for the weight and the height.
Inform the user.
Then, exit the program without causing it to crash.
(1.) We shall create a new project: AdvancedJavaModule2
As we discussed earlier, the The project name is the name of the public class: AdvancedJavaModule2
The project name is also the name of the Java file: AdvancedJavaModule2.java
The name of the namespace is: advancedjavamodule2
(Notice the name is all lowercase of the Java file name)
We shall create another Java file under the same package.
We demonstrated this concept in Module 1.
That class will be the Main class because it will contain the main method.
Let us name that class: BodyMassIndex.java
(2.) Because the first name and the last name is not needed in the calculation, we shall ask for the user input
of the first name and last name in the main method
The main method is in the BodyMassIndex public class
The BodyMassIndex public class is in the BodyMassIndex.java file
Teacher: You know something I learned in America...as regards dating?
Student: What is it?
Teacher: You should not ask a woman her weight.
Student: LOL. Is that all you learned?
Teacher: Another thing is that you should not ask a woman her age.
But, a woman can ask a man his age.
Student: That is correct. In America, you do not ask a woman her weight or her age.
Teacher: Is that not double standard?
Anyway...B2B (back to business)
(3.) We shall create two fields: weight and height for our class: AdvancedJavaModule2
Because we shall associate the weight and height with the user's first name and last name, we shall declare
these fields as private.
(4.) We shall create public properties for these private attributes so we can access them.
Remember that method names in Java should begin with uppercase letter.
Property is a special method.
So, the properties should be the uppercase beginning letters of the variables.
(5.) We shall create a parametized constructor that will initialize the class attributes.
Assign the attributes to the constructor parameters.
(6.) We shall create a method: BodyMassIndexDetails
This method is necessary to calculate the BMI.
We need to throw an exception to ensure that only positive values are entered for the user input weight and
height.
Zero and negative values should not be allowed.
No worries. We shall disuss Exception Handling in details in another module.
For now, please learn how to do it in this application.
In addition, we shall interpret the BMI and make recommendation based on the calculated BMI value.
We shall create three more variables here. These variables are local variables.
For local variables that are directly calculated from the class fields, we do not need to initialize.
However, for local variables that are not directly calculated from the class fields,
we must initialize those variables.
(7.) Go to the main method in the BodyMassIndex public class class and ask for user input of the
first name, last name, weight, and height
We will declare two more variables for the: weight and the height in the main method.
We shall use that weightPounds and heightInches as our variables.
Notice that they are the constructor parameters we used in the AdvancedJavaModule2 class
In other words: our constructor parameters in the AdvancedJavaModule2 class are the
weightPounds and heightInches variables in the BodyMassIndex class
Create the object: calculateBMI
Use that weightPounds and heightInches as the arguments
Display your summary and make it look nice.
To use a background color in the Netbeans console window:
\033[43m is the code that gives a yellow background.
Use the object to call the method.
(8.) Test your program for each piece/case.
In other words, test your program to ensure that the calculation, interpretation, and recommendation is correct
for all the BMI options.
You may also test the examples on the CDC website.
(9.) Test your program to check for user input errors.
In other words, test your program for the Exceptions.
Please see the images.
Review the comments.
![]() |
![]() |
![]() |
![]() |
Exceptions:
Please review the Teacher-Student scenario
Student: Mr. C, why do we need to develop desktop application?
Can't we just focus on console applications?
Teacher: Desktop applications are required for several DB assessments and for your Midterm Project.
It is optional for your Final Project.
It is important you learn to develop them.
Student: But, why?
Teacher: These are the reasons:
(1.) GUIs (desktop applications) cover a significant part of Number (1.) of the Student Learning Outcomes of the Beginning Java course.
They also cover some parts of Numbers (2.), (3.), and (4.) of the Beginning Java course.
(2.) You can run the executable JAR (.jar) file of a desktop application in any desktop/laptop that has
Java installed in it (both Windows and Mac)
Student: What are executable JAR files?
Teacher: Good question.
When you develop a Java program with Swing components such as the one we shall develop in a moment,
an executable file can also be developed. It is a file that is run on your computer to execute (do) something on your computer.
When you download and install a program on your computer (Windows users), it is normally seen as install.exe,
setup.exe or other "something".exe with the word, Application used to describe it.
In our case, it is going to be a standalone file with the jar extension described by
Executable Jar File that when downloaded in any desktop, can run when double-clicked.
Usually, you will get a warning from your computer not to download it because it can destroy your computer.
If you do not know the source/origin of the executable file, do not download it.
But in this case, we shall develop the program so we know it is safe.
When we develop the program, we need to follow these steps to locate the executable file.
Double-click: Application folder $\rightarrow$ dist $\rightarrow$ Application.jar
That Application.jar file is the executable file.
You can download it (no worries, it is safe), save it on your desktop, and run it on your desktop whenever
you want to.
Student: If I copy it to another desktop, will it run?
Teacher: Yes, it will run on any desktop provided that Java is installed on that computer.
That is the nice thing about it.
Student: Just that file?
It will run with all the functionality?
Without copying the entire folder?
Teacher: That is correct.
Click these links and review some of the desktop applications done by my students:
VB desktop applications and
C# desktop applications
These will run without any additional download.
Desktop applications are much better than console applications.
If you click the PROJECTS tab of this website and review the console applications done by my students,
you will realize that you need to type at least one command in the console before you can run the application.
If you review the PROJECTS (console applications) done by my C++ students,
it may require some program downloads to run on your machine (laptop/desktop).
You do not have to worry about typing commands or extra downloads when running desktop applications.
Student: Pretty cool.
Teacher: Yes, it is.
(3.) Assume you are working in a developing country (in Nigeria for example), you have a computer but no
internet service, and you really need to develop applications for the projects you are working on;
developing desktop applications is highly recommended in such cases because you do not need the Web/Internet
to run them. All you need is a laptop or desktop.
Student: But, I'm not working in Nigeria.
Neither do I intend to work there.
Teacher: What if you work for a multinational company and your compnay transfers you to work there?
What if you decide to join your church or organization on a charity mission trip?
(4.) Have you heard that the only thing that is not safe is anything on the Web?
Well-developed desktop applications minimizes your use of web and mobile applications, thereby minimizing cyber crimes.
There are limitations with desktop applications.
But, there are advantages too.
One of the advantages of Java is the developement of Desktop aplications.
Let us a Body Mass Index (BMI) desktop application. 😊
As is the case for development of desktop applications, the three basic things to do are:
(1.) Create the user interface
(2.) Set the properties.
(3.) Write the program code.
$(1.)$ JFrame Form
(A.) Add a JFrame Form
(B.) Adjust the form in the Design area
(C.) Set the font property of the form to:
Font: Times New Roman Font Style: Plain Size: $16$
(D.) Set the title property to Body Mass Index (BMI) Application
$(2.)$ Label
(A.) Add a label aligned to the left
(B.) Change thetext Property to: First Name at the Properties window
(C.) Press the ENTER key
(D.) Adjust the size
Go to the Properties window and change the font property to: Font: Times New Roman Font Style:
Plain Size: $16$
Let us run it to see how it looks before we continue.
Notice we unchecked that box to Create a Main Class when we were creating the Project.
This is because we want the JFrame Form: now titled: bodymassindex.BMIApplication.java to be the Main Class.
Close the app.
Close it again.
Let us change it to font size of $24$ and run it again.
$(3.)$ Text Field
(A.) Add a text field aligned to the right
(B.) Delete the text property: jTextField1
(C.) Go to the Properties window and change the font property to: Font: Times New Roman Font
Style: Plain nbsp; Size: $24$
(D.) Align the user-entered text to the center.
In the Properties window, set the horizontalAlignment property to CENTER
(E.) Right-click the text field and Change Variable Name to firstNameTextField
$(4.)$ Duplicate the First Name label by right-clicking the label and clicking the Duplicate option.
Change the text property to Last Name
$(5.)$ Duplicate the Last Name label.
Change the text property to Weight
$(6.)$ Duplicate the Weight label.
Change the text property to Height
$(7.)$ Duplicate the firstName text field.
Change Variable Name to lastNameTextField
$(8.)$ Duplicate the lastName text field.
Change Variable Name to weightTextField
$(9.)$ Duplicate the weight text field.
Change Variable Name to heightTextField
$(10.)$ Align the labels and the text fields accordingly.
Adjust as needed.
$(11.)$ Copy the Weight label, paste it, and move it to the right of the weight text field.
The label is for the unit of the weight.
Change the text property to pounds
Adjust and align.
$(12.)$ Copy the Height label, paste it, and move it to the right of the height text field.
The label is for the unit of the height.
Change the text property to inches
Adjust and align.
$(13.)$ Button
(A.) Add a Button.
Align the left hand side to the left, and Adjust.
Change the font property to: Font: Times New Roman Font Style: Plain nbsp; Size: $24$
Change the text property to Calculate BMI
Change Variable Name to calculateButton
(B.) Add another button in the form.
Adjust.
Change the font property to: Font: Times New Roman Font Style: Plain nbsp; Size: $24$
Change the text property to Reset
Change Variable Name to resetButton
(C.) Add another button in the form.
Align the right hand side to the right and Adjust.
Change the font property to: Font: Times New Roman Font Style: Plain nbsp; Size: $24$
Change the text property to Exit
Change Variable Name to exitButton
$(14.)$ Text Area
Add a text area.
The output will be displayed in the text area.
Align to both ends: the left hand side and the right hand side of the controls; and Adjust.
Change the font property to: Font: Times New Roman Font Style: Plain nbsp; Size: $24$
Change Variable Name to resultTextArea
The Design Area is:
The Inspector Area is:
The Palette (ToolBox Controls) are:
The Property Editor is:
Now, onto the Coding part....
(1.) Double-click the Calculate BMI button to go to the Source Area
Write the code that will display the result in the text area.
(2.) Create a new Java class: BMIApp under the same package
The Property Editor is:
(3.) Copy all the code in the "other" class (not the Main class): AdvancedJavaModule2.java that we did for
the Console Application.
Do not include the public class name.
Paste the code inside the BMIApp class
Change the constructor name to the BMIApp
Make some changes regarding the results.
In other words, use a StringBuilder class.
This is necessary because we want to print the results from the BodyMassIndexDetails method in the
BMIApp class to the text area in the BMIApplication class.
(4.) Open the Main class for the Console Application: BodyMassIndex.java
Copy some code.
Paste the code in the Main method in the Desktop Application class: BMIApplication.java
Modify the code.
(5.) Double-click the Reset button to go to the Source Area
Write the code that will clear all entries in the text fields.
(6.) Double-click the Exit button to go to the Source Area
Write the code that will close the application.
Please review the screenshots and the comments.
(1.) Test the program for each condition (the conditional statements for the BMI)
(2.) Test the program for Exceptions (exception handling).
Publish our GUI as a Desktop Application
This means that we have to create an executable JAR (Java ARchive) file.
To do this, we need to Clean and Build Project (Clean and Build the Introduction project) or press the
Shift + F11 keys on
your keyboard.
When this is done, the dist folder is created.
That dist folder contains the Executable JAR file.
Please review the screenshots.
Student: I have a question.
If I decide to make some changes to the code, will those changes be automatically reflected in the app
even though the app has been published?
Teacher: Good question.
Whenever you make changes to your program code, then you will need to Clean and Build Project again.
An updated executable jar file will then replace the previous one.
So, you will need to re-download the new file.
For example: let us make a change to the title of the application.
Compare the title of the application on the screenshots with the title of the application on the JAR executable file
Did you notice the change?
The new file was downloaded after making the change, and doing Clean and Build Project
This is the BodyMassIndexApplication.jar executable file
You may click the link to download and run it. No worries, it is safe.
It is a desktop application.
If you have Java on your computer (PC or Mac desktop/laptop), click the file and run the application directly on your desktop.
For Questions (1.) and (2.)
(I.) Consider any concept/scenario that uses conditional statements.
Use at least two (two or more) different conditions.
The BMI Calculator has four different conditions.
But, please use any application that has at least two different conditions.
(II.) Accept user input(s).
(III.) Use a class you created.
(IV.) Use at least one private field.
(V.) Use properties that should access that private field.
(VI.) Use at least one method.
(VII.) Include some checks for user input errors.
(VIII.) Test your program and display the result/output for each condition.
(IX.) Test your program for user-input errors.
(X.) Submit all the screenshots in your DB 2 forum on Blackboard.
(1.) Develop a console application for your concept.
(2.) Develop a desktop application for your concept.
(1.) If your colleague developed only a console application, develop the desktop application for that concept.
(2.) If your colleague developed only a desktop application, develop the console application for that concept.
(3.) Other substantive responses.
For Question (1.)
(I.) Consider any concept/scenario that uses conditional statements.
Use at least two (two or more) different conditions.
The BMI Calculator has four different conditions.
But, please use any application that has at least two different conditions.
(II.) Accept user input(s).
(III.) Use a class you created.
(IV.) Use at least one private field.
(V.) Use properties that should access that private field.
(VI.) Use at least one method.
(VII.) Include some checks for user input errors.
(VIII.) Test your program and display the result/output for each condition.
(IX.) Test your program for user-input errors.
(X.) Submit all the screenshots in your DB 2 forum on Blackboard.
(1.) Develop a console application and a desktop application for your concept.
One application will count for DB Post.
The other application will count for DB Response.
Please specify which one should count for DB Post or DB Response.
(2.) Develop a console application for an extension of my concept (the BMI application).
I did the application for the United States System (Customary System).
Extend the application by developing the calculator for the International System (Metric System).
The formula is on the screenshot.
Ask the user which system he/she wants to use to calculate the BMI.
Based on the user's selection, display the appropriate units for the weight and the height, as well as the output.
Test all the conditions for both systems.
(3.) Develop a desktop application for an extension of my concept (the BMI application).
I did the application for the United States System (Customary System).
Extend the application by developing the calculator for the International System (Metric System).
The formula is on the screenshot.
Ask the user which system he/she wants to use to calculate the BMI.
Your desktop application should have the dropdown list for both systems, but should be null be default.
Based on the user's selection, display the appropriate units for the weight and the height, as well as the output.
Test all the conditions for both systems.
(4.) Textbook Question: Case Problem: Question $(1.)$ on Pages $167$ and $168$ of your textbook.
(5.) Textbook Question: Case Problem: Question $(2.)$ on Pages $168$ and $169$ of your textbook.
(1.) Textbook Chapter
(2.) Java Exceptions (All) by Oracle
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(3.) Type Java Exception and/or Java Exception Handling in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(4.) Type Java Exception and/or Java Exception Handling in the search bar and view the results.
The midterm project is designed to assess your knowledge of Object-oriented Programming in solving real-world problems.
It is a Piecewise Function application.
Any other application will not considered.
Please:
(1.) Visit my website on: Piecewise Functions
(2.) Read the Story to understand the idea of Piecewise functions.
(3.) Read the Overview of Piecewise Functions for more understanding of Piecewise
functions.
(4.) Study the Applications of Piecewise Functions
(5.) Review the Project Examples. Ensure you follow all the instructions and directions.
(6.) Complete the Midterm Project for your course.
(7.) Ask questions. I can advise.
(8.) Upload your draft project (clear screenshots of all your Math work and the .exe file) in the Midterm Project Drafts forum of the course on Blackboard.
I shall review and provide feedback.
You may also submit your draft to me via email. I shall review and provide feedback.
(9.) Upload your actual completed entire project (clear screenshots of all your Math work and the project with all the files) in the
Midterm Project course area of the course.
NOTE: Any actual project submitted to me via email will not be graded.
If you wish to save some time for research:
Please review the Piecewise Function projects done by my previous students.
The direct link of the verifiable websites are included.
(I.) VB.NET Projects
(II.) C# Projects
(III.) C++ Projects
(IV.) Java Projects
You may not do any same application done by any of my previous students for Java
You may do any Piecewise Function application not done by any of my previous students for Java.
If you are not sure what project you may or may not do, please contact me via the school email.
inherit, inheritance, behavior, data, class members, colon symbol :, parent class, base class, super class, child class, derived class, extended class, sub class, ancestors, single inheritance, multilevel inheritance, transitive inheritance, override, abstraction, abstract class, abstract method, interface, polymorphism, interface, enum, enumeration,
Students will:
(1.) Discuss the inheritance of a class.
(2.) Discuss polymorphism in object-oriented programming.
(3.) Write programs that demonstrate the inheritance of a class.
(4.) Write programs that demonstrate polymorphism.
(1.) Textbook Chapter
(2.) From: Java Inheritance to: Java Enums by W3schools
(3.) Interfaces and Inheritance (All: From: Interfaces to: Questions and Exercies) - The Java Tutorials by Oracle
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type Java Inheritance and Polymorphism in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(5.) Type Java Inheritance and Polymorphism in the search bar and view the results.
There are three primary characteristics/pillars of object-oriented programming:
(1.) Encapsulation
(2.) Inheritance
(3.) Polymorphism
A teacher, Mr. C with his three students: Student $1$, Student $2$, and Student $3$
The students are dual enrolled high school students.
They are bold and smart.
They are taking a Computer Science course with Mr. C
Teacher: Today, we shall be discussing Inheritance
Student $1$: Is this a Biology class?
Teacher: Why do you ask?
Student $2$: Why do you answer questions with questions?
Teacher: Typical of Nigerians 😊
It saves you from getting into trouble.
Student $1$: I asked because we are studying Genetics.
Teacher: Interesting.
So, we can use some interdisciplinary knowledge from both courses.
My first question is:
What did you inherit from your parents: Dad, Mom, Grand Dad, Grand Mom (Father's side), Grand Dad, Grand Mom
(Mother's side), several generations on both sides, atavism?
Student $2$: What do you mean by atavism
Student $3$: It's a reappearance of an ancestral trait.
For example: Remember those Nigerian parents (both of them are Black) that gave birth to a white baby girl?
One of the reasons the doctors gave was dormant white genes which entered both of the female's parents' families
long ago.
That is atavism.
You can read the story online. Wait: here is the link from CBS News:
(https://www.cbsnews.com/news/white-baby-shocks-black-parents-medically-possible/)
Student $1$: CBS News? LOL
Teacher: Hey, do not say what you want to say.
This is not politics.
Student $1$: And what if I do?
Student $3$: Some other news sources have it as well.
Teacher: Okay guys, you have not answered my question.
Student $2$: Well, as you can see: I have blonde hair and blue eyes.
But surprisingly, my parents have brown hair and brown eyes.
Why is that?
Student $1$: Your parents have the dominant brown hair and brown eyes genes and the recessive blond hair
and blue eyes genes.
They passed those recessive genes to you.
Student $2$: Interesting.
But, if I want my children to have those dominant brown hair and brown eyes genes, what should I do?
Student $1$: Let me just invite you to our Biology course so you ask those questions.
I am still learning.
But, just pray for it. Do not do anything to try to disrupt nature.
Teacher: Okay, get back on track to my questions.
Student $3$: I inherited intelligence from my parents.
Student $1$: So, we had this argument in class: Is intelligence acquired or inherited?
Is it by nature or nature or both?
Teacher: Intelligence is both nature and nurture though it is more of nurture.
Student $1$: What are your reasons, Sir?
Teacher: You have two Nigerian parents, did not attend school did not have any formal education; yet
their children are the best graduating medical students.
Student $1$: Well, the fact that they did not attend school does not mean that they are not intelligent.
Someone who is not literate can still be intelligent. I think intelligence is wisdom.
Student $3$: I inherited tallness from my Mom.
My Mom is tall and my Dad is of average height.
Teacher: I am still waiting for your answer.
Student $1$: Who? Me?
Teacher: Yes of course.
Student $1$: I think I inherited my temperament from my Dad.
Teacher: Bold. Reactive (not proactive). High activity level. Persistent.
Student $1$: You got it.
But, you do know environmental factors contribute as well.
Teacher: Yes I know.
Just like Intelligence, Temperament is both nature and nurture. However, it is more of nurture.
Student $1$: Now, back to you, Mr. C
What did you inherit from your parents?
Teacher: Oh come on.
Can't you see it?
Everyone is looking at me.
Student $1$: Meaning?
That I am a very handsome man.
Everyone starts smiling/laughing
It's good to laugh and be relaxed before we start learning some codes.
Student $1$: We are looking at you because you are the professor.
Teacher: And because I am very handsome.
Alright, B2B...
Everyone says: Back to Business
So as you can see (based on our discussion), one can inherit traits from the Dad, Mom, Mom and Dad, grandparents, or
even ancestral traits.
So far:
In your previous course: the Beginner's course; we discussed
(1.) Method/Function
In the previous modules for this course, we discussed:
(1.) A class
(2.) Constructor
(3.) Property
Say that we created a class: Class $A$ with some members: fields, properties, and methods
We want to create another class: Class $B$ and use the members from class $A$ and also use additional members
Keep in mind that class members includes fields, properties, and methods.
Rather than create Class $B$ and define all those members from Class $A$, we can create Class $B$ as a child of
Class $A$ so that it inherits the class members from Class $A$ and then create the addtional members for it.
We can also create Class $C$ to inherit some of the properties of Class $A$ and also some of the properties
of Class $B$
So, you can see it this way:
Class $A$ as the parent
Class $B$ as the child
Class $C$ as the grandchild
Remember one inherits the genes of grandparents and great grand parents and so on and so forth. The amount
depends on the percentage or fraction. (which you discuss in Genetics).
Welcome to Inheritance.
Inheritance is the ability of a class to inherit the members of
another class.
The class whose members are inherited from another class is known as the base class or
parent class or super class
The class that inherits the class members from another class is known as the derived class or
child class or extnded class or sub class.
So, this is seen as:
Base class and Derived class OR
Base class and Extended class OR
Parent class and Child class OR
Super class and Sub class (Compare to Superset and Subset in Algebra)
(Please get used to these words because we shall be using them interchangeably.)
The main purpose of inheritance is to reuse, extend, and modify the class members of a parent class by
the child class.
It allows one to define a child class that reuses (inherits), extends, or modifies/overrides the behavior of a parent class.
When a class is derived from a base class, the derived class implicitly gains all the members of the base
class, besides its constructors and finalizers.
The derived class reuses the code in the base class without having to reimplement it.
You can add more members in the derived class.
The derived class extends the functionality of the base class.
The ancestors of a derived class are the superclasses from which the subclass is derived.
(1.) The inheritance of a base class from a derived class is achieved using the colon symbol.
The syntax is:
(1.)
Textbook Questions
(4.) Question $6$ on Page $508$
(5.) Question $8$ on Page $508$
(1.)
Textbook Questions
(4.) Question $10$ on Page $509$
(5.) Question $2$ on Page $562$
(6.) Question $6$ on Page $564$
(7.) Question $8$ on Page $565$
(8.) Question $10$ on Page $565$
(9.) Question $13$ on Page $566$
Students will:
(1.) Textbook Chapter
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type to be given later or type the topic in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(5.) Type to be given later or type the topic in the search bar and view the results.
Each question in this tab is to be done by only one student.
You do not need to respond to the initial post of another student.
(1.)
Students will:
(1.) Textbook Chapter
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type to be given later or type the topic in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(5.) Type to be given later or type the topic in the search bar and view the results.
Each question in this tab is to be done by only one student.
You do not need to respond to the initial post of another student.
(1.)
Students will:
(1.) Textbook Chapter
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type to be given later or type the topic in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(5.) Type to be given later or type the topic in the search bar and view the results.
Each question in this tab is to be done by only one student.
You do not need to respond to the initial post of another student.
(1.)
Students will:
(1.) Textbook Chapter
Videos:
Please click the RESOURCES tab of this website
Click the LinkedIn Learning (Kent State University) link
Follow the directions to access the website.
(4.) Type to be given later or type the topic in the search bar and view the results.
Videos and Textbooks:
Please click the RESOURCES tab of this website
Click the Safari Books Online link
Follow the directions to access the website.
(5.) Type to be given later or type the topic in the search bar and view the results.
Each question in this tab is to be done by only one student.
You do not need to respond to the initial post of another student.
(1.)
There are two options for your Final Exam.
Please choose only one option.
This exam is designed to assess your understanding of the Java language.
You have reviewed several topics and several concepts in each topic for eight modules.
Pick at least $1$ concept in at least $1$ topic in each of the $8$ modules.
That gives at least $8$ concepts in $8$ different topics in $8$ modules.
Find two more concepts in any topic in any module.
That gives $10$ concepts.
For each concept:
(1.) Write at least three sentences about that concept.
(2.) Develop a program about that concept.
In other words, write at least one code example about the concept.
Run the code.
Display the output.
Submit clear screenshots of your program (code and output)
Deliverables:
(1.) $10$ concepts in $10$ different topics for $8$ modules
Please write the: Module number, the Topic, and the Concept
(2.) Three sentences for each concept.
(3.) Code for each concept.
(4.) Output for each concept.
Please submit all these information as a zip file in the Final Exam folder of the Blackboard course.
This exam is designed to assess your understanding of the Java language.
Please review all the questions and answers of the
Advanced Placement (AP) Computer Science Exams
Student: Mr. C, you are giving us a final exam with the answers?
How nice of you?
Teacher: Yes of course, I am nice. 😊
But, please read on.
First-come, first-served basis
A particular question may NOT be done by more than one student.
In other words, no two or more students are permitted to do the same question.
Please:
(1.) Pick any five questions from any of the years.
(2.) Go to the Final Exam Questions forum of the Blackboard course.
(3.) Write the year and the question numbers in that forum only if it has not been written by any other student.
In other words, you need to review any year and questions posted by your colleagues and make sure that you do not attempt
the same question.
For each question:
(4.) Write it or take clear screenshots.
(5.) Develop the Java program for the solution.
The answers are already provided for you.
However, please write detailed comments in your program that explains the solution.
(6.) Run the program.
Submit clear screenshots of the code and results.
(7.) Submit clear screenshots of the: numbered questions, the Java program (including comments) of the solutions,
and the results of the five questions in the Final Exam folder of the Blackboard course.
(8.) Make your work easy for me to grade.
In other words, write detailed clear specific explanations.
Do not give me any avenue to deduct points.
For example:
First Task: Notify your colleagues of the questions you intend to do.
In the Final Exam Questions forum of the Blackboard course: you may write:
Hey guys, I am doing $2006$ Question ($2$.), $2010$ Question ($3$.), ... etc.
Second Task: Do the questions.
(1.) $2006$ Question (2.)
Write the question or take screenshots of the question.
Develop the Java program. Write detailed comments.
Run the program.
Submit clear screenshots of the code and results.
(2.) $2010$ Question (3.)
Write the question or take screenshots of the question.
Develop the Java program. Write detailed comments.
Run the program.
Submit clear screenshots of the code and results.
Third Task: Submit all deliverables.
Submit clear screenshots of the: numbered questions, the Java program (including comments) of the solutions,
and the results of the five questions in the Final Exam folder of the Blackboard course.
Should you have any questions, please let me know.
Thank you.
You are not allowed to do any of the questions in these Samples.
Please find your own set of questions.
(1.) Option $2$: Sample 1
There are two options for your Final Project.
Please choose only one option.
Desktop Applications and/or Console Applications are required.
It is important you communicate with me for approval prior to doing this project.
The final project is designed to assess problem-solving skills using the knowledge you have acquired in the
course.
In that regard, solving at least a real-world problem using the knowledge gained in the course is expected.
(1.) Think about any of these companies: our Institution: Kent State University; your local campus; your work place; public and
private schools (excluding home schools); organizations, firms, and businesses
(excluding controversial firms and the like).
Any company you choose should have a verifiable website.
The direct link of the company's website is required.
(2.) Identify a problem on the website that you want to solve.
The problem must be solved by programming using the knowledge acquired from any of the course
topics/concepts/description/learning objectives.
Think about your Midterm Project. You solved a problem: calculating bills, federal taxes, etc.
(3.) Develop the computer program to solve the problem.
Test the program to ensure that it works.
Write detailed comments as applicable.
(4.) Prepare a Documentation Manual/Reflection for the project.
Please cite your sources accordingly.
What is the company?
What is their website?
What problem did you identify?
Did you solve the entire problem or part of the problem?
What course topics/concepts/description/learning objectives did you apply in solving the problem?
How did you solve the problem?
Did you encounter any issues while trying to solve the problem?
Are there any limitations to the project?
Are there any recommendations to the company?
Deliverables:
(1.) Program (all files)
(2.) Clear screenshots of your program (code and output)
(3.) Project Reflection/Documentation Manual
Please submit all these information as a zip file in the Final Project folder of the Blackboard course.
The final project is designed to assess your understanding and analysis of data using the knowledge you have
acquired in the course.
Please:
(1.) Visit my website on: Descriptive Statistics
(2.) Review the information for a good understanding of Descriptive Statistics.
It is highly likely that you have a prior knowledge of this topic. Is that right?
(3.) Click the Project link.
(4.) Review the Project Examples. Ensure you follow all the instructions and directions.
(5.) Complete the Final Project for your course.
(6.) Ask questions. I can advise.
(7.) Upload your draft project (clear screenshots of all your Math work and the .exe file)
in the Midterm Project Drafts forum of the course on Blackboard.
I shall review and provide feedback.
You may also submit your draft to me via email. I shall review and provide feedback.
(8.) Upload your actual completed entire project (clear screenshots of all your Math work
and the project with all the files) in the Midterm Project course area of the course.
Please submit all these information as a zip file in the Final Project folder of the Blackboard course.
NOTE: Any actual project submitted to me via email will not be graded.
Dear Students,
Greetings to you.
As you evaluate me and my teaching style on the Blackboard course, I ask that you consider these questions
in addition to the survey questions.
Thank you for giving me the opportunity to teach the course.
It was nice working with you.
I wish you the best in your academic profession.
Thank you!
Samuel Dominic Chukwuemeka (SamDom For Peace)
B.Eng., A.A.T, M.Ed., M.S
Working together for success
Grading Method: Grading Method
Classroom/Learning Environment: Blackboard course management system.
Course Assessments: Discussion Board (DB) assignments, Midterm Project, Final Project and the Final Exam
Direct forms of communication: live office hours/tutoring sessions, emails, comments to your DB posts and responses and
phone calls.
Indirect forms of communication: course announcements, websites (notes, videos, etc).
Course Contents
Please review the Course Description and Student Learning Outcomes
It is the first link in your course.
Those are the basic topics that KSU require that I teach.
(1.) Did I cover those topics?
(2.) Did I cover other necessary topics that is relevant for you to succeed in your profession?
(3.) Did the assessments demonstrate the application of the topics?
(4.) Did the assessments demonstrate the application of the topics required for your profession?
(5.) Did the contents and assessments demonstrate important skills such as critical thinking, use of technology,
creativity, and organization among others?
Teaching and Learning
(6.) Did you acquire any knowledge from me?
(7.) Did you acquire sufficient knowledge, or more than sufficient knowledge from me?
(8.) Did you acquire any knowledge from any of your colleagues because of how the course was set up?
(9.) Did you acquire sufficient knowledge, or more than sufficient knowledge from any of your colleagues because of
how the course was set up?
(10.) Did I provide effective feedback for any of your assessments?
(11.) Did you acquire any knowledge based on that feedback?
(12.) Did the feedback help you improve in any way?
(13.) Did you have enough support to ensure the successful completion of the course?
Were your questions answered?
Did you have enough resources/learning aids?
(14.) Did I provide a safe and conducive environment for learning?
(15.) Was the Grading Method fair?
Pacing Guide
(16.) Were you given enough time to learn the contents?
(17.) Were you given enough time to complete the assessments?
Professionalism
(18.) In all our communication (both direct and indirect), did I act professionally?
(19.) In all our communication (both direct and indirect), did I use a respectful tone?
(20.) What do you like or dislike about our communication?
Personality
(21.) Based on your experience with me (taking the course with me and communicating with me among others), how
would you describe my person?
Do I give a lot of work?
Do I give a lot of explanations?
Do I have a lot of expectations for my students?
Do I really want you to learn?
Do I really want you to succeed?
Do I ask a lot of questions?
Do I answer questions with questions sometimes?
In those times, please note that it is a teaching technique.
It is never meant to disrespect you. I do not disrespect my students. I respect them.
It is a technique to guide you to review directions/concepts, and explain what you do not understand.
Would you take another course with me? Why or why not?
Did your views/perception about me affect you in completing this course successfully or unsuccessfully?
Need a programmer for personal/professional/commercial projects?
Look no further. Any of my available students (not just the ones listed here) can help.
Just head on to the Division of Student Affairs, Kent State University
or contact me here or via my school email address.
These are nice projects (Console Applications and Desktop Applications) done by my students.
Some of them are Midterm Projects while some are Final Projects.
Because of FERPA (Federal Educational Rights and Privacy Act) laws, only the first names of my students are
written.
NOTE: Java must be installed on your computer for these applications to run.
To run the Console applications, please review the screenshots.
To run the Desktop applications, please double-click the application.
Console Applications
Directions to Run:
Desktop Applications
Desktop Applications
Java Tutorials by Oracle (Free)
Java Tutorial: W3schools.com (Free)
Java Documentation: Oracle (Free)
AP Computer Science Java Quick Reference
Java SE Developer Community
American Standard
Code for Information Exchange (ASCII) Characters
Sorting
Techniques and Algorithms
LinkedIn Learning (Kent State University)
Safari Books Online
For Kent State University students, Select your Institution > Choose “Not Listed?
Click here.”
Enter your Kent State University email address and click Let’s Go
Tutorials, Exercises, and Solutions from W3Resource (Free)
Java Programming Exercises and Solutions from W3Resource (Free)
SoloLearn (Free)
Java for Programmers: Udacity (Free)
Java Notes for Professionals: Stack Overflow Documentation (Free)
Wikibooks: Java
Programming (Free)
Stack Overflow: Question and Answer Forum
for Computer Science
Lynda.com from LinkedIn Learning (Start for Free. Then, not free)
Codecademy (Start for Free. Then, not
free)
Chukwuemeka, S.D (2016, April 30). Samuel Chukwuemeka Tutorials - Math, Science, and
Technology.
Retrieved from https://www.samuelchukwuemeka.com
Farrell, J. (2019). Java Programming. Cengage Learning.
Java Documentation. (n.d.). Oracle Help Center. https://docs.oracle.com/en/java/
Java Notes for Professionals Book. (n.d.). Books.Goalkicker.Com. Retrieved June 30, 2020, from
https://books.goalkicker.com/JavaBook/
AP Computer Science A Past Exam Questions. (2019, May 4). AP Central. https://apcentral.collegeboard.org/courses/ap-computer-science-a/exam/past-exam-questions