1 PROG2004 Assignment 1 Weight: 20% of your final mark Due: 23rd August 2021 10 pm Specifications Your task is to complete various exercises in Netbeans, using the Java language, and to submit these via the MySCU link created for this purpose. Marking criteria includes: • Use of correct coding style, including the use of comments; • Accuracy of coding; • Use of suitable coding structures; • Correct submission and naming conventions of assessment items as required. Getting Help This assignment is to be completed individually. It is the opportunity to gain an understanding of the concepts of object oriented programming and coding syntax. It is important that you master these concepts yourself. You are permitted to work from the examples in the study guide or textbook but you must acknowledge assistance from other textbooks or classmates. In particular, you must not use online material or help from others, as this would prevent you from mastering these concepts. Who can you get help from? Use this diagram to determine from whom you may seek help with your program. Encouraged Attribution Required Ask tutor Not acceptable Lecturer Tutors Online Forums Relatives Students outside unit Hired coders Classmates Private Tutors Other 2 Please note that if your marker has any suspicion that you had help with your code or that your work is not your own you will be asked to come to a meeting with your marker to explain your code. Any student who is unable to explain their code will be submitted for academic misconduct. Part 1 – Classes and objects Create a new Java project called firstName_lastName_Part1 in Netbeans. In my case the project would be called alex_hendry_Part1. Select the option to create a main method. Create a new class called Computer. In the Computer class write the code for: • Instance variables to store the computers make and model • Two other instance variables that are appropriate for a computer • A default constructor and a second constructor that initialises all four of the instance variables • Accessor (getters) and mutator methods (setters) for all four of the instance variables • A method called printDetails that prints the computers details e.g. “The computers details are: “ followed by all four of the instance variables formatted for readability In the main method write the code to: • Create 2 computers, one using the default constructor, the other using the constructor that initialises all the instance variables for the computer • Demonstrate the use of one accessor method and one mutator method for one of the computers you created • Print the computers details using the printDetails method for one of the computers you created Part 2 – Inheritance, collections and polymorphism Create a new Java project called firstName_lastName_Part2 in Netbeans. In my case the project would be called alex_hendry_Part2. Select the option to create a main method. Create a new class called Computer. Create a second new class called Laptop. Modify the new Laptop class so that it extends Computer (Computer is the superclass; Laptop is the subclass). Rewrite the program you created in Part 1 so that: • The instance variables and accessor and mutator methods for the make and model are in the Computer class • The two other instance variables and accessor and mutator methods are in the Laptop class 3 • The 2 constructors in the Laptop class call the appropriate constructors in the Computer class using the super keyword. The constructor in the Laptop class that takes parameters must initialise the make and model in the Computer class • The Computer class has a method called printDetails that prints the make and model of the computer. Override the printDetails method in the Laptop class and print all of the laptop details as you did in part 1. The printDetails method in the Laptop class must use the super keyword to call the printDetails method in the Computer class In the main method write the code to: • Declare an ArrayList with a type parameter of Laptop • Add at least 2 laptops to the ArrayList • Use an Iterator (java.util.Iterator) to loop through the laptops in the ArrayList and print out the make and model. Please note that use of any other kind of loop will not receive any marks. • Check if the ArrayList contains a particular laptop • Get a laptop from the ArrayList • Remove a laptop from the ArrayList • Print the size of the ArrayList • Clear the ArrayList In the class that contains the main method, create a second method that takes a Computer as a parameter. Write the code to print out the computers make and model using the Computer accessor methods. Then create an object of type Laptop and an object of type Computer in the main method and use the method you have just created to demonstrate polymorphism. Part 3 – Abstract classes Create a new Java project called firstName_lastName_Part3 in Netbeans. In my case the project would be called alex_hendry_Part3. Select the option to create a main method. Create a new class called Laptop. Create a second new class called Computer. Rewrite your code from Part2 so that: • The Computer class is abstract. • The Computer contains at least one abstract method All methods, constructors etc that were in the Laptop and Computer classes in part 2 must be included in part 3. You need to rewrite the Laptop and Computer classes from part 2 so that Computer is abstract and there are multiple ways to create a Laptop. Check your code works by creating a new Laptop in your main method. 4 Part 4 – Interfaces Create a new Java project called firstName_lastName_Part4 in Netbeans. In my case the project would be called alex_hendry_Part4. Select the option to create a main method. Create a new class called Laptop. Create a new interface called Computer. Rewrite your code from Part2 so that: • Computer is an interface • Laptop implements Computer. All methods, constructors etc that were in the Laptop and Computer classes in part 2 must be included in part 4. You need to rewrite the Laptop and Computer classes from part 2 so that Computer is an interface and there are multiple ways to create a Laptop. Check your code works by creating a new Laptop in your main method. Submission You should now have 4 Netbeans projects. You must zip the projects into one zip file called firstName_lastName_Part3.zip. For example, mine would be alex_hendry_A1.zip. Submit this file via the Assignment 1 link on MySCU by the due date. Please leave enough time for it to upload, so do not submit at the last minute!
欢迎咨询51作业君