This topic has been locked!|
and she's STILL hawt
|
is this a contest now?
maybe i'll work on my code ;o ![]() ![]() ![]() ![]() ![]() ![]() Things to know: The squeaky wheel gets the grease
Currently working on: DLDB (needs a major ass kicking for not listening to meh) Next in line: Mod night, Wiki, ?, ? I has sexy plans. Recently completed: Message center +some | forum activity | sessions, login |
|
and she's STILL hawt
|
wtf? no arrays?
who gives programming homework with boundaries? ![]() ![]() ![]() ![]() ![]() ![]() Things to know: The squeaky wheel gets the grease
Currently working on: DLDB (needs a major ass kicking for not listening to meh) Next in line: Mod night, Wiki, ?, ? I has sexy plans. Recently completed: Message center +some | forum activity | sessions, login |
|
I paid eleven minerals for THIS?
|
People who haven't been taught them yet
But.. I have never heard of a class that teaches recursion before arrays. In the book I'm stuck with right now, arrays/ArrayList is chapter 7 and recursion is chapter 10. ![]() ![]() ![]() ![]() ![]() ![]() "Three can keep a secret, if two are dead." -Benjamin Franklin
"Had, having, and in quest to have, extreme; A bliss in proof, and proved, a very woe; Before, a joy proposed; behind, a dream. All this the world well knows; yet none knows well To shun the heaven that leads men to this hell." -William Shakespeare |
|
we were taught arrays in grade 11 this is grade 12 class, I had the grade 11 class last semester (to catch up) and now im in the grade 12 class, the teacher wasn't present yesterday but the students said that we arn't allowed to use arrays because apparently he hasn't re-taught arrays to us yet, however I beg to differ because on the first three days we did review and there were array questions, so I don't think that no arrays is actually a requirement, it doesn't say it on the rubric so I think that they should be okay, he can't exactly tell me that I don't know arrays, because I clearly know arrays... at most he can take maybe 1 - 2 marks away but most of the marks are in presentation, documentation, file location etc...
|
|
I paid eleven minerals for THIS?
|
If you flatly aren't allowed to use arrays, you can be really clever and write the equivalent of the ArrayList class yourself
![]() ![]() ![]() ![]() ![]() ![]() "Three can keep a secret, if two are dead." -Benjamin Franklin
"Had, having, and in quest to have, extreme; A bliss in proof, and proved, a very woe; Before, a joy proposed; behind, a dream. All this the world well knows; yet none knows well To shun the heaven that leads men to this hell." -William Shakespeare |
|
I paid eleven minerals for THIS?
|
I meant write your own class to emulate ArrayList, but that is a prohibitively large amount of work and you would need to know generic classes
![]() ![]() ![]() ![]() ![]() ![]() "Three can keep a secret, if two are dead." -Benjamin Franklin
"Had, having, and in quest to have, extreme; A bliss in proof, and proved, a very woe; Before, a joy proposed; behind, a dream. All this the world well knows; yet none knows well To shun the heaven that leads men to this hell." -William Shakespeare |
|
Code /** * McFuPucks is a java class that decides whether the user's input amount of pucks is obtainable via boxes of 6,9 and/or 20 * * Rowan Collins * Version 1.0 */ import java.util.Scanner; public class McFuPucks { //start of McFuPucks class public static void main(String[] args) { //start of main method /** * Main acquires the users desired pucks and initiates the recurring method "buyable" */ Scanner input = new Scanner(System.in); //input is the scanner object used to obtain user input System.out.print("Input the number of McFuPucks you'd like to purchase: "); int i = input.nextInt(); //i is the desired amount of McFuPucks int[] boxSizes = {6,9,20}; //boxSizes is the different variety of box sizes if(buyable(i, boxSizes) == true) { System.out.println("This is buyable"); } else { System.out.println("This is not buyable"); } } //end of main method private static boolean buyable(int x, int[] array) { //start of buyable method /** * buyable is a method that reccurs in order to find if the desired amount of pucks is obtainable using a variety of boxsizes * * @param int x is the desired amount of McFuPucks * @param int[] array is the different boxsizes * * @return true or false depending on whether or not it is purchasable */ int n = 0; //n is the temporary value used in comparison against x (target value) to decide if n is too low, too high or 'buyable' while (true) { //start of recursive loop if (n == x) { return true; } if (array.length > 1) { int[] shortArray = new int[array.length - 1]; for (int i = 1; i < array.length; i++) { shortArray[i - 1] = array[i]; } if (buyable(x - n, shortArray)) { return true; } } n += array[0]; if (n > x) { return false; } } //end of recursive loop } //end of buyable method } //end of McFuPucks class |
|
What the hell is
Code if(buyable(i, boxSizes) == true)I think you meant Code if(buyable(i, boxSizes)) My point: be more elegant! Well, at least DTBK used what I suggested (in a much uglier way). -__- Also, explain your algorithm in your comments. It's not whether or not you can understand it, it's whether or not someone who doesn't want to look at the code can understand it in two minutes or less. .. Unless you have a really long algorithm. ![]() ![]() ![]() ![]() ![]() ![]() |
|
I needed it so that instead of saying true or false it said "This is buyable" or "This is not buyable" so I had to do true vs false, unless what you're saying outputs the same result just without the == true
I just need to make sure that the comments I do have make sense and are correct so that my teacher wont be like "wtf iz dis nuub talking about" |
|
and she's STILL hawt
|
if(buyable()) and if(buyable() == TRUE) are the exact same thing... as long as buyable only returns true or false.
Like in my PHP code, I could have put if (count($valid) == TRUE) (i do believe all non-zeros are "TRUE" anyways ;o) or if (count($valid) > 0)... but it was unnecesary ;o ![]() ![]() ![]() ![]() ![]() ![]() Things to know: The squeaky wheel gets the grease
Currently working on: DLDB (needs a major ass kicking for not listening to meh) Next in line: Mod night, Wiki, ?, ? I has sexy plans. Recently completed: Message center +some | forum activity | sessions, login |
|
I paid eleven minerals for THIS?
|
Shocko just copied my '== true'. I think I was under the influence of something when I wrote that
if (a) {} and if (a == true) {} are entirely synonymous. Since Java variables are strictly delineated by type, there is no === operator. ![]() ![]() ![]() ![]() ![]() ![]() "Three can keep a secret, if two are dead." -Benjamin Franklin
"Had, having, and in quest to have, extreme; A bliss in proof, and proved, a very woe; Before, a joy proposed; behind, a dream. All this the world well knows; yet none knows well To shun the heaven that leads men to this hell." -William Shakespeare |
|
and she's STILL hawt
|
Sometimes the type thing in php annoys me.
Shocko, wtf comments. { //start of McFuPucks class is that really necessary? ;o I need to do something about tab conversion inside code blocks... ![]() ![]() ![]() ![]() ![]() ![]() Things to know: The squeaky wheel gets the grease
Currently working on: DLDB (needs a major ass kicking for not listening to meh) Next in line: Mod night, Wiki, ?, ? I has sexy plans. Recently completed: Message center +some | forum activity | sessions, login |
This topic has been locked!