CMSC 335

Ebote24
  • 2 years ago
  • 60
files (10)

Homework44.pdf

1

Homework 4 1. (10 pts) For the following program, explain the interesting elements related to threads. Focus on explaining the output of the program.

1 public class TaskThreadDemo { 2 public static void main (String args []) { 3 String [] sa = {"a", "X", "+", "."}; 4 for (String s: sa) { 5 Runnable ps = new PrintChar (s, 200); 6 Thread ts = new Thread (ps, s); 7 ts.start (); 8 } // end for each character 9 } // end main 10 } // end class TaskThreadDemo 11 12 class PrintChar implements Runnable { 13 String ch; 14 int times; 15 16 public PrintChar (String c, int n) { 17 ch = c; 18 times = n; 19 } // end constructor 20 21 public void run () { 22 for (int i = 0; i < times; i++) { 23 System.out.print (ch); 24 } // end for loop 25 } // end method run 26 } // end class PrintChar

2. (10 pts) What is changed if the method called on line 7, start(), is replaced with run()? Explain (of course). Focus on explaining the output of the program.

3. (10 pts) What is changed if the method Thread.yield() is added between lines 23 and 24? Explain. Focus on explaining the output of the program.

4. (10 pts) Modify the above program so that the Thread.sleep method is called after each character has been printed causing it to sleep for 500 milliseconds. Describe how that modification has altered the output and explain why the change had the effect that you described.

5. (10 pts) Modify the above program so that the Thread.sleep method is called after each thread is created in the main method causing it to sleep for 500 milliseconds. Describe how that modification has altered the output and explain why the change had the effect that you described.

2

Grading Rubric:

Attribute Meets Does not meet Problem 1 10 points

Explains the interesting elements related to threads. Focuses on explaining the output of the program.

0 points Does not explain the interesting elements related to threads. Does not focus on explaining the output of the program.

Problem 2 10 points Explains what is changed if the method called on line 7, start(), is replaced with run().Focuses on explaining the output of the program.

0 points Does not explain what is changed if the method called on line 7, start(), is replaced with run(). Does not focus on explaining the output of the program.

Problem 3 10 points Explains what is changed if the method Thread.yield() is added between lines 23 and 24. Focuses on explaining the output of the program.

0 points Does not explain what is changed if the method Thread.yield() is added between lines 23 and 24. Does not focus on explaining the output of the program.

Problem 4 10 points Explains how the output is changed if the Thread.sleep method is called after each character has been printed.

0 points Does not explain how the output is changed if the Thread.sleep method is called after each character has been printed.

Problem 5 10 points Explains how the output is changed if the Thread.sleep method is called after each thread is created in the main method.

0 points Does not explain how the output is changed if the Thread.sleep method is called after each thread is created in the main method.

CMSC335Project22.pdf

CMSC 335 Project 2 Overview

In the project you will construct a Java GUI that uses event handlers and listeners while expanding on the project 1 Shape theme. Before completing this exercise, be sure to review and try the Java class and inheritance examples and materials found on the Java Tutorial:

https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

Please also review the tutorial on Java FX (newer package) or legacy Java Swing. Java FX:

• https://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm • https://docs.oracle.com/javafx/2/ui_controls/jfxpub-ui_controls.htm • https://docs.oracle.com/javase/8/javase-clienttechnologies.htm • https://docs.oracle.com/javafx/2/

Java Swing (Legacy): https://docs.oracle.com/javase/tutorial/uiswing/index.html

Assignment Details

Design, implement and test a set of Java classes that allows a user to select a shape from a list of available shape images, enter appropriate dimensional parameters (suggest a dropdown box of dimensional size choices) and then display that shape in a frame (either as an image or as a drawing).

Your list of shapes should be similar, if not identical to the ones used in project one:

• Circle • Square • Triangle • Rectangle • Sphere • Cube • Cone • Cylinder • Torus

Take your time on understanding how the graphical components and listeners work so you can easily display appropriate actions based on any event.

Submission Requirements:

1. Submit all of your Java source files (each class should be in a separate .java file). These files

should be zipped and submitted with the documentation. 2. UML class diagram showing the type of the class relationships. 3. Developer’s guide describing how to compile and execute the program. The guide should

include a comprehensive test plan that includes evidence of testing each component of the menu with screen captures and descriptions supporting each test. Documentation includes Lessons learned.

4. Test Plan in table format: #, Description, Screenshot, PASS/FAIL

Your compressed zip file should be submitted to the Project 2 folder as directed.

Grading Rubric: Attribute

Meets

Design 45 points Designs a Java class Inheritance hierarchy that would satisfy the following is- a and has-a relationships:

• Circle • Square • Triangle • Rectangle • Sphere • Cube • Cone • Cylinder • Torus

Functionality 85 points Contains no coding errors.

Contains no compile warnings.

Constructs a Java Swing GUI that uses event handlers and listeners while expanding on the project 1 Shape theme.

Displays shapes in a frame of your FX or Swing -based GUI. For 3-D shapes consider loading an image from a file and displaying that as a representative.

Test Data and Test Plan

45 points Tests the application using multiple and varied test cases. Test plan in format described in requirements.

Documentation and submission

40 points Source code files include header comment block, including file name, date, author, purpose, appropriate comments within the code, appropriate variable and function names, correct indentation.

Submission includes Java source code files, Data files used to test your program, Configuration files used.

Documentation includes a UML class diagram showing the type of the class relationships.

Documentation includes a user's Guide describing of how to set up and run your application.

Documentation includes a test plan with sample input and expected results, test data and results and screen snapshots of some of your test cases.

Documentation includes Lessons learned.

Documentation is in an acceptable format. Document is well-organized. The font size should be 12 point.

The page margins should be one inch. The paragraphs should be double spaced. All figures, tables, equations, and references should be properly labeled and formatted using APA style.

The document should contain minimal spelling and grammatical errors.

Any submissions that do not represent work originating from the student will be submitted to the Dean’s office and evaluated for possible academic integrity violations and sanctions.

CMSC335Project21.pdf

CMSC 335 Project 2 Overview

In the project you will construct a Java GUI that uses event handlers and listeners while expanding on the project 1 Shape theme. Before completing this exercise, be sure to review and try the Java class and inheritance examples and materials found on the Java Tutorial:

https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

Please also review the tutorial on Java FX (newer package) or legacy Java Swing. Java FX:

• https://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm • https://docs.oracle.com/javafx/2/ui_controls/jfxpub-ui_controls.htm • https://docs.oracle.com/javase/8/javase-clienttechnologies.htm • https://docs.oracle.com/javafx/2/

Java Swing (Legacy): https://docs.oracle.com/javase/tutorial/uiswing/index.html

Assignment Details

Design, implement and test a set of Java classes that allows a user to select a shape from a list of available shape images, enter appropriate dimensional parameters (suggest a dropdown box of dimensional size choices) and then display that shape in a frame (either as an image or as a drawing).

Your list of shapes should be similar, if not identical to the ones used in project one:

• Circle • Square • Triangle • Rectangle • Sphere • Cube • Cone • Cylinder • Torus

Take your time on understanding how the graphical components and listeners work so you can easily display appropriate actions based on any event.

Submission Requirements:

1. Submit all of your Java source files (each class should be in a separate .java file). These files

should be zipped and submitted with the documentation. 2. UML class diagram showing the type of the class relationships. 3. Developer’s guide describing how to compile and execute the program. The guide should

include a comprehensive test plan that includes evidence of testing each component of the menu with screen captures and descriptions supporting each test. Documentation includes Lessons learned.

4. Test Plan in table format: #, Description, Screenshot, PASS/FAIL

Your compressed zip file should be submitted to the Project 2 folder as directed.

Grading Rubric: Attribute

Meets

Design 45 points Designs a Java class Inheritance hierarchy that would satisfy the following is- a and has-a relationships:

• Circle • Square • Triangle • Rectangle • Sphere • Cube • Cone • Cylinder • Torus

Functionality 85 points Contains no coding errors.

Contains no compile warnings.

Constructs a Java Swing GUI that uses event handlers and listeners while expanding on the project 1 Shape theme.

Displays shapes in a frame of your FX or Swing -based GUI. For 3-D shapes consider loading an image from a file and displaying that as a representative.

Test Data and Test Plan

45 points Tests the application using multiple and varied test cases. Test plan in format described in requirements.

Documentation and submission

40 points Source code files include header comment block, including file name, date, author, purpose, appropriate comments within the code, appropriate variable and function names, correct indentation.

Submission includes Java source code files, Data files used to test your program, Configuration files used.

Documentation includes a UML class diagram showing the type of the class relationships.

Documentation includes a user's Guide describing of how to set up and run your application.

Documentation includes a test plan with sample input and expected results, test data and results and screen snapshots of some of your test cases.

Documentation includes Lessons learned.

Documentation is in an acceptable format. Document is well-organized. The font size should be 12 point.

The page margins should be one inch. The paragraphs should be double spaced. All figures, tables, equations, and references should be properly labeled and formatted using APA style.

The document should contain minimal spelling and grammatical errors.

Any submissions that do not represent work originating from the student will be submitted to the Dean’s office and evaluated for possible academic integrity violations and sanctions.

Homework34.pdf

1

Homework 3

1. (5 pts) What events do the following components generate in either Swing or FX:

• JButton or Button • JTextField or TextField • JComboBox or ComboBox

2. (5 pts) What methods does JTable implement which are required by the interfaces implemented by the JTable class beyond those interfaces implemented by the various parent classes of JTable? 3. (5 pts) Address how the differences among these various layout managers, focusing on their behavior as their container is resized:

a. FlowPane in FX (or FlowLayout in Swing) b. GridPane in FX (or GridLayout in Swing) c. AncherPane d. TilePane e. Any other layout of your choice in FX or Swing.

4. (10 pts) (Ex 1.8.2) The dining philosophers problem was invented by E. W. Dijkstra, a concurrency pioneer, to clarify the notions of deadlock and starvation freedom. Imagine five philosophers who spend their lives just thinking and feasting. They sit around a circular table with five chairs. The table has a big plate of rice. However, there are only five chopsticks (in the original formulation forks) available, as shown in Fig. 1.5. Each philosopher thinks. When he gets hungry, he sits down and picks up the two chopsticks that are closest to him. If a philosopher can pick up both chopsticks, he can eat for a while. After a philosopher finishes eating, he puts down the chopsticks and again starts to think.

a. What is wrong with everybody doing the following - other than that the philosophers never get up from the table?

2

1. think for a while 2. get left chopstick 3. get right chopstick 4. eat for a while 5. return left chopstick 6. return right chopstick 7. return to 1

b. How can the above be fixed to avoid deadlocks?

c. Is your solution starvation free? Literally!

5. (10 pts) What methods must a class implementing the java.util.concurrent.locks.Lock interface implement? Describe some of the expected characteristics of each of the methods of this interface?

6. (5 pts) Explain what the JVM does when it encounters a synchronized directive. Hint: consider carefully what is synchronized.

7. (10 pts) What is the difference between Lock Interface and synchronized keyword?

Grading Rubric:

Attribute Meets Does not meet Problem 1 5 points

Lists the events associated with each provided component.

0 points Does not list the events associated with each provided component.

Problem 2 5 points Lists the methods JTable implements.

Lists the methods which are required by the interfaces implemented by the JTable class beyond those interfaces implemented by the various parent classes of JTable.

0 points Does not list the methods JTable implements.

Does not list the methods which are required by the interfaces implemented by the JTable class beyond those interfaces implemented by the various parent classes of JTable.

Problem 3 5 points Addresses the differences among the various layout managers.

Focuses on their behavior as their container is resized.

0 points Does not address the differences among the various layout managers.

Does not focus on their behavior as their container is resized.

Problem 4 10 points Explains what is wrong with

0 points Does not explain what is wrong with everybody doing the actions provided.

3

everybody doing the actions provided.

Explains how the actions be fixed to avoid deadlocks.

Explains if the solution provided is starvation free.

Does not explain how the actions be fixed to avoid deadlocks.

Does not explain if the solution provided is starvation free.

Problem 5 10 points Explains what methods a class implementing the java.util.concurrent.locks.Lock interface must implement.

Describes some of the expected characteristics of each of the methods of this interface.

0 points Does not explain what methods a class implementing the java.util.concurrent.locks.Lock interface must implement.

Does not describe some of the expected characteristics of each of the methods of this interface.

Problem 6 5 points Explains what the JVM does when it encounters a synchronized directive.

0 points Does not explain what the JVM does when it encounters a synchronized directive.

Problem 7 10 points Explains difference between Lock interface and synchronized keyword.

0 points Does not explains difference between Lock interface and synchronized keyword.

CMSC335Final2.pdf

CMSC 335 Project 3

Overview In this project you will construct a Java GUI that uses event handlers, listeners and incorporates Java’s concurrency functionality and the use of threads. The following Oracle Tutorials may be useful to help you become comfortable with Thread processes.

• https://docs.oracle.com/javase/tutorial/essential/concurrency/

In addition, a zip file is included that includes several Oracle Java files that use different types of GUI components as well as threads. I recommend going through the reading above and GUI below and the examples to become familiar before attempting the final project.

Java FX: • https://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm • https://docs.oracle.com/javafx/2/ui_controls/jfxpub-ui_controls.htm • https://docs.oracle.com/javase/8/javase-clienttechnologies.htm • https://docs.oracle.com/javafx/2/

Java Swing (Legacy): • https://docs.oracle.com/javase/tutorial/uiswing/index.html

Assignment Details As a new engineer for a traffic congestion mitigation company, you have been tasked with developing a Java GUI that displays time, traffic signals and other information for traffic analysts. The final GUI design is up to you but should include viewing ports/panels to display the following components of the simulation:

1. Current time stamps in 1 second intervals 2. Real-time Traffic light display for three major intersections 3. X, Y positions and speed of up to 3 cars as they traverse each of the 3 intersections

Some of the details of the simulation are up to you but the following guidelines will set the guardrails:

1. The components listed above should run in separate threads. 2. Loop through the simulation with button(s) providing the ability to start, pause, stop and

continue the simulation.

3. You will need to use basic distance formulas such as distance = Speed * time. Be sure to be consistent and define your units of measure (e.g. mile/hour, versus km/hour)

4. Assume a straight distance between each traffic light of 1000 meters. 5. Since you are traveling a straight line, you can assume Y = 0 for your X,Y positions. 6. Provide the ability to add more cars and intersections to the simulation through the GUI. 7. Don’t worry about physics. Assume cars will stop on a dime for red lights, and continue through

yellow lights and green lights. 8. Document all assumptions and limitations of your simulation.

Submission Requirements:

1. Submit all of your Java source files (each class should be in a separate .java file). These files should be zipped and submitted with the documentation.

2. UML class diagram showing the type of the class relationships. 3. Developer’s guide describing how to compile and execute the program. The guide should

include a comprehensive test plan that includes evidence of testing each component of the menu with screen captures and descriptions supporting each test. Documentation includes Lessons learned.

4. Test Plan in table format: #, Description, Screenshot, PASS/FAIL

Your compressed zip file should be submitted to the Project 3 folder in LEO no later than the due date listed in the classroom calendar.

Grading Rubric:

Attribute Meets Design 50 points

Designs a Java Swing GUI that uses event handlers, listeners and incorporates Java’s concurrency functionality and the use of threads.

Functionality 100 points Contains no coding errors.

Contains no compile warnings.

Constructs a Java Swing GUI that uses event handlers, listeners and incorporates Java’s concurrency functionality and the use of threads Include viewing ports/panels to display the following components of the simulation:

1. Current time stamps in 1 second intervals 2. Real-time Traffic light display for three major intersections 3. X, Y positions and speed of up to 3 cars as they traverse each of the

3 intersections The components run in separate threads.

Loop through the simulation with button(s) providing the ability to start, pause, stop and continue the simulation.

Provides the ability to add more cars and intersections to the simulation through the GUI.

Test Data and Test Plan

50 points Tests the application using multiple and varied test cases. Test plan in format described in requirements.

Documentation and submission

50 points Source code files include header comment block, including file name, date, author, purpose, appropriate comments within the code, appropriate variable and function names, correct indentation.

Submission includes Java source code files, Data files used to test your program, Configuration files used.

Documentation includes a UML class diagram showing the type of the class relationships.

Documentation includes a user's Guide describing of how to set up and run your application.

Documentation includes a test plan with sample input and expected results, test data and results and screen snapshots of some of your test cases.

Documentation includes Lessons learned.

Documents all assumptions and limitations of your simulation.

Documentation is in an acceptable format.

Document is well-organized.

The font size should be 12 point.

The page margins should be one inch.

The paragraphs should be double spaced.

All figures, tables, equations, and references should be properly labeled and formatted using APA style.

The document should contain minimal spelling and grammatical errors.

Any submissions that do not represent work originating from the student will be submitted to the Dean’s office and evaluated for possible academic integrity violations and sanctions.

Homework25.pdf
This file is too large to display.View in new window
CMSC335Project14.pdf
This file is too large to display.View in new window
Homework16.pdf
This file is too large to display.View in new window
DBWEEK1-8.docx
This file is too large to display.View in new window
CodeZip1.zip
This file is too large to display.View in new window