SlideShare a Scribd company logo
Modify the bouncing ball example demonstrated
FOR MORE CLASSES VISIT
tutorialoutletdotcom
COIS 2240 Assignment#3 Question#1
Modify the bouncing ball example demonstrated in class to include a
rectangle as shown in the
figure here: The width of the rectangle should be equal to radius*4,
while the height should be equal to the
radius. In your modified code, the ball should bounce back when it
touches the surface of the
rectangle. You should be able to move the rectangle left or right when
pressing on it with mouse
and dragging it towards the left or right.
Here is the the code shown in class for the bouncing ball:
www.cs.armstrong.edu/liang/intro11e/html/BallPane.html
www.cs.armstrong.edu/liang/intro11e/html/BounceBallControl.html
Question#2:
For the following class, write a JUnit test class to test the method
getTotalRentPayment and
whether an exception is thrown by the method setRentAmount.
public class
private
private
private
private RentCalculator {
double utilitiesCharge;
int numberOfMonths;
double rentAmount;
java.util.Date loanDate; /**
* Construct a RentCalculator with specified monthly utilities
charge, number of
* months, and rent amount
*/ COIS2240 Assignment#3 Page !2 of !3 public RentCalculator(double
utilitiesCharge, int numberOfMonths,
double rentAmount) {
this.utilitiesCharge = utilitiesCharge;
this.numberOfMonths = numberOfMonths;
this.rentAmount = rentAmount;
loanDate = new java.util.Date();
}
/** Return annualInterestRate */
public double getutilitiesChargee() {
return utilitiesCharge;
}
/** Set a new monthly untility charge */
public void setutilitiesCharge(double utilitiesCharge) {
this.utilitiesCharge = utilitiesCharge;
}
/** Return numberOfMonths */
public int getNumberOfMonths() {
return numberOfMonths;
}
/** Set a new numberOfMonths */
public void setNumberOfMonths(int numberOfMonths) {
this.numberOfMonths = numberOfMonths;
}
/** Return loanAmount */
public double getRentAmount() {
return rentAmount;
}
/** Set a newRentAmount */
public void setRentAmount(double rentAmount) throws Exception {
if (rentAmount < 0)
throw new Exception("Money cannot be negative");
this.rentAmount = rentAmount;
}
/** Find total payment */
public double getTotalRentPayment() {
double totalPayment = (rentAmount + utilitiesCharge) *
numberOfMonths;
return totalPayment;
} } /** Return loan date */
public java.util.Date getLoanDate() {
return loanDate;
} COIS2240 Assignment#3 Page !3 of !3 Question#3:
a) Following the Observer design pattern, write a class called
TenantObserver that prints a
message to the tenant in its update method when setRentAmount is
called in the
RentCalculator class from Question#2. Modify the RentCalculator class
to allow to register/
unregister observers.
b) Apply the Singleton pattern on RentCalculator to ensure that only one
RentCalculator is
could be instantiated. Change what is necessary in the RentCalculator
class to apply the
Singleton pattern.
Question#4: The List interface is defined as follows:
interface List {
int count(); //return the current number of elements in the list
Object get(int index); //return the object at the index in the list
Object first(); //return the first object in the list
Object last(); //return the last object in the list
boolean include(Object obj); //return true is the object in the list
void append(Object obj); //append the object to the end of the list
void prepend(Object obj); //insert the object to the front of the list
void delete(Object obj); //remove the object from the list
void deleteLast(); //remove the last element of the list
void deleteFirst(); //remove the first element of the list
void deleteAll(); //remove all elements of the list
}
(a) Write a class adapter to adapt Java ArrayList to the List interface.
(b) Write a main program to test your adapters through List interface.
(c) Same requirement as (a) and (b), but write an object adapter to adapt
Java ArrayList to the
List interface. For all these questions, test your code with some inputs.
You have to submit the following to the
blackboard:
1-Source code.
2-Screenshots of the output or the test runs. Put all the screenshots in a
single word document.
************************************************
(c) Same requirement as (a) and (b), but write an object adapter to adapt
Java ArrayList to the
List interface. For all these questions, test your code with some inputs.
You have to submit the following to the
blackboard:
1-Source code.
2-Screenshots of the output or the test runs. Put all the screenshots in a
single word document.
************************************************

More Related Content

PDF
Things to avoid in JavaScript
DOCX
01 list using array
PPTX
C Programming Language Part 7
Things to avoid in JavaScript
01 list using array
C Programming Language Part 7

What's hot (20)

PPTX
Stack using Array
PDF
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
PPTX
C Programming Language Step by Step Part 2
PPTX
C Programming Language Part 6
PPTX
Expressions using operator in c
PPT
Lecture 3 c++
TXT
Arm code arduino
PDF
Programs that work in c and not in c
PPTX
Adding two integers in c
PPTX
My lecture infix-to-postfix
PPTX
Conversion of Infix to Prefix and Postfix with Stack
DOCX
New microsoft office word document (2)
PDF
Introduction to Computer and Programing - Lecture 04
PDF
CalculateLoanPayments
DOCX
PDF
First c program
DOCX
Programming fundamentals
DOCX
Temp conversion
DOCX
Practical no 6
Stack using Array
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
C Programming Language Step by Step Part 2
C Programming Language Part 6
Expressions using operator in c
Lecture 3 c++
Arm code arduino
Programs that work in c and not in c
Adding two integers in c
My lecture infix-to-postfix
Conversion of Infix to Prefix and Postfix with Stack
New microsoft office word document (2)
Introduction to Computer and Programing - Lecture 04
CalculateLoanPayments
First c program
Programming fundamentals
Temp conversion
Practical no 6
Ad

Similar to Modify the bouncing ball example demonstrated/tutorialoutlet (20)

PDF
Java and j2ee_lab-manual
PDF
JavaProgrammingManual
PPT
Jeop game-final-review
PDF
Java Lab Manual
DOC
202: When the user clicks a JCheckBox, a(n) occurs.
DOC
22: The logical relationship between radio buttons is maintained by objects o...
DOC
17: provides the basic attributes and behaviors of a window—a title bar at th...
DOC
7: Assume the following class declaration.
DOC
3: A(n) ________ enables a program to read data from the user.
DOC
10: In the Java graphics system, coordinate units are measured in ________.
DOC
19: When the user presses Enter in a JTextField, the GUI component generates ...
DOC
18: Which of the following does not generate an event?
DOC
12: When an object is concatenated with a String
DOC
21: Which method determines if a JRadioButton is selected?
DOC
5: Every Java application is required to have
DOC
15: Which method call converts the value in variable stringVariable to an int...
DOC
8: Which statement below could be used to randomly select a state from an arr...
DOC
1: The .class extension on a file means that the file
DOC
11: Which is a correct way to invoke the static method sqrt of the Math class?
DOC
16: Which of the following is the method used to display a dialog box to gath...
Java and j2ee_lab-manual
JavaProgrammingManual
Jeop game-final-review
Java Lab Manual
202: When the user clicks a JCheckBox, a(n) occurs.
22: The logical relationship between radio buttons is maintained by objects o...
17: provides the basic attributes and behaviors of a window—a title bar at th...
7: Assume the following class declaration.
3: A(n) ________ enables a program to read data from the user.
10: In the Java graphics system, coordinate units are measured in ________.
19: When the user presses Enter in a JTextField, the GUI component generates ...
18: Which of the following does not generate an event?
12: When an object is concatenated with a String
21: Which method determines if a JRadioButton is selected?
5: Every Java application is required to have
15: Which method call converts the value in variable stringVariable to an int...
8: Which statement below could be used to randomly select a state from an arr...
1: The .class extension on a file means that the file
11: Which is a correct way to invoke the static method sqrt of the Math class?
16: Which of the following is the method used to display a dialog box to gath...
Ad

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PDF
Insiders guide to clinical Medicine.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
master seminar digital applications in india
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Types and Its function , kingdom of life
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Basic Mud Logging Guide for educational purpose
Insiders guide to clinical Medicine.pdf
Computing-Curriculum for Schools in Ghana
Microbial disease of the cardiovascular and lymphatic systems
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
master seminar digital applications in india
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Final Presentation General Medicine 03-08-2024.pptx
01-Introduction-to-Information-Management.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Supply Chain Operations Speaking Notes -ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
Sports Quiz easy sports quiz sports quiz
PPH.pptx obstetrics and gynecology in nursing
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Types and Its function , kingdom of life
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

Modify the bouncing ball example demonstrated/tutorialoutlet

  • 1. Modify the bouncing ball example demonstrated FOR MORE CLASSES VISIT tutorialoutletdotcom COIS 2240 Assignment#3 Question#1 Modify the bouncing ball example demonstrated in class to include a rectangle as shown in the figure here: The width of the rectangle should be equal to radius*4, while the height should be equal to the radius. In your modified code, the ball should bounce back when it touches the surface of the rectangle. You should be able to move the rectangle left or right when pressing on it with mouse and dragging it towards the left or right. Here is the the code shown in class for the bouncing ball: www.cs.armstrong.edu/liang/intro11e/html/BallPane.html www.cs.armstrong.edu/liang/intro11e/html/BounceBallControl.html Question#2: For the following class, write a JUnit test class to test the method getTotalRentPayment and whether an exception is thrown by the method setRentAmount. public class
  • 2. private private private private RentCalculator { double utilitiesCharge; int numberOfMonths; double rentAmount; java.util.Date loanDate; /** * Construct a RentCalculator with specified monthly utilities charge, number of * months, and rent amount */ COIS2240 Assignment#3 Page !2 of !3 public RentCalculator(double utilitiesCharge, int numberOfMonths, double rentAmount) { this.utilitiesCharge = utilitiesCharge; this.numberOfMonths = numberOfMonths; this.rentAmount = rentAmount; loanDate = new java.util.Date(); } /** Return annualInterestRate */
  • 3. public double getutilitiesChargee() { return utilitiesCharge; } /** Set a new monthly untility charge */ public void setutilitiesCharge(double utilitiesCharge) { this.utilitiesCharge = utilitiesCharge; } /** Return numberOfMonths */ public int getNumberOfMonths() { return numberOfMonths; } /** Set a new numberOfMonths */ public void setNumberOfMonths(int numberOfMonths) { this.numberOfMonths = numberOfMonths; } /** Return loanAmount */ public double getRentAmount() { return rentAmount; } /** Set a newRentAmount */
  • 4. public void setRentAmount(double rentAmount) throws Exception { if (rentAmount < 0) throw new Exception("Money cannot be negative"); this.rentAmount = rentAmount; } /** Find total payment */ public double getTotalRentPayment() { double totalPayment = (rentAmount + utilitiesCharge) * numberOfMonths; return totalPayment; } } /** Return loan date */ public java.util.Date getLoanDate() { return loanDate; } COIS2240 Assignment#3 Page !3 of !3 Question#3: a) Following the Observer design pattern, write a class called TenantObserver that prints a message to the tenant in its update method when setRentAmount is called in the RentCalculator class from Question#2. Modify the RentCalculator class to allow to register/ unregister observers.
  • 5. b) Apply the Singleton pattern on RentCalculator to ensure that only one RentCalculator is could be instantiated. Change what is necessary in the RentCalculator class to apply the Singleton pattern. Question#4: The List interface is defined as follows: interface List { int count(); //return the current number of elements in the list Object get(int index); //return the object at the index in the list Object first(); //return the first object in the list Object last(); //return the last object in the list boolean include(Object obj); //return true is the object in the list void append(Object obj); //append the object to the end of the list void prepend(Object obj); //insert the object to the front of the list void delete(Object obj); //remove the object from the list void deleteLast(); //remove the last element of the list void deleteFirst(); //remove the first element of the list void deleteAll(); //remove all elements of the list } (a) Write a class adapter to adapt Java ArrayList to the List interface. (b) Write a main program to test your adapters through List interface.
  • 6. (c) Same requirement as (a) and (b), but write an object adapter to adapt Java ArrayList to the List interface. For all these questions, test your code with some inputs. You have to submit the following to the blackboard: 1-Source code. 2-Screenshots of the output or the test runs. Put all the screenshots in a single word document. ************************************************
  • 7. (c) Same requirement as (a) and (b), but write an object adapter to adapt Java ArrayList to the List interface. For all these questions, test your code with some inputs. You have to submit the following to the blackboard: 1-Source code. 2-Screenshots of the output or the test runs. Put all the screenshots in a single word document. ************************************************