-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TOPIC 1: Object-Oriented Programming - MASTER ISSUE #1
Comments
I'm Alyssa, my favourite food is sushi 🍣 , and I would like to learn how to implement machine learning using TensorFlow! |
I'm Allen, my favourite food is fried chicken and poutine, and I would like to learn how to program a 2D platformer game. |
I'm Kevin, my favourite food is ramen, and I would like to learn how to create a simple A.I. |
@AllenZoo @Kevin-Tan25 @RuthlessDebugMachine if you have any questions about assignments, labs, technical issues or general course material for topic 1, you can comment them on this issue thread :) |
Hi Alyssa, I am Howard. I just met a problem. If I want to track 40 previous random number seeds and save them and still updating them while the program is running, can you briefly tell me what the method would be? like the type, brief structure of implements etc. I remember that we seemed have gone over this in class but I did not actually catch on well, thanks! |
Hi @RuthlessDebugMachine, just to clarify, is there a specific way you want to create these random seeds? And as you are updating them, are you simply calling the same random function again to retrieve new values to save to these variables? |
@alyeffy ,yes, by using Math.Random() method, and it is calling the same method again and again. |
@RuthlessDebugMachine so since the method is constantly updating values and not returning anything, it sounds like it is a mutator. A simple implementation for this could be to create an empty array of doubles of length 40, then call the Math.random() function 40 times using a for loop, assigning each value to an index in the array. This way, you could access each specific number in the list when needed using standard array access. You could even use a specific collection rather than an array, depending on your needs. However, you need to specify how frequently you want to update them while the program is running as well. In other words, it needs a condition (e.g. a certain amount of time has passed) that has to be met before the seeds are updated. Depending on the condition, an observer/event listener design pattern might be useful for this as well. Design patterns and Collections are not part of the AP subset, so I have a simple implementation below: // I am assuming that your class has the following data fields:
public double[] seeds; // an array of doubles storing the values of the seeds
public boolean needsUpdate; // a boolean indicating whether or not the seeds need to be updated
// Creates a class object with an empty seeds array and updates them right away.
public ClassName() {
this.seeds = new double[40]; // initializes an empty array of doubles of length 40
updateSeeds(); // updates the seeds
}
// Updates the seeds in the seeds data field and then sets needsUpdate to false
public void updateSeeds() {
for (int i = 0; i < this.seeds.length(); i++) {
this.seeds[i] = Math.random(); // replaces existing seed values with new ones
}
this.needsUpdate = false; // sets the update flag to false since seeds were just updated
}
// Checks whether of not the seeds need to be updated based on the condition
public void checkUpdate() {
if (condition) // depending on your condition, this method might have parameters that need to be taken into account for the condition
this.needsUpdate = true;
}
public void main() { // remember that the main function is always run first
ClassName x = new ClassName(); // instantiation of the class
while (x.getUpdateFlag() == false) { // updateSeeds always starts as false because of the constructor
x.checkUpdate(); // changes needsUpdate to true if update condition is met
if (x.getUpdateFlag()) // if needsUpdate is true (I left the self-explanatory implementation for this getter out)
x.updateSeeds(); // updates the seeds and sets needsUpdate to false again
// end of while loop body, and since needsUpdate is guaranteed to be false by the end, an infinite loop ensues
// this ensures that the seeds are constantly being checked if they need to be updated and are updated when they do
}
} |
LAST UPDATED: 12 OCT 2018
General inquiries and updates relating to Topic 1 will be updated on this issue.
LESSON 01 - 05/10/2018
Intro to the Java language, Object-Oriented Programs, and Basic Program Design Approaches
PREP:
ASSIGNMENTS:
LAB:
LESSON 02 - 16/10/2018
Elementary Java Syntax, Data Representation, and Bit Conversion
PREP:
ASSIGNMENTS:
LAB:
LESSON 03 - 23/10/2018
Inheritance and Polymorphism
PREP:
ASSIGNMENTS:
Card.java
(solution) class in our first lab last lesson, complete theisEmpty
andsize
accessor methods. HINT: You will need to use one of the methods from the AP Exam Java Quick ReferenceLAB:
LESSON 04 - 30/10/2018
Abstract Classes, Interfaces, and UML Diagrams
PREP:
ASSIGNMENTS:
LAB:
The text was updated successfully, but these errors were encountered: