PRG/421 Java Programming II  
PRG/421    PRG421 JAVA Programming II

Or you may purchase UOP Tutorials by the Week below...   

PRG/421 ANALYZE
PRG/421 CODING
PRG/421  LT SET UP AN FAQ
    PRG/421 Java Programming II

PRG/421 WEEK 1

All Week 1 Tutorials listed below are included in purchase!! A+ Work!

 

Learning Team: Set Up an FAQ
Instructions:
Each week during this course, you will be working with your teammates to create a Java™ FAQ, or frequently asked questions, list with answers. The audience for your Java™ FAQ will be other Java students.
FAQs are extremely common in business and technology today. They answer important questions in an informal, quick answer format for a variety of audiences, from customers to partners to internal stakeholders.
Each week, your team will be assigned Java™-related questions to research and answer in FAQ format. Members of your group will research the answers to each week's questions and edit each other's work, so that at the end of the course your team's FAQs are all
answered clearly, economically, and accurately, with no misspellings or punctuation errors.
For this week's Learning Team assignment, review the example FAQ, "Frequently Asked OWL Questions (FAQs)," and notice the following formatting guidelines, all of which are designed to make reading an FAQ easy for online readers:

  • Title appears at top of the FAQ, followed by contributors and "last edited" date
  • Questions appear bolded and two font sizes larger than answers
  • A double space appears between each question and answer
  • Answers appear beneath corresponding questions
  • Both questions and answers are short, direct, and clear. The text is not meant to impress with fancy words or to be exhaustive; rather, it is written the way one professional might advise a colleague, using second person ("you") and providing clear, specific definitions, advice, and links to extended definitions or examples where appropriate.

Complete this Learning Team assignment by doing the following as a
team:

  • Decide which of your team's members will be responsible for submitting the team's Collaborative FAQ document each week.
  • Create a Microsoft® Word document with the title "Java Frequently Asked Questions (FAQ)."
  • Each group member should add his or her name to a contributor list beneath the FAQ title.

The team member responsible for submitting the team's work will submit the formatted FAQ document, which will only contain the title and contributor names at this time, to the Assignment Files tab.

 

 

Individual: Week One Analyze Assignment
Includes Instructor Feedback
The purpose of creating an abstract class is to model an abstract situation.
Example:
You work for a company that has different types of customers: domestic, international, business partners, individuals, and so on. It well may be useful for you to "abstract out" all the information that is common to all of your customers, such as name, customer number,
order history, etc., but also keep track of the information that is specific to different classes of customer. For example, you may want to keep track of additional information for international customers so that you can handle exchange rates and customs-related activities, or you may want to keep track of additional tax-, company-, and department-related information for business customers.
Modeling all these customers as one abstract class ("Customer") from which many specialized customer classes derive or inherit ("InternationalCustomer," "BusinessCustomer," etc.) will allow you to define all of that information your customers have in common and put it in the "Customer" class, and when you derive your specialized
customer classes from the abstract Customer class you will be able to reuse all of those abstract data/methods.This approach reduces the coding you have to do which, in turn, reduces the probability of errors you will make. It also allows you, as a programmer, to reduce the cost of producing and maintaining the program.
In this assignment, you will analyze Java™ code that declares one abstract class and derives three concrete classes from that one abstract class. You will read through the code and predict the output of the program.
Read through the linked Java™ code carefully.
Predict the result of running the Java™ code.

Write your prediction into a Microsoft® Word document, focusing specifically on what text you think will appear on the console after running the Java™ code.

In the same Word document, answer the following question:

  • Why would a programmer choose to define a method in an abstract class, such as the Animal constructor method or the getName() method in the linked code example, as opposed to defining a method as abstract, such as the makeSound() method in the linked example?

Submit your Word document to the Assignment Files tab.

 

Individual: Week One Coding Assignment
Includes Instructor Feedback
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following:

  • An abstract Bicycle class that contains private data relevant to all types of bicycles (cadence, speed, and gear) in addition to one new static variable: bicycleCount. The private data must be made visible via public getter and setter methods; the static variable must be set/manipulated in the Bicycle constructor and made visible via a public getter method.
  • Two concrete classes named MountainBike and RoadBike, both of which derive from the abstract Bicycle class and both of which add their own class-specific data and getter/setter methods.

Read through the "Lesson: Object-Oriented Programming Concepts" on The Java™ Tutorials website.
Download the linked Bicycle class, or cut-and-paste it at the top of a new Java™ project named BicycleDemo.
Download the linked BicycleDemo class, or cut-and-paste it beneath the Bicycle class in the BicycleDemo.java file.
Optionally, review this week's Individual "Week One Analyze Assignment," to refresh your understanding of how to code derived classes.
Adapt the Bicycle class by cutting and pasting the class into the NetBeans editor and completing the following:

  • Change the Bicycle class to be an abstract class.
  • Add a private variable of type integer named bicycleCount, and
    initialize this variable to 0.
  • Change the Bicycle constructor to add 1 to the bicycleCount each
    time a new object of type Bicycle is created.
  • Add a public getter method to return the current value of
    bicycleCount.
  • Derive two classes from Bicycle: MountainBike and RoadBike. To
    the MountainBike class, add the private variables tireTread (String) and
    mountainRating (int). To the RoadBike class, add the private variable
    maximumMPH (int).

Using the NetBeans editor, adapt the BicycleDemo class as follows:


Create two instances each of MountainBike and RoadBike.
Display the value of bicycleCount on the console.

 

Comment each line of code you add to explain what you added and why. Be sure to include a header comment that includes the name of the program, your name, PRG/421, and the date.
Rename your JAVA file to have a .txt file extension.
Submit your TXT file to the Assignment Files tab.

 

Discussion Question: Data Hiding
Data hiding is the way in which programmers implement encapsulation. Java™ programmers use the keywords private and protected to control what data is visible outside of a class; in other words, to control what code can access and manipulate class data.
Read Table 1-2, "Determining Access to Class Members," in "Java - Protected Members Accessed in Derived Class
Using Base Class Instance" on the Stack Overflow website.
Note: This table is similar, though not identical, to Table 1-1, "Access Modifiers," in Ch. 1, "Advanced Class Design," of OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide.
Discuss the following by posting to the discussion area:

  • If Class A contains private data and Class B inherits from Class A, is it possible to make Class A's private data visible to Class B? If so, how? Be sure to provide reasons for your answer based on this week's textbook readings or this week's assignment code.

 

Supporting Activity: Static Variables and Methods
For this assignment, you will predict the output of Java™ code that includes a static (class) variable accessed by a static method. Completing this assignment will help you understand the utility of using static variables and methods, as well as recognize the syntax required to create static variables and methods.
Read through the linked Java™ code carefully.
Predict the result of running the Java™ code; specifically, what text you think will appear on the console after running the Java™ code. Can you think of other uses for static variables and methods? In other words, can you think of other situations in which you might want all instances of a class to be able to access a single class variable?

 

PRG421 Analyze Week 2
PRG421 Coding Assignment Week 2
PRG/421 LT FAQs
    PRG/421 Java Programming II

PRG/421 Week 2

All Week 2 Tutorials listed below are included in purchase!!

 

Learning Team: Java I/O FAQ
Instructions:
The purpose of this activity is to define and explain the syntax required for data output.
Continue working as a team on your FAQ document by answering the following questions and adding them to the Microsoft® Word document you started in your Week One Learning Team assignment, "Set Up a FAQ":
      • What is the syntax for writing data to a file?
      • What is the syntax forwrapping file output in an exception handler?

Note: You may want to review Ch. 8, "IO," in OCP: Oracle® Certified Professional Java SE 8 Programmer II Study Guide: Exam 1Z0-809 for help answering these questions.
The team member responsible for submitting the team's work will submit the formatted FAQ document containing this week's questions and answers to the Assignment Files tab.

 

Individual: Week Two Analyze Assignment
Instructions:
For this assignment, you will analyze Java™ that presents instructional text on the console, accepts user input, and then create a file based on that user input.
Read the linked Java™ code carefully.
Then, answer the following questions in a Microsoft® Word file:

  • As you run the program in NetBeans the first time, at the prompt (the program will pause for input) type abc Return def Return ghi Ctrl+Shift+Del. What is the result?
  • As you run the program in NetBeans the second time, at the prompt (the program will pause for input) type 123 Ctrl+Shift +Del. What is the result?
  • What happens if the file Data.txt already exists when you run the program?
  • What happens if the file Data.txt does not already exist when you run the program?

Submit your Word file to the Assignment Files tab.

 

 

Individual: Week Two Coding Assignment
Instructions:
For this assignment, you will build on "starter" code to create a Java™ program that prompts the user for input, accepts user input, and produces both console and file output.
Copy the linked code to a JAVA file.
Add Java® code based on the comments inside the code.
Note: Refer to this week's Individual "Week Two Analyze Assignment" for model code you can adapt to meet this assignment's requirements.
Test, debug, and run your code using the NetBeans editor to make sure it meets the program requirements.
Save your JAVA file with a .txt extension.
Submit your TXT file to the Assignment Files tab.

 

Discussion Question: Data Conversion

(3 Answers Included)

Accepting input and producing output virtually always requires data conversion. Because Java™ students new to I/O are often surprised at the steps necessary to read data and then put it in a form that can actually be used, the purpose of this discussion is to experiment with data conversion techniques and share the issues that arise to arrive at a better understanding of the critical role data conversion plays in Java I/O.
Copy and paste the linked code into a Java™ program (or rename the file using a .java extension) and run it in NetBeans. The purpose of the program is to calculate a salesperson's total annual compensation. The program asks the user for the total amount dollar amount of sales for a year, and then uses that input to make calculations.
Post your results after running the program to the discussion area.
Discuss with your classmates what errors were produced, what could have caused the errors, and how this code can be fixed. Is there an approach you learned from this code that you can apply to all those situations in which you need to read data and convert it to a usable form?
Note: To interpret your results, you may want to refer to Ch. 5, "Dates, Strings, and Localization," of OCP: Oracle® Certified Professional Java® SE8, Programmer II Study Guide.


Discussion Question: Choosing a Data Output Option

(2 Answers Included)

Before you can perform data output, you must first decide the form in which you want the output data to appear. Onscreen and flat-file output are sometimes appropriate in a small system, such as a modest inventory application in which updated results display on a screen to be analyzed by a user, and in which output is designed for little more
than backup on a local, secure machine. Displaying information onscreen can be a benefit, since the user does not have to produce and review a program-generated report, while saving small amounts of data to an easily-read file with no requirement to manage a database can be the best approach if program requirements do not dictate otherwise.
However, in high-volume scenarios where one program "feeds" large amounts of data to another program, console output and flat-file data storage may not make practical sense.
Post to the discussion area descriptions of at least two scenarios for which console or flat file output would not be appropriate. For each scenario, describe why console/flat file output would not be appropriate, and identify an alternative approach that might make more sense.
Review your classmates' posts, then explain what characteristics the scenarios of your classmates and you described share. In general, for what types of programming scenarios are flat file/console output inappropriate?

 

 

 

PRG/421 Week 3 Analyze
PRG421 Week 4 Coding Assignment
PRG/421 Learning Team FAQ
    PRG/421 Java Programming II

PRG/421 Week 3

All Week 3 Tutorials listed below are included in purchase!!

 

Learning Team: Stream Manipulation and Generics FAQ
Instructions:
The purpose of this assignment is to identify the syntax for a common data conversion or manipulation method and differentiate the syntax and intent of implementing a generic class versus an abstract class.
Continue working as a team on your FAQ document by answering the following questions and adding them to the Microsoft® Word document you started in Week One and continued in your Week Two Learning Team assignment, "Java I/O FAQ":

  • The peek() method retrieves, but does not remove, the first element
    of a list. What is the syntax for peek()?
  • What is the difference between a generic class and an abstract class?

The team member responsible for submitting the team's work will submit the formatted FAQ document containing this week's questions and answers to the Assignment Files tab.

 

Individual: Week Three Analyze Assignment
Instructions:
For this assignment, you will analyze code that uses a file input stream and a file output stream.
Read through the linked Java™ code.
In a Microsoft® Word document, answer the following questions:

  • Could this program be run as is? If not, what is it lacking?
  • Does this program modify the contents of an input stream? In what
    way?
  • What are the results of running this code?

Submit your completed Word document to the Assignment Files tab.

 

Individual: Week Three Coding Assignment
Instructions:
For this assignment, you will develop "starter" code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text flie, sort and store the contents of the text file into an ArrayList, then write the sorted contents via an ouput stream to a separate output text file.
Copy and paste the following Java™ code into a JAVA source file in NetBeans:
import java.io.BufferedReader;
import java.io.BufferedWriter;
public class Datasort {
public static void main (String [] args) {
File fin = // input file
File fout = // create an out file
// Java FileInputStream class obtains input bytes from a file
FileInputStream fis = new FileInputStream(fin);
// buffering characters so as to provide for the efficient reading of characters, arrays, and lines
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
// declare an array in-line, ready for the sort String aLine;
ArrayList<String> al = new ArrayList<String> (); int i = 0;
while ((aLine = in.readLine()) != null) {
// set the sort for values is greater than 0
Collections.sort(al); // sorted content to the output file
{
System.out.println(s);
}
// close the 2 files
}}

Add code as indicated in the comments.
Note: Refer to this week's Individual assignment, "Week Three Analyze Assignment," and to Ch. 8, "IO," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide.
Run and debug your modified program in NetBeans until it satisfies the requirements described above.
Save your finalized JAVA file with a .txt extension.
Submit your TXT file to the Assignment Files tab.


Discussion Question: Benefits of Generics

(5 Answers Included)

The purpose of this discussion is to describe the difference between implementing a class as an abstract class (i.e., a
class from which concrete classes can be derived) and a generic class (i.e., a class from which different types of
classes can be derived).
Discuss the benefits of using a generic class.
Share an example of a real-life situation that would benefit from being modeled as a generic class.
Instructions

 

Supporting Activity: Abstract Methods and Classes

(2 Answers Included)

The purpose of this activity is to understand the syntax necessary to declare and implement abstract methods and classes.
A method declared without any body within an abstract class is called an abstract method. The body of an abstract method must be defined by its subclass. Abstract methods can never be declared final or static, and any class that extends an abstract class must implement all the abstract methods declared by the super class. Abstract methods are useful in situations when two or more subclasses are expected to do a similar thing in different ways, extending the same abstract class by providing different implementations of the same abstract methods.
For this activity, you will practice defining an abstract method in one class (class A) and implementing that method in a derived class (class B).
Copy and paste the following code into a JAVA source file in NetBeans; note the abstract and extends keywords in the source:
abstract class A {
abstract void demoabst();

}
class B extends A { // subclass B derives from A
void demoabst () {
System.out.println("This is a code demo.");
}
public static void main(String[] args) {
B b = new B(); // class B reference and object
b. demoabst (); // reference demoabst object
}}
Run and debug the JAVA file in NetBeans

 

 

PRG421 Week 4 Analyze
PRG421 Week 4 Coding
PRG/421 Week 4 LT FAQ's
    PRG/421 LT FAQ

PRG/421 Week 4

All Week 4 Tutorials listed below are included in purchase!!

 

Learning Team: Concurrency and Localization FAQ
Instructions:
The purpose of this assignment is to define key components of concurrency and to identify the purpose and benefit of localization, which is implemented (in part) using the Locale object.
Continue working as a team on your FAQ document by answering the following questions and adding them to the Microsoft® Word document you started in Week One and continued in your Week Three Learning Team assignment, "Stream Manipulation and Generics FAQ":
• What is a thread?
• What is a process?
• What is deadlock?
• What is the purpose and benefit of localization?
The team member responsible for submitting the team's work will submit the formatted FAQ document containing this week's questions and answers to the Assignment Files tab.

 

Individual: Week Four Analyze Assignment
Instructions:
Deadlock occurs when no processing can occur because two processes that are waiting for each other to finish. For example, imagine that two processes need access to a file or database table row in order to complete, but both processes are attempting to access that resource at the same time. Neither process can complete without the other releasing access to the required resource, so the result is deadlock.
Read and analyze code in the linked document that spawns two different threads at the same time.
In a Microsoft® Word file, predict the results of executing the program, and identify whether a deadlock or starvation event will occur and, if so, at what point in the code.
Submit your Word file to the Assignment Files tab.

 

Individual: Week Four Coding Assignment
Instructions:
For this assignment, you will develop Java™ code that relies on localization to format currencies and dates.
In NetBeans, copy the linked code to a file named "Startercode.java".
Read through the code carefully and replace all occurrences of "___?___" with Java™ code.
Note: Refer to "Working with Dates and Times" in Ch. 5, "Dates, Strings, and Localization," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide for help.
Run and debug your JAVA file to ensure that your solution works.
Save your JAVA file with a .txt extension.
Submit your TXT file to the Assignment Files tab.

 

Discussion Question: Benefits and Drawbacks of Concurrency

(4 Answers Included)

The purpose of this discussion is to explore concurrency, which refers to threads that run alongside each other during program execution, as opposed to running serially, or one after the other, and to discuss potential drawbacks and problems associated with concurrency.
Java™ provides built-in support for concurrent programming by allowing the running of multiple threads concurrently within a single program. A thread, also called a lightweight process, is a single sequential flow of programming operations with a definite beginning and end. During the lifetime of a thread, there is only a single point of execution. A thread by itself is not a program, because it cannot run on its own, instead all threads must run within a program.
Research and discuss with your classmates the benefits of concurrency in Java™. What are the potential drawbacks?

 

Supporting Activity: Localization

(3 Answers Included)

The purpose of this activity is to provide you with an explanation for, and some experimentation with, the concept of localization via the Locale object.
Localization is the process of adapting a program so that it displays information in the way local users need to see it, and is important for any program running on the web where users from virtually any country in the world can access it.
A program that has been effectively localized displays currency in pounds and dates in day/month/year format to United Kingdom audiences, currency in dollars and dates in month/day/year format to United States audiences, etc.
Localization is particularly significant in that it allows for organizing all user-facing text so that it display text in different languages, as necessary.
Note: This course does not address localization in detail, however it does introduce the topic and demonstrate how setting a Locale object allows Java™ programmers to take advantage of pre-built formatting.
For this supporting activity, you will run an existing Java™ program to see how changing the Locale object automatically changes date formats.
Download the linked Java™ file, or cut-and-paste it into a new Java™ project in NetBeans using a name of your choosing.
Examine the Java™ code, paying special attention to the main() method, in which three Locale objects are created: one for France, one for Germany, and one for the United States. Notice that passing different Locale objects to the same methods (e.g., showDateStyles(), showTimeStyles(), and showBothStyles()) results in a customized display.
Note: Refer to the linked list of standardized codes to see which codes represent which countries.
Insert the following code at the beginning of the main() method, just after the opening curly brace:
Date now = new Date();
System.out.println("Here is default date format: " +
DateFormat.getInstance().format(now));
Save the program, and run it in NetBeans again. What locale does the Java™ runtime environment assume by default: U.S. or European? (Hint: Typically, the Java™ runtime environment sets the default locale on download/install based on your computer system.)

 

 

 

 

PRG/421 Analyze
PRG/421 Entire Class
PRG/421 Entire Class
    PRG/421 Java II

PRG/421 Week 5

All Week 5 Tutorials listed below are included in purchase!!

 

Learning Team: JDBC-Related FAQ
Instructions:
The purpose of this assignment is to identify the JDBC API syntax necessary for establishing a connection to a database, retrieving data from a database, processing the data, and presenting a subset of the data on the console. Familiarity with the syntax for all of these methods will be required in this week's Individual, "Week Five Coding
Assignment."
Continue working as a team on your FAQ document by answering the following questions and adding them to the Microsoft® Word document you started in Week One and continued in your Week Four Learning Team assignment, "Concurrency and Localization FAQ":

  • What is the JDBC API syntax required in order to accomplish the following:
  • Establish a connection to a database
    Create a statement (ty
    pically a query)
    Execute the query
    Process the query results
    Close the database connection

The team member responsible for submitting the team's work will submit the formatted FAQ document containing this week's questions and answers to the Assignment Files tab.

 

Individual: Week Five Analyze Assignment
Instructions:
For this assignment, you will analyze code that uses the JDBC API to access a database, retrieve data, and compose output based on that data. You will then comment the code to reflect the purpose and expected results of the code.
Download the linked TXT file, and read through the Java™ code carefully.
Add your name, instructor's name, and today's date to the header comment.
Replace the five comment placeholders with succinct comments that explain and predict the results of the Java™ statement(s) that directly follow the comment placeholders.

 

Individual: Week Five Coding Assignment
Instructions:

For this assignment, you will create Java™ code that accesses a relational database, requests data, and then analyzes and displays a portion of that data.

Imagine a MySQL relational database schema named COMPANY_DB containing two tables, employee_table and payroll_table, such that the records in each of the tables is as follows:

  • employee_table:

Emp id

FName  

LNname

Addr

City

State

Zip

100

Jack

Smith

123 North

Topeka

 KS

66603

101

Joe

Apple

4 Street

Denver

CO

80202

111

Nancy

Good

45 SW

Hartford

CT

06103

121

Tom

Whatever

89 NE

Dover

DE

19901

122

Jim

Thompson

789 W 95

Albany

NY

12207

123

Tommy

Boyson

154 Bolt

Boston

MA

02201

125

John

Jones

47 West

Lincoln

NE

68502

  • payroll_table:

Emp id

Paysch

401k

Spouse

100

BiWk

yes

yes

101

BiWk

yes

yes

111

Monthly

no

no

121

Wkly

pending

yes

122

Wkly

yes

no

123

Monthly

pending

no

125

Monthly

no

yes

 

The credentials you will need to access the database which holds both of the tables are as follows:

  • Host string = localhost:3306
  • Username = student
  • Password = prg421

Copy and paste the linked Java™ "starter" code into the NetBeans editor and save as a JAVA file.

Add Java™ statements to the file to accomplish the following:

  • Establish a connection to the database
  • Query the database, joining the two tables on the Emp_id field
  • Display your name and today's date on the console along with the following returned database results:
    • employee identification number
    • first and last name
    • state
    • payroll schedule
    • 401k plan
  • Close the database connection

Identify and correct any compile-time errors that exist in the starter code.

Note: Because you will not be connecting to an actual database, some compiler errors will remain.

After you finish, rename your JAVA file with a .txt extension using the following naming convention:

  • PRG421_Week5CodingAssignment_LastnameFirstname.txt.

Submit your TXT file to the Assignment Files tab.

 

Discussion Question: Databases Accessible via JDBC

(5 Answers Included)

The purpose of this discussion is to identify the purpose and utility of JDBC to Java™ programmers, including the data formats that JDBC allows Java™ programmers to interact with. Research and discuss the differences between a flat database and a relational database. Does JDBC provide a way for Java™ programmers to access flat databases, relational databases, or both? What specific relational databases can be accessed via JDBC?

 

Supporting Activity: Basic SQL Statements

(5 Answers Included)

The purpose of this activity is for you to familiarize yourself with the basics of SQL syntax, which is required for retrieving data from a database using JDBC. As a Java™ programmer, you do not have to be an expert at Structured Query Language (SQL), the language used to access and manipulate data stored in relational databases. However, to retrieve or update data in a relational database, you will need a passing familiarity with SQL statements, because you will need to pass these SQL statements as arguments to one or more JDBC API calls and should understand enough to see the issue if they do not work.
Familiarize yourself with basic SQL statements by taking the linked 25-question "W3Schools SQL Quiz." Use the answers to each quiz question to familiarize yourself with basic SQL query statements and keywords, such as SELECT and JOIN.