Complete exercises in BlueJ

1
CSC72003 – Programming II Assignment 1
Weight: 20% of your final mark
Due: 14th December 2018 at 10 pm
Specifications
Your task is to complete various exercises in BlueJ, using the Java language, and to submit these via the MySCU link created for this purpose.
The exercises may be found at the end of topics 1 to 5 in your study guide, as well as below.
Marking criteria includes:
• Use of correct coding style, including the use of comments;
• Accuracy of coding;
• Use of suitable coding structures;
• Correct submission 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 on which later learning will be based. It is important that you master these concepts yourself. Since you are mastering fundamental skills, you are permitted to work from the examples in the study guide or textbook but you must acknowledge assistance from other textbooks or classmates. 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.
Lecturer
Tutors
Online Forums Relatives
Students outside unit
Hired coders Classmates
Private Tutors
Other
Encouraged
Attribution Required
Ask tutor
Not acceptable
Assignment Questions
Question 1
[From Topic 1]
Open the house project from Topic 1. Open the terminal window and record method calls.
2
Create a picture with at least 6 objects, recording all method calls.
Take a screenshot of your picture and add the pasted list of method calls needed to create the picture.
Your work should be in a Word document, with your name and student ID in the footer, as well as “CSC72003 Ass 1 Q1”. Call your document by your username_Q1.docx. Save this document in a folder called username_A1. For example, my folder would be called rmason10_A1.
You will save all your work in this folder, and zip it to submit at the end of your assignment.
Question 2
[From Topic 2]
Create a new BlueJ project called your username-A1Q2. For example, mine would be rmason10-A1Q2.
Click on New Class and give the class a name of Person. Make sure “Java” and “class” are selected.
Write a description of your new Class in the top comments. Make sure you put in your name as the author and give the version as the date you last worked on this exercise.
Add definitions for the following fields:
• a name field of type String
• an age field of type int
• an eyeColour field of type String
• a boolean field called canDrive
Write a constructor for your Person class that takes two parameters – the first of type String called myName, and the second of type int called myAge. Set the initial values of the Person class’s fields, using the constructor.
Write an accessor method called getName() that returns the value of the name field.
Write a mutator method called setAge() that takes a single parameter of type int and sets the value of the age field.
Work out what other accessor and mutator methods would be useful for this class and add them.
Write a method called printDetails, which prints out all the details of a Person object. For example: if the name field holds the value “Helen” then the printDetails would print (in part):
The name of this person is Helen.
Take into account the canDrive status. The printDetails() method should print a line saying
3
either that the person can drive, or the person cannot drive.
Zip the project folder and save in the assignment folder.
Question 3.
[From workshop Topic 3]
Create a new BlueJ project called your username-A1Q3. For example, mine would be rmason10-A1Q3.
Create a class, Heater, that contains four fields, temperature, increment, max and min, all of whose type is double.
Make sure you write a description of your new Class in the comments, with your name as author and date as the last date you worked on this exercise.
Define a constructor that takes and sets the min, max and sets the temperature to 20.0, and increment to 1.0.
Also define a constructor that takes no parameters. The temperature field should be set to the value of 20.0 in this constructor, increment to 1.0, and maximum and minimum to reasonable amounts.
Define the mutators warmer and cooler, whose effect is to increase or decrease the value of temperature by the increment respectively.
The mutator methods should not let the temperature be set to a value higher than max, or lower than min. Add a mutator method that sets the value of the increment. Make sure you add a check to make sure that unrealistic values are not passed to this mutator method.
Define an accessor method to return the value of temperature.
Test your work.
Zip the project and include in your assessment files.
Question 4
[From workshop Topic 4]
Create a new BlueJ project called your username-A1Q4. For example, mine would be rmason10-A1Q4. Create a class, FBNames, which has one ArrayList field called names, which holds a collection of Strings.
Make sure you write a description of your new Class in the comments, with your name as author and date as the last date you worked on this exercise.
Define a constructor that initialises the ArrayList. Note that you can add any other initialisations that you feel are relevant.
Create methods to add elements, remove elements and get the number of elements in the collection. Make sure you add tests for errors and sensible error messages.
Create a method called printFizzBuzz(). This method should loop through the collection, and print out the elements (each String on one line). If the String starts with a, e, i, o or u, instead of
4
printing the String, it should print “Fizz” on the line. If the String starts with A, E, I, O or U, instead of printing the String, it should print “Buzz”.
For example, if the collection contained the names “banana”, “Apple”, “orange”, “pear”, “peach”, “kiwi fruit”, “Grape”, then the printout would look like:
banana
Buzz
Fizz
pear
peach
kiwi fruit
Grape
Once you have finished your project, open the terminal window in BlueJ and turn on record method calls. Create a new FBNames class, and then add at least 11 Strings. Make sure you don’t use the same collection as my example.
Demonstrate removing an element, and then find the number of elements using your methods. Finally, run your FizzBuzz method.
Copy all your calls into a text file and save it in your project folder.
Zip the project and include in your assessment files.
Question 5
[From workshop Topic 5]
Part A:
Imagine you need to open a standard combination dial lock but don’t know the combination and don’t have a pair of bolt cutters. Write a Java program in BlueJ with a method that prints all possible combinations, so you can print them on a piece of paper and check off each one as you try it. Assume the numbers on each dial range from zero to thirty-six and three numbers in sequence are needed to open the lock.
Part B:
Suppose the lock isn’t a very good one and any number that’s no more than two away from the correct number in each digit will also work.
In other words if the combination is 17-6-32, then 18-5-31, 19-4-32, 15-8-33 and many other combinations will also open the lock.
Write another method that prints out a minimal list of combinations you would need to try to guarantee opening the lock.
Submission
You must zip the files in your folder into one zip file called username_A1.zip For example, mine would be rmason10_A1.zip.
Submit this file via the Assignment 1 link on MySCU by the due date. Please leave enough
5
time for it to upload, so do not submit at the last minute!