Download presentation
Presentation is loading. Please wait.
1
Recitation 3 September 9, 2011 Wade Gobel
2
As you come in… Please sit next to someone with whom you would like to collaborate during this recitation Take a look at assignment 3 on the course webpage (new policy: indicate extra credit in comments) Mac users If you’re having problems with Object Editor, download oeall3.jar from the course webpage (under “Downloads”)
3
Today’s Goals: Gain experience using ObjectEditor on a class with properties Maintain state in a class
4
Notes: Please pay attention during instruction portion of the Recitation (hopefully only about 15 minutes) No surfing, No texting, No typing! Then you are free to work on the problem for the rest of the recitation time You must work in pairs for today’s recitation
5
State Example Height Weight BMI public class ABMISpreadsheet {
double height; public double getHeight() { return height; } public void setHeight(double newHeight) { height = newHeight; double weight; public double getWeight() { return weight; public void setWeight(double newWeight) { weight = newWeight; public double getBMI() { return weight/(height*height); … Height Weight BMI
6
State Example import bus.uigen.ObjectEditor;
public class ABMISpreadsheet { //Properties declared: Weight (editable), Height (editable), BMI (read-only) … public static void main(String[] args) { ABMISpreadsheet bmiSpreadsheet = new ABMISpreadsheet(); bmiSpreadsheet.setHeight(1.77); bmiSpreadsheet.setWeight(71.0); System.out.println(“Height: ” + bmiSpreadsheet.getHeight()); System.out.println(“Weight: ” + bmiSpreadsheet.getWeight()); System.out.println(“BMI:” + bmiSpreadsheet.getBMI()); ObjectEditor.edit(bmiSpreadsheet); } Console: Height: 1.77 Weight: 71.0 BMI:
7
Properties Height - Editable Weight - Editable BMI – Read-Only
public class ABMISpreadsheet { double height; public double getHeight() { return height; } public void setHeight(double newHeight) { height = newHeight; double weight; public double getWeight() { return weight; public void setWeight(double newWeight) { weight = newWeight; public double getBMI() { return weight/(height*height); Height - Editable Weight - Editable BMI – Read-Only & Dependent
8
Class Specification: AStatefulFactorialCalculator
Create a class called AStatefulFactorialCalculator Class should contain: An editable property called number A read-only property called numberFactorial dependent on number (equal to the factorial of that number) Create a class called Recitation3 that contains the main method Main method must: Accept only one program argument Create an instance of AStatefulFactorialCalculator Set the property number to the input argument (set) Output both properties to the console (get) Use ObjectEditor to edit this instance InputString must be initialized, otherwise a NullPointerException will occur when ObjectEditor calls getInputString the first time.
9
Setup and Submission When finished, demo your code to a TA
Please follow the instructions on the course website to set up your project When finished, demo your code to a TA
10
Setting up Object Editor
Recall from lecture: Jar must be on build path (problems?) Import statement necessary: import bus.uigen.ObjectEditor; Must call ObjectEditor.edit(yourObject); Added for reference purposes.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.