Computer Science assignments
3 years ago
60
input.txt
CMSC335Final.pdf
CMSC335Project1.pdf
Homework14.pdf
- Project25.pdf
- Project2Skeleton.zip
- CodeZip.zip
input.txt
((a + 4) ~), a = 3; ((x * 2.6) + (y - 3)), x = 1.5, y = 6; (( 7 / z_1) + (z_1 ^ 2)), z_1 = 2; ((6 % b) < 5), b = 4; (c > d), c = 9, d = 7; (e & 8), e = 5; (f ? 1 2), f = 0; (g # 1 2 3), g = 2; (tt + ss), tt = 2; (aa + 1), aa = 1, aa = 2;
CMSC335Final.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.
CMSC335Project1.pdf
CMSC 335 Project 1 Overview In the project you will use Java Inheritance to create a series of related classes with a “Shape” theme. Before completing this exercise, be sure to review and try the Java class and inheritance examples and materials found on the Oracle Java Tutorials:
https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html Note: Be sure to review is-a and has-a class relationships prior to starting this exercise as well.
Assignment Details
Design, implement and test a Java class Inheritance hierarchy that would satisfy the following is-a and has-a relationships:
• A Shape is an object • A TwoDimensionalShape is a Shape • A ThreeDimensionalShape is a Shape • A Circle is a TwoDimensionalShape • A Square is a TwoDimensionalShape • A Triangle is a TwoDimensionalShape • A Rectangle is a TwoDimensionalShape • A Sphere is a ThreeDimensionalShape • A Cube is a ThreeDimensionalShape • A Cone is a ThreeDimensionalShape • A Cylinder is a ThreeDimensionalShape • A Torus is a ThreeDimensionalShape • A Shape has a NumberofDimensions • A TwoDimensionalShape has an area • A ThreeDimensionalShape has a volume
Note you should fill in additional methods and variables that make sense for each of the classes. Also some assumptions about shape types is appropriate and should be documented in the code and documents submitted. For example, type of triangle …
Create a command line driven menu that allows a user to construct each of the TwoDimensional and ThreeDimensional Shape subclasses. The menu should continue to loop prompting for a specific class and then prompt for appropriate input parameters. The values returned should be the volume or area as appropriate to the shape. Error checks should be in developed to make sure appropriate menu items and types of data were input and prompt the user to enter to correct data. An option to exit the program should be available as well that will provide an appropriate Thank you message along with the current date and time.
The following represents a possible menu session for a user: *********Welcome to the Java OO Shapes Program **********
Select from the menu below:
1. Construct a Circle 2. Construct a Rectangle 3. Construct a Square
4. Construct a Triangle 5. Construct a Sphere 6. Construct a Cube 7. Construct a Cone 8. Construct a Cylinder 9. Construct a Torus 10. Exit the program
2
You have selected a Rectangle
What is the length?
4
What is the Width?
9.5
The area of the Rectangle is 38.
Would you like to continue? (Y or N)
3
Sorry I do not understand. Enter Y or N Y
Select from the menu below:
1. Construct a Circle 2. Construct a Rectangle 3. Construct a Square 4. Construct a Triangle 5. Construct a Sphere 6. Construct a Cube 7. Construct a Cone 8. Construct a Cylinder 9. Construct a Torus 10. Exit the program
10
Thanks for using the program. Today is Nov 11 at 1:40 PM.
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 Test # Description Screenshot PASS/FAIL Flag 1.
Your compressed zip file should be submitted to the Project 1 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:
• A Shape is an object • A TwoDimensionalShape is a Shape • A ThreeDimensionalShape is a Shape • A Circle is a TwoDimensionalShape • A Square is a TwoDimensionalShape • A Triangle is a TwoDimensionalShape • A Rectangle is a TwoDimensionalShape • A Sphere is a ThreeDimensionalShape • A Cube is a ThreeDimensionalShape • A Cone is a ThreeDimensionalShape • A Cylinder is a ThreeDimensionalShape • A Torus is a ThreeDimensionalShape • A Shape has a NumberofDimensions • A TwoDimensionalShape has an area • A ThreeDimensionalShape has a volume
Functionality 85 points Contains no coding errors.
Contains no compile warnings. Creates a command line driven menu that allows a user to construct each of the TwoDimensional and ThreeDimensional Shape subclasses.
The menu should continue to loop prompting for a specific class and then prompt for appropriate input parameters. The values returned should be the volume or area as appropriate to the shape.
Error checks should be in developed to make sure appropriate menu items and types of data were input and prompt the user to enter to correct data.
An option to exit the program should be available as well that will provide an appropriate Thank you message along with the current date and time
Test Data and Test Plan
45 points Tests the application using multiple and varied test cases. Test Plan included following format 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.
Homework14.pdf
1
Homework 1
For problems 1 through 4, explain why the code as shown is almost certainly not what the programmer intended, and how it should be fixed to work the way the programmer probably had in mind.
1. (5 pts) What is wrong with the following program and how should it be fixed?
1 public class MyClassA { 2 int v = 12; 3 4 public MyClassA (int pV) { 5 v = pV; 6 } 7 8 public static void main (String args []) { 9 MyClassA m = new MyClassA (); 10 } // end main 11 } // end class MyClassA
2. (5 pts) What is wrong with the following program and how should it be fixed?
1 public class MyClassB { 2 int v = 12; 3 4 public void MyClassB (int pV) { 5 v = pV; 6 } 7 8 public static void main (String args []) { 9 MyClassB m = new MyClassB (23); 10 } // end main 11 } // end class MyClassB
3. (5 pts) What is wrong with the following program and how should it be fixed?
1 public class MyClassD { 2 public static void main (String args []) { 3 MyClassC m = new MyClassC (23); 4 } // end main 5 } // end class MyClassD 6 7 class MyClassC { 8 int v = 12; 9 10 public MyClassC (int pV) { 11 int v = pV; 12 }
2
13 14 } // end class MyClassC
4. (5 pts) What is wrong with the following program and how should it be fixed?
1 public class MyClassE { 2 public static void main (String args []) { 3 MyClassF m = new MyClassF (23); 4 } // end main 5 } // end class MyClassE 6 7 class MyClassF { 8 int v = 12; 9 10 private MyClassF (int pV) { 11 v = pV; 12 } 13 14 } // end class MyClassF
5. (5 pts) Given all the problems identified in problems 1 through 4, explain in detail why the following code works, ie, compiles without errors or warnings.
1 public class MyClassG { 2 public static void main (String args []) { 3 MyClassH m = new MyClassH (23, true); 4 } // end main 5 } // end class MyClassG 6 7 class MyClassH { 8 int v = 12; 9 10 public MyClassH (int x, boolean b) { 11 this (x); 12 } 13 14 private MyClassH (int pV) { 15 v = pV; 16 } 17 18 } // end class MyClassH
6. (5 pts) Explain why the following class hierarchy is not reasonable:
• DefenseDepartment o General
§ Private
3
7. (5 pts) Give at least one example of a reasonable field for each of the following classes in the following class hierarchy. Be sure that the field is at the right level in the hierarchy.
• Vehicle o Car o Airplane
§ Passenger § Fighter § Bomber
o SpaceShip
8. (5 pts) Give at least one example of a reasonable method for each of the following classes in the following class hierarchy. Be sure that the method is at the right level in the hierarchy. Constructors, getters and setters don't count for this problem.
• Vehicle o Car o Airplane
§ Passenger § Fighter § Bomber
o SpaceShip
9. (5 pts) Please provide an example of an encapsulation and an inheritance relationship? Explain 10. (5 pts) Present reasonable parent and child classes for the class Tree (the biological kind). Give a short explanation for why the classes you are proposing are in good parent-child relationships.
Grading Rubric:
Attribute Meets Does not meet Problem 1 5 points
Explains why the code as shown is almost certainly not what the programmer intended.
Explains how it should be fixed to work the way the programmer probably had in mind.
0 points Does not explain why the code as shown is almost certainly not what the programmer intended.
Does not explain how it should be fixed to work the way the programmer probably had in mind.
Problem 2 5 points Explains why the code as shown is almost certainly not what the programmer intended.
Explains how it should be fixed to work the way the programmer probably had in mind.
0 points Does not explain why the code as shown is almost certainly not what the programmer intended.
Does not explain how it should be fixed to work the way the programmer probably had in mind.
4
Problem 3 5 points Explains why the code as shown is almost certainly not what the programmer intended.
Explains how it should be fixed to work the way the programmer probably had in mind.
0 points Does not explain why the code as shown is almost certainly not what the programmer intended.
Does not explain how it should be fixed to work the way the programmer probably had in mind.
Problem 4 5 points Explains why the code as shown is almost certainly not what the programmer intended.
Explains how it should be fixed to work the way the programmer probably had in mind.
0 points Does not explain why the code as shown is almost certainly not what the programmer intended.
Does not explain how it should be fixed to work the way the programmer probably had in mind.
Problem 5 5 points Given all the problems identified in problems 1 through 4, explains in detail why the code works, ie, compiles without errors or warnings.
0 points Given all the problems identified in problems 1 through 4, does not explain in detail why the code works, ie, compiles without errors or warnings.
Problem 6 5 points Explains why the class hierarchy is not reasonable.
0 points Does not explain why the class hierarchy is not reasonable.
Problem 7 5 points Gives at least one example of a reasonable field for each of the classes.
The field is at the right level in the hierarchy.
0 points Does not give at least one example of a reasonable field for each of the classes.
The field is not at the right level in the hierarchy.
Problem 8 5 points Gives at least one example of a reasonable method for each of the classes.
The method is at the right level in the hierarchy.
Does not include constructors, getters and setters.
0 points Does not give at least one example of a reasonable method for each of the classes.
The method is not at the right level in the hierarchy.
Includes constructors, getters and setters.
Problem 9 5 points Explains inheritance and encapsulation correctly and in
0 points Does not explain inheritance and encapsulation correctly and in sufficient detail given the example provided.
5
sufficient detail given the example provided.
Problem 10 5 points Presents reasonable parent and child classes for the class Tree.
Gives a short explanation for why the classes you are proposing are in good parent-child relationships.
0 points Does not present reasonable parent and child classes for the class Tree.
Does not give a short explanation for why the classes you are proposing are in good parent-child relationships.