Assignment Chef icon Assignment Chef

Browse assignments

Assignment catalog

33,401 assignments available

[SOLVED] Cmsc 335 project 3

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.htmlAs 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 intersectionsSome 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 yourtest 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.

$25.00 View

[SOLVED] Cmsc 335 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.

$25.00 View

[SOLVED] Cmsc 335 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 ComboBox2. (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.

$25.00 View

[SOLVED] Cmsc 335 project 2

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.htmlDesign, 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.

$25.00 View

[SOLVED] Cmsc 335 homework 2

1. (5 pts) What are the diagrams defined in the UML Standard. Give a one or two sentence description of each one. Please provide a small example of a UML diagram.2. (5 pts) Given the following code, how should the toString methods in the classes H2ClassA and H2ClassB be written to give the indicated output and take advantage of the natural toString method in H2ClassB? 1 import java.util.ArrayList; 23 public class H2ClassA { 4 ArrayList list = new ArrayList (); 5 6 public static void main (String args []) { 7 H2ClassA y = new H2ClassA (); 8 int [] v = {4, 3, 7, 5, 99, 3}; 9 for (int m: v) 10 y.list.add (new H2ClassB (m)); 11 System.out.println (y); 12 } // end main 13 14 } // end class H2ClassA 15 16 class H2ClassB { 17 int x; 18 H2ClassB (int a) { x = a;} 19 } // end H2ClassB OUTPUT: 4 3 7 5 99 3 3. (5 pts) How can the following code be corrected? Give at least two good answers. 1 public class H2ClassC { 2 H2ClassC (int a) {} 3 } // end class H2ClassC 4 5 class H2ClassD extends H2ClassC{ 6 } // end class H2ClassD 4. (5 pts) Why does the following code give a compiler error? How should it be fixed? 2 1 public class H2ClassE { 2 int x, y, z; 34 H2ClassE (int a) { 5 x = a; 6 this (5, 12); 7 } 8 9 H2ClassE (int b, int c) { 10 y = b; 11 z = c; 12 } 13 } // end class H2ClassE 5. (5 pts) What is wrong with the following declaration? How should it be fixed? public static final int myNumber = 17.36; 6. (5 pts) What is wrong with the following code? How should it be fixed? 1 public class H2ClassG { 2 final int x; 3 4 H2ClassG () {} 5 H2ClassG (int a) {x = a;} 6 } // end class H2ClassG 7. (5 pts) What is wrong with the following code? How should it be fixed? 1 public class H2ClassH { 2 final int x; 3 4 int H2ClassH () { 5 if (x == 7) return 1; 6 return 2; 7 } // end 8 } // end class H2ClassH 8. (5 pts) What is wrong with the following code? x should be given a value of 24. What are two ways this can be legally accomplished? 1 public class H2ClassI { 2 final int x; 3 4 public static void main (String args []) { 5 H2ClassI h = new H2ClassI (); 3 6 h.x = 24; 7 } // end main 8 } // end class H2ClassI 9. (5 pts) What is wrong with the following Swing code? Give two effective ways to fix it. 1 import javax.swing.*; 2 import java.awt.event.*; 3 4 public class H2ClassJ extends JFrame { 5 public static final long serialVersionUID = 22; 6 7 public H2ClassJ () { 8 addMouseListener (new MouseListener () { 9 public void mouseClicked (MouseEvent e) {} 10 }); 11 } // end constructor 12 13 } // end class H2ClassJ 10. (5 pts) What is incorrect in the following FX GUI code? 1 import javax.javafx.*; 2 3 public class H2ClassK { 4 submit.setOnAction((ActionEvent e) -> { 5 label.setText(“A comment”); 6 }); 7 } // end class H2ClassK Grading Rubric: Attribute Meets Does not meet Problem 1 5 points Gives a one or two sentence description of each standard UML diagram. 0 points Does not give a one or two sentence description of each standard UML diagram. Problem 2 5 points Explains how the toString methods in the classes H2ClassA and H2ClassB be written to give the indicated output and take advantage of the natural toString method in H2ClassB. 0 points Does not explains how the toString methods in the classes H2ClassA and H2ClassB be written to give the indicated output and take advantage of the natural toString method in H2ClassB.Problem 3 5 points Provides at least two good answers 0 points Does not provide at least two good 4 explaining how the code can be corrected. answers explaining how the code can be corrected.Problem 4 5 points Explains why the code gives a compiler error. Explains how the code should be fixed. 0 points Does not explain why the code gives a compiler error. Does not explain how the code should be fixed.Problem 5 5 points Explains what is wrong with the declaration. Explains how the code should be fixed. 0 points Does not explain what is wrong with the declaration. Does not explain how the code should be fixed.Problem 6 5 points Explains what is wrong with the code. Explains how the code should be fixed. 0 points Does not explain what is wrong with the code. Does not explain how the code should be fixed.Problem 7 5 points Explains what is wrong with the code. Explains how the code should be fixed. 0 points Does not explain what is wrong with the code. Does not explain how the code should be fixed.Problem 8 5 points Explains what is wrong with the code. Explains two ways x could be given a values of 24 legally. 0 points Does not explain what is wrong with the code. Does not explain two ways x could be given a values of 24 legally.Problem 9 5 points Explains what is wrong with the code. Explains 2 effective ways the code could be fixed. 0 points Does not explain what is wrong with the code. Does not explain 2 effective ways the code could be fixed. Problem 10 5 points Explains why the code is incorrect. Explains how it should be fixed. 0 points Does not explain why the code is incorrect. Does not explain how it should be fixed.

$25.00 View

[SOLVED] Cmsc 335 project 1

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.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 volumeNote 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 isa 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 yourtest 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.

$25.00 View

[SOLVED] Cmsc 335 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.

$25.00 View

[SOLVED] Cmsc 215 intermediate programming programming project 4

The fourth programming project involves writing a program to test the relationships between time intervals. The program should contain four classes. The first class should be a generic class Interval defined for any type that implements the Comparable interface. Objects of this type have a start and end of the generic type parameter that defines the start and end of the interval. The class should be immutable, so it should have no setter methods. At a minimum, it should contain the following public methods:  A constructor that accepts the start and end of an interval and constructs an Interval object  A method within that is supplied an object of the generic type parameter and returns whether that object is inside the interval, including the endpoints  A method subinterval that is passed an interval as a parameter and returns whether the interval parameter is a subinterval, completely within, the interval on which the method is invoked  A method overlaps that is passed an interval as a parameter and returns whether the interval parameter overlaps the interval on which the method is invoked The second class Time should contain two integer instance variables that represent the hours and minutes and one additional variable for the meridian, AM or PM. The class should implement the Comparable interface and should be immutable, so it should have no setter methods. At a minimum, it should contain the following public methods:  A constructor that accepts the hours and minutes as integers and the meridian as a string and constructs a Time object  A constructor that accepts a string representation of a time in the format HH:MM AM and constructs a Time object  A method compareTo that compares two times and returns what is required of all such methods that implement the Comparable interface  A method toString that returns the string representation of the time in the format HH:MM AM When either constructor is called, several checks need to be made on the input. For both constructors, a check is needed to ensure that the hours and minutes are within range and that the meridian is AM or PM. For the constructor that accepts the string representation, additional checks are needed to ensure that the hours and minutes are numeric values. Should any check fail, an exception InvalidTime should be thrown that includes the reason. The third class is the exception class InvalidTime that implements a checked exception. It should have an instance variable of type String that saves the message and the following method:  A constructor that accepts the message as a string and constructs an InvalidTime object The fourth class Project4 should implement a GUI interface that contains two buttons. The first button CompareIntervals should compare the two intervals and output one of the following messages depending upon how the intervals compare:  Interval 1 is a sub-interval of interval 2  Interval 2 is a sub-interval of interval 1  The intervals overlap  The intervals are disjoint Shown below is an example of the output when the CompareIntervals button is clicked: The second button CheckTime should check whether the time is within the intervals and output one of the following messages depending upon which intervals it is within:  Both intervals contains the time HH:MM AM  Only interval 1 contains the time HH:MM AM  Only interval 2 contains the time HH:MM AM  Neither interval contains the time HH:MM AM Shown below is an example of the output when the CheckTime button is clicked: You are to submit two files. 1. The first is a .zip file that contains all the source code for the project. The .zip file should contain only source code and nothing else, which means only the .java files. If you elect to use a package, the .java files should be in a folder whose name is the package name. Every outer class should be in a separate .java file with the same name as the class name. Each file should include a comment block at the top containing your name, the project name, the date, and a short description of the class contained in that file. 2. The second is a Word document (PDF or RTF is also acceptable) that contains the documentation for the project, which should include the following: a. A UML class diagram that includes all classes you wrote. Do not include predefined classes. b. A test plan that includes test cases that you have created indicating what aspects of the program each one is testing c. A short paragraph on lessons learned from the project

$25.00 View

[SOLVED] Cmsc 215 intermediate programming programming project 2

The second programming project involves writing a program that produces a list of students who are eligible for membership in an honor society. This program consists of four classes. The first class is the Student class. It has three instance variables which include the student name, credit hours earned and quality points. At a minimum, it should have following methods:  A constructor that allows the student’s name, credit hours and quality points to be initialized.  A method named gpa that returns the student’s grade point average, which is computed as the quotient of the quality points and credit hours  A method eligibleForHonorSociety that returns whether a student’s gpa exceeds the threshold for honor society membership, which applies to all students  A toString method that returns a string containing the student name and grade point average  A class (static) method setGpaThreshold that sets the minimum gpa threshold for honor society membership The Student class has two subclasses. The first is Undergraduate. It has an additional instance variable that specifies the student’s year: either a freshman, sophomore, junior or senior. At a minimum, it should have following methods:  A constructor that allows the student’s name, credit hours, quality points and year to be initialized  An overridden method eligibleForHonorSociety that applies the requirement that the student be either a junior or senior in addition to the requirement that applies to all students to be eligible for honor society membership  An overridden toString method that returns a string containing the student name, grade point average, and year The second subclass is Graduate. It has an additional instance variable that reflects whether the student is pursuing a master’s degree or doctorate At a minimum, it should have following methods:  A constructor that allows the student’s name, credit hours, quality points and degree sought to be initialized  An overridden method eligibleForHonorSociety that applies the requirement that the student be seeking a master’s degree in addition to the requirement that applies to all students to be eligible for honor society membership  An overridden toString method that returns a string containing the student name, grade point average, and degree sought Finally there should be a fourth class Project2 that contains the main method. It should read in student information from a text file named students.txt. If the file does not exist, an error message should be displayed and the program should terminate. Each line of the text file will represent the information for one student. An example of how the text file will look is shown below: Brown,William 72 230 Junior Johnson,Mary 21 77 Masters Jones,Sally 32 95 Sophomore For undergraduate students, the final value is the student’s year. For graduate students, the final value is the degree the student is seeking. As the students are read in, Student objects of the appropriate type should be created and they should be stored in an array list of type Student. As the students are read in, the total of all grade point averages should be accumulated so that an average gpa can be computed. You may assume that the file that the data in the file will be formatted correctly. Once all the student data is read in, the threshold for honor society membership should then be set to the midpoint of the average gpa and the highest possible gpa of 4.0 by calling the setGpaThreshold method. The threshold should also be displayed on the console. Then a report should be displayed on the console that lists all students who are eligible for membership . Be sure to follow good programming style, which means making all instance variables private, naming all constants and avoiding the duplication of code. Furthermore you must select enough test data to completely test the program. You are to submit two files. 1. The first is a .zip file that contains all the source code for the project. The .zip file should contain only source code and nothing else, which means only the .java files. If you elect to use a package, the .java files should be in a folder whose name is the package name. Every outer class should be in a separate .java file with the same name as the class name. Each file should include a comment block at the top containing your name, the project name, the date, and a short description of the class contained in that file. 2. The second is a Word document (PDF or RTF is also acceptable) that contains the documentation for the project, which should include the following: a. A UML class diagram that includes all classes you wrote. Do not include predefined classes b. A test plan that includes test cases that you have created indicating what aspects of the program each one is testing c. A short paragraph on lessons learned from the project

$25.00 View

[SOLVED] Cmsc 215 intermediate programming programming project 1

The first programming project involves writing a program to find the tallest basketball player whose age is less than or equal to the average of all the players. The program should contain three classes. The first class Height should contain two integer instance variables for the feet and inches. The class should be immutable, so it should have no setter methods At a minimum it should contain the following methods:  A constructor that accepts feet and inches constructs a Height object  A method toInches that returns the height in total inches  A method toString that returns the string representation of the height with a single quote following the feet and a double quote following the inches Regardless of what value for inches was supplied to the constructor the toString method should display the height normalized so the inches are less than 12. The second class Player should contain three instance variables that include the player’s name, the player’s height, which should be stored as the type Height, and the player’s age. The class should be immutable, so it should have no setter methods It should contain the following methods:  A constructor that accepts a player’s name, height and age constructs a Player object  Getter methods for each of the instance variables  A method toString that returns the string representation of a player with each field appropriately labeled The toString method of the Player class should call the toString method of the Height class. The third class Project1 should repeatedly prompt the user for the information for each of the players. It should create a Player object for each player and add the player to an ArrayList. As the players are read in, the total age of all players should be computed to enable the average to be calculate once all have been input. Once all player information has been input, the average age of all players should be output. Then the list of players should be traversed to find the tallest player whose age is less than or equal to the average age of all players. You are to submit two files. 1. The first is a .zip file that contains all the source code for the project. The .zip file should contain only source code and nothing else, which means only the .java files. If you elect to use a package the .java files should be in a folder whose name is the package name. Every outer class should be in a separate .java file with the same name as the class name. Each file should include a comment block at the top containing your name, the project name, the date, and a short description of the class contained in that file. 2. The second is a Word document (PDF or RTF is also acceptable) that contains the documentation for the project, which should include the following: a. A UML class diagram that includes all classes you wrote. Do not include predefined classes. b. A test plan that includes test cases that you have created indicating what aspects of the program each one is testing c. A short paragraph on lessons learned from the project

$25.00 View

[SOLVED] Cmsc 451 project 2 project 2 involves writing an analysis of the results that you obtained in first project.

Project 2 involves writing an analysis of the results that you obtained in first project. You are to submit a paper that discusses the results of your analysis. Your paper should include the following items: • Title Page • Table of Contents – with the following headers and sub-headers (in CAPS) • INTRODUCTION – A brief introduction of the sorting algorithms that you have selected and how the two algorithms compare including: o PSEUDOCODE – High-level pseudocode for the sorting algorithms o BIG- Θ – A Big-Θ analysis of the two algorithms o JVM WARM UP – An explanation of your approach to avoiding the problems associated with JVM warm-up o CRITICAL OPERATION – A discussion of the critical operation that you chose to count for each algorithm with an explanation of why you selected it • ANALYSIS – An analysis of the results of your study, which should include: o GRAPH – line graph of critical operations and execution times for both algorithms o PERFORMANCE COMPARISON – a comparison of the performance of the two algorithms o CRITICAL OPERATION RESULTS AND TIME MEASUREMENTS – a comparison of the critical operation results and the actual execution time measurements o COEFFICIENT OF VARIATION – a discussion of the significance of the coefficient of variance results and how it reflects the data sensitivity of both algorithms o RESULTS vs BIG- Θ – how your results compare to your Big-Θ analysis • CONCLUSION – A conclusion that summarizes the important observations of your study If for any reason, it was necessary to revise the program you submitted in project 1, the revised source code should also be included along with the paper.

$25.00 View

[SOLVED] Cmsc451 homework 6 1. using warshall’s algorithm, compute the reflexive-transitive closure of the relation below.

1. Using Warshall’s algorithm, compute the reflexive-transitive closure of the relation below. Show the matrix after the reflexive closure and then after each pass of the outermost for loop that computes the transitive closure. [ 0 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 0 0 1 0 1] 2. Using the matrix in the previous problem show the final result of executing Floyd’s algorithm on that matrix to produce a matrix containing path lengths. 3. Show the graph that corresponds to the matrix in the first problem assuming the rows and columns correspond to the vertices a, b, c, d and e. Show its condensation graph, renaming its vertices. Determine any topological order of that graph and create an adjacency matrix with the vertices ordered in that topological order. Finally compute the reflexive-transitive closure of that matrix. What characteristic of that matrix indicates that it defines a total order? 4. Using Floyd’s algorithm, compute the distance matrix for the weight directed graph defined by the following matrix: [ 0  4 −2  2 3 6 −3 2 0  4  5 0 ] Show the intermediate matrices after each iteration of the outermost loop.

$25.00 View

[SOLVED] Cmsc451 homework 5 1. execute prim’s minimum spanning tree algorithm by hand on the graph below showing how the data structures

1. Execute Prim’s minimum spanning tree algorithm by hand on the graph below showing how the data structures evolve specifically indicating when the distance from a fringe vertex to the tree is updated. Clearly indicate which edges become part of the minimum spanning tree and in which order. Start at vertex F. 2. Execute Kruskal’s algorithm on the weighted tree shown below. Assume that edges of equal weight will be in the priority queue in alphabetical order and each edge name is ordered alphabetically. Clearly show what happens each time an edge is removed from the priority queue and how the dynamic equivalence relation changes on each step and show the final minimum spanning tree that is generated. 3. Examine the minimum spanning trees generated in the previous two problems. In both cases, indicate whether the spanning tree is unique. If it is not unique provide all other minimum spanning trees. Explain how you made the determination whether the minimum spanning tree is unique. 4. Given the following adjacency lists (with edge weights in parentheses) for a directed graph: A: B(2), C(7), D(6) B: C(3), F(1) C: E(3) D: E(3) E: F(1) F: C(3), D(1) Execute Dijkstra’s shortest-path algorithm by hand on this graph, showing how the data structures evolve, with A as the starting vertex. Clearly indicate which edges become part of the shortest path tree and in which order.

$25.00 View

[SOLVED] Cmsc451 homework 4 consider the following directed graph for each of the problems: 1. perform a breadth-first search

Consider the following directed graph for each of the problems: 1. Perform a breadth-first search on the graph assuming that the vertices and adjacency lists are listed in alphabetical order. Show the breadth-first search tree that is generated. 2. Perform a depth-first search on the graph assuming that the vertices and adjacency lists are listed in alphabetical order. Classify each edge as tree, forward, back or cross edge. Label each vertex with its start and finish time. 3. Remove all the back edges from the graph so it becomes a DAG. Perform a depth-first search recording the start and finish times. Using those finish times, provide the topological order that is produced. Provide one breadth-first topological order for that graph. 4. Determine the strongly connected components of the graph using the algorithm provided in the sample problems. Show the final depth-first search of the transpose graph labeled with its start and finish times. Identify the strongly connected components based on that search.

$25.00 View

[SOLVED] Cmsc 451 project 1 the first project involves benchmarking the behavior of java implementations of two of the following sorting algorithms

The first project involves benchmarking the behavior of Java implementations of two of the following sorting algorithms: Quick Sort, Bubble Sort, Insertion Sort, Heap Sort, Radix Sort, Bucket Sort, Selection Sort, Merge Sort, Shell Sort, Bucket Sort. You must post your selection of the two algorithms that you chose in the “Ask the Professor” conference. Every student must have a unique combination of algorithms.. You must write the code to perform the benchmarking of the two algorithms that you selected. You do not have to write the sorting algorithms yourself, you may take them from some source, but you must reference your source. You must identify some critical operation to count for each algorithm that reflects the overall performance and modify each of the two sorting algorithms so that they count that operation. In addition to counting critical operations you must measure the actual run time in nanoseconds. In addition, you should examine the result of each call to verify that the data has been properly sorted to verify the correctness of the algorithm. If the array is not sorted, an exception should be thrown. It should also randomly generate data to pass to the sorting methods. It should produce 40 data sets for each value of n, the size of the data set and average the result of those 40 runs. The exact same data must be used for both sorting algorithms. It should also create 12 different sizes of data sets. Choose sizes that will clearly demonstrate the trend as n becomes large. Be sure that the data set sizes are evenly spaced so this data can be used to generate graphs in project 2 This project should consist of two separate programs (BenchmarkSorts.java and Report.java). The first of those programs should perform the benchmarking described above and generate two data files, one for each of the two sorting algorithms. The benchmarking program must be written to conform to the following design: The purpose of the methods in the abstract class AbstractSort are as follows: • The method sort is an abstract method that must be implemented in both of your classes that contain the sorting methods that you have selected • The startSort method should be called before the sort begins and it should initialize the counter and record the starting time of the sort • The endSort method should be called after the sort ends and it should compute the elapsed time of the sort • The incrementCount method should be called whenever the critical operation that you selected is executed and it should increment the critical operation counter • The getCount method should return the final value of the counter • The getTime method should return the elapsed time The output files should contain 12 lines that correspond to the 12 data set sizes. The first value on each line should be the data set size followed by 40 pairs of values. Each pair represents the critical element count and the time in nanoseconds for each of the 40 runs of that data set size. The values on each line should be delimited by spaces. The second program (Report.java) should produce the report. It should allow the user to select the input file using JFileChooser. The report should contain one line for each data set size and five columns and should be displayed using a JTable. The first column should contain the data set size the second the average of the critical counts for the 40 runs and the third the coefficient of variance of those 40 values expressed as a percentage. The fourth and fifth column should contain similar data for the times. The coefficient of variance of the critical operation counts and time measurement for the 40 runs of each data set size provide a way to gauge the data sensitivity of the algorithm. Shown below is an example of how the report should look: On the due date for project 1, you are to submit a .zip file that includes the source code for both programs. All the classes should be in the default package. You must research the issue of JVM warm-up necessary for properly benchmarking Java programs and ensure that your code performs the necessary warm-up so the time measurements are accurate.

$25.00 View

[SOLVED] Cmsc451 homework 3

1. Shown below is the code for the bubble sort consisting of two recursive methods that replace the two nested loops that would be used in its iterative counterpart: void bubbleSort(int array[]) { sort(array, 0); } void sort(int[] array, int i) { if (i < array.length – 1) { bubble(array, i, array.length – 1); sort(array, i + 1); } } void bubble(int[] array, int i, int j) { if (j

$25.00 View

[SOLVED] Cmsc 451 homework 6

1. Using Warshall’s algorithm, compute the reflexive-transitive closure of the relation below. Show the matrix after the reflexive closure and then after each pass of the outermost for loop that computes the transitive closure. [ 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1] 2. Using the matrix in the previous problem show the final result of executing Floyd’s algorithm on that matrix to produce a matrix containing path lengths. 3. Show the graph that corresponds to the matrix in the first problem assuming the rows and columns correspond to the vertices a, b, c, d and e. Show its condensation graph, renaming its vertices. Determine any topological order of that graph and create an adjacency matrix with the vertices ordered in that topological order. Finally compute the reflexive-transitive closure of that matrix. What characteristic of that matrix indicates that it defines a total order? 4. Using Floyd’s algorithm, compute the distance matrix for the weight directed graph defined by the following matrix: [ 0 4  5 2 0 3 3  2 0  −2  −4 0 ] Show the intermediate matrices after each iteration of the outermost loop. Grading Rubric Problem Meets Does Not Meet Problem 1 10 points 0 points Showed the correct matrix after the reflexive closure (2) Did not show the correct matrix after the reflexive closure (0) Showed the correct matrices after each pass of the outermost for loop that computes the transitive closure (8) Did not show the correct matrices after each pass of the outermost for loop that computes the transitive closure (0) Problem 2 10 points 0 points Showed the correct final result of executing Floyd’s algorithm on that matrix to produce a matrix containing path lengths (10) Did not show the correct final result of executing Floyd’s algorithm on that matrix to produce a matrix containing path lengths (0) Problem 3 10 points 0 points Showed the correct graph that corresponds to the matrix in the first problem assuming vertices a, b, c, d and e (1) Did not show the correct graph that corresponds to the matrix in the first problem assuming vertices a, b, c, d and e (0) Showed its correct condensation graph, renaming its vertices (2) Did not show its correct condensation graph, renaming its vertices (0) Determined a correct topological order of that graph (2) Did not determine a correct topological order of that graph (0) Created a correct adjacency matrix with the vertices ordered in that topological order (1) Did not create a correct adjacency matrix with the vertices ordered in that topological order (0) Correctly computed the reflexivetransitive closure of that matrix (2) Did not correctly compute the reflexive-transitive closure of that matrix (0) Correctly explained what characteristic of that matrix indicates that it defines a total order (2) Did not correctly explain what characteristic of that matrix indicates that it defines a total order (0) Problem 4 10 points 0 points Showed the correct intermediate matrices after each iteration of the outermost loop using Floyd’s algorithm (7) Did not show the correct intermediate matrices after each iteration of the outermost loop using Floyd’s algorithm (0) Showed the correct final matrix after executing Floyd’s algorithm (3) Did not show the correct final matrix after executing Floyd’s algorithm (0)

$25.00 View

[SOLVED] Cmsc451 homework 1

1. Consider the following iterative function: int square(int n) { int result = 0; for (int i = 1; i i; j–) if (array[j] < array[j – 1]) swap(array, j, j – 1); } Let n be the length of the array. Using summation evaluation, determine the number of swaps that are performed in the worst case as a function of n. 4. Given the following recursive function and it corresponding helper function that returns the sum of all the elements of an array that are located at even subscripts: int sumEvenElements(int array[], int i) { if (i >= array.length) return 0; return array[i] + sumEvenElements(array, i+2); } int sumEvenElements(int array[]) { return sumEvenElments(array, 0) } Assume n is the length of the array. Find the initial condition and recurrence equation that expresses the execution time for the worst case of the recursive function and then solve that recurrence.

$25.00 View