Skip to main content
留学咨询

辅导案例-FIT2099

By May 15, 2020No Comments

Monash University FIT2099 Object-Oriented Design and Implementation 2020 S1 Java Bootcamp, Week 2 Classes and Objects Objectives In this week’s lab, you will: • design and implement a multi-class program • use fields (a.k.a. attributes) in Java classes • use methods (a.k.a. operations) in Java classes • use git to store your code and documentation In the assessed lab exercises this semester, you will create a simple framework for an information system that keeps track of information for a university. This lab is worth 2% of your final mark for FIT2099. Task 1. UML Class diagram You must draw a UML class diagram showing the system that you plan to implement in this Bootcamp session, and should show it to a staff member before you start coding. Note that this system will incorpo- rate work you have done in multiple tasks, so read the entire lab sheet carefully. You will be working on this system for a few weeks, but today you don’t have to include anything that isn’t covered in this week’s Bootcamp. You’ll be creating updated class diagrams each week. This diagram should be quick and simple. It only needs to show the classes you plan to create and the relationships (associations and dependencies in UML) between them. You don’t need to show attributes or methods. You are strongly encouraged to draw this diagram by hand, either on paper or on a white- board1. Remember that you need to do the readings on Moodle before the lectures and labs each week. This week there are readings about UML class diagrams. Even if you don’t finish the challenges today, you should get feedback on your completed UML class diagram before you leave. This will mean you can work at home without coding up a poorly-designed solution. Task 2. Start the implementation Even when you have a complete design, it is usually a good idea to implement and test your program bit by bit. Create a new Eclipse project called JavaUniversity. There is a Java source file called University.java on Moodle. Download it and see if you can figure out how to add it to your Eclipse project. The source code is reproduced on the next page. 1If you choose to use the whiteboard in your classroom, take a photo so you can refer to it later. 1 Monash University FIT2099 Object-Oriented Design and Implementation 2020 S1 1 public class University { public void printStatus() { 3 System.out.println(“Welcome to Java University”); System.out.println(); 5 System.out.println(“Thank you for using Java University”); } 7 } As you can see, all the class can currently do is print a welcome message. Once you have added the class to your project, create a new UniversityDriver class. This class should contain only a main(…) method that creates a University object and calls its printStatus method. Run your program and confirm that it works as expected. While you are working on this task, the lab staff will be circulating the room assisting students and providing feedback on your UML class diagrams. Please ensure that you have had feedback from lab staff before proceeding to task 3. Task 3. Extending the implementation – adding a Unit class The system needs a Unit class. Each Unit object must know its unit code (e.g. “FIT1234” and its name (e.g. “Advanced Bogosorts”). The Unit class should also have a getUnitDescription() method, that returns a string of the concatenated unit code and name, e.g. “FIT1234 Advanced Bogosorts”. To test your Unit class, add some code to University.printStatus() that • creates a Unit object and • prints its description using the getUnitDescription() method. Confirm that your program is producing correct output before proceeding to the next task; if it isn’t, and you can’t figure out why, consult a staff member. Task 4. Arrays of Units Now, we would like the system to be able to handle an arbitrary number of Units. Modify the University class so that instead of containing a single Unit, it contains an array of Units.2 Add two new methods, createUnits() and displayUnits(), to University. • createUnits() must create three new Unit objects, add unit codes and descriptions to them, and store them in the array. • displayUnits() must display the descriptions for the units, which you can generate by invoking getUnitDescription() on each of the units in the array. Try to use a loop rather than repeated code, and try to avoid hard-coding the array length into displayUnits. If you need additional information about Java arrays and/or Java loops, Oracle has comprehensive documentation for Java at http://docs.oracle.com/javase/8/. Hint: have a look at the tutorials, particularly the “learning the language” tutorials. There are links to these on Moodle. Modify the printStatus() method to display the welcome message, call the createUnits() method, call the displayUnits() method, and then display the goodbye message. 2Java offers you several other ways to store a collection of Units. For now, we’ll keep it simple by just using an array. 2 Monash University FIT2099 Object-Oriented Design and Implementation 2020 S1 Task 5. Using git As of Week 3, you will be required to keep your Bootcamp source code on git.infotech.monash.edu, so it is a good idea to upload your Week 2 code there now. There are a set of Java Bootcamp Notes on this week’s Moodle page that will help you set up and manage your local git repository. Using git is not a Challenge for this week. This gives late enrolees and students who strike technical problems a chance to fix their git setup. However, git will be required for next week’s Challenges. Please make sure that git is working for you before you attempt the Week 3 worksheet. That’s it for this week’s bootcamp. Now read the Challenges and check that you have done them to your own satisfaction before you call a staff member over to be marked. Don’t leave this to the last minute, though – they might find that your code or diagram has a problem that needs to be rectified. Challenges This lab contains two Challenges, each of which is marked pass/fail. Challenges are listed at the end of this sheet and are worth one mark each. In order to pass a Challenge, you need to complete it fully. Challenge 1: Show your marker a system that runs as described. That is, it creates three Unit objects, stores them, and displays their information. You must also provide a UML class diagram showing the classes and the relationships between them. Challenge 2: Show your marker that your system follows good Java practices and meets non-functional requirements. This includes: • implementing the structure precisely as specified, • following the Google Java Style Guide, • hiding implementation details as much as possible, • having well-chosen names for attributes and methods (other than those we have named for you), and • correctly distinguishing between associations and dependencies in the class diagram. 3

admin

Author admin

More posts by admin