Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

05-22-2016 , 07:58 PM
If you feel especially lazy and it's your local machine:

# chmod -R 777 /folder

I'll never be a syadmim, that's for sure.
Programming homework and newbie help thread Quote
05-23-2016 , 07:37 AM
That's what I do when Ruby upgrades give me trouble.
Programming homework and newbie help thread Quote
05-23-2016 , 06:02 PM
I know some auto installers flip the switches for you. Can't remember exactly how one worked, but I think I had to manually change to 775 and the installer flipped over to 644. Something like that.

It wouldn't surprise me if some flip to 777 and flip back.
Programming homework and newbie help thread Quote
05-24-2016 , 12:05 AM
well, i think a long time ago when i was new to bash and was setting up my mac, I maybe used 'sudo' when I shouldn't have, and have had to fight with it ever since.

far too lazy to figure out how to properly uninstall everything
Programming homework and newbie help thread Quote
05-24-2016 , 12:40 AM
Quote:
Originally Posted by Noodle Wazlib
well, i think a long time ago when i was new to bash and was setting up my mac, I maybe used 'sudo' when I shouldn't have, and have had to fight with it ever since.

far too lazy to figure out how to properly uninstall everything
Can't figure out why something is working? sudo your way to victory ldo
Programming homework and newbie help thread Quote
05-24-2016 , 12:47 AM
that's what got me in this mess to begin with!! Now I can't update past ruby 2.3.0
Programming homework and newbie help thread Quote
05-24-2016 , 09:21 PM
Quote:
Originally Posted by Noodle Wazlib
that's what got me in this mess to begin with!! Now I can't update past ruby 2.3.0
Can you uninstall Ruby on Mac? I'm not brave enough to attempt it on my work machine.
Programming homework and newbie help thread Quote
05-24-2016 , 10:16 PM
no clue, but i can damn sure tell you how to unintentionally uninstall it from linux tho
Programming homework and newbie help thread Quote
05-28-2016 , 04:05 PM
After beginning with Python, I've just started an online class about Java. For one of my assignments, I have to debug a simple program. As far as I can tell I have done so, but when I try to run the program in NetBeans I get a message saying that there is a broken platform reference I have to fix. I have no idea what this means, and searching the internet hasn't been helpful to this point. The first assignment that I just did 5 minutes ago is literally the first time I have ever tried to use Java and my entire knowledge of it is basically from the first two chapters of my text book, so be gentle if this is a really stupid question!

If it helps, here's the code:

public class CalculateAverage {
public static void main(String[] args) {
double average = (10 + 10 + 10 + 10 + 10 + 10) / 6.0;
System.out.println("The average is: " + average);
}

}

Lines 1, 2, and 4 have a red exclamation mark next to them in NetBeans, each of which display error messages that I will also post shortened versions of in case that's helpful:
Cannot access java.lang
Cannot find symbol class string
Package system does not exist

Thanks. I've always received great help when I've come here in the past.
Programming homework and newbie help thread Quote
05-28-2016 , 04:14 PM
Have you installed the jdk yet?

I just installed IntelliJ and couldn't figure out why it wasn't working. Had never done the jdk on this computer.

Last edited by Loki; 05-28-2016 at 04:15 PM. Reason: And I've been programming Java for about 1 1/2 years
Programming homework and newbie help thread Quote
05-29-2016 , 12:56 AM
Quote:
Originally Posted by LBloom
After beginning with Python, I've just started an online class about Java. For one of my assignments, I have to debug a simple program. As far as I can tell I have done so, but when I try to run the program in NetBeans I get a message saying that there is a broken platform reference I have to fix. I have no idea what this means, and searching the internet hasn't been helpful to this point. The first assignment that I just did 5 minutes ago is literally the first time I have ever tried to use Java and my entire knowledge of it is basically from the first two chapters of my text book, so be gentle if this is a really stupid question!

If it helps, here's the code:

public class CalculateAverage {
public static void main(String[] args) {
double average = (10 + 10 + 10 + 10 + 10 + 10) / 6.0;
System.out.println("The average is: " + average);
}

}

Lines 1, 2, and 4 have a red exclamation mark next to them in NetBeans, each of which display error messages that I will also post shortened versions of in case that's helpful:
Cannot access java.lang
Cannot find symbol class string
Package system does not exist

Thanks. I've always received great help when I've come here in the past.
Are you aware of the ability to import different packages in python? Well, I imagine that's probably what you need to do here (however you do that in Java) before you're able to log anything to the cli.
Programming homework and newbie help thread Quote
05-29-2016 , 12:59 AM
Quote:
Originally Posted by Noodle Wazlib
Have you installed the jdk yet?
sounds like this
Programming homework and newbie help thread Quote
05-30-2016 , 12:07 PM
I've never used NetBeans, but I did find some hits googling "netbeans cannot access java.lang" including this advice:
Quote:
Right click the project
properties
libraries
update "Java Platform"
Nothing wrong with the program, it's going to be something along these lines.
Programming homework and newbie help thread Quote
05-31-2016 , 04:50 PM
Thanks guys, I ended up figuring it out. Turns out the problem was an intentional part of the file I downloaded. One of the "bugs" I had to fix was changing the documentation of the code. I don't think I'm putting that very precisely, but that's the gist of it.

Another beginning Java question:

One simple program I had to write for my first week of assignments was along these lines: get five numbers from a user, calculate the numbers' sums and products, and also print how many negative numbers, positive numbers, and zeroes there were. So all that was easy enough. My question regards initializing variables. So at the start of the program I had something like:
int num1;
int num2;
...
int num5;
int positive;
int negative;
int zero;

For the math aspects of the program, everything went fine. I used some if statements to determine pos/neg/zero, and incremented those variables within. For some reason, though, when the program got to the if statements, I would get a message saying that positive wasn't initialized. I was able to fix this easily enough by just putting positive = 0, negative = 0, and zero = 0 at the beginning of the program, and then it ran just fine. I just don't understand why I had to do this. I'm not at home right now but I'll post the exact code later if that would help.

Again, thanks, I can't even begin to describe how helpful this forum has been for me as I set out to learn coding.
Programming homework and newbie help thread Quote
05-31-2016 , 04:59 PM
When you declare those variables, you are just grabbing memory that is the size of an int. You don't know what is at that memory, so it wants you to initialize it. It is preventing you from assuming that memory was a zero initialized region when it wasn't and getting undefined/unexpected results.
Programming homework and newbie help thread Quote
05-31-2016 , 05:12 PM
Quote:
Originally Posted by KatoKrazy
When you declare those variables, you are just grabbing memory that is the size of an int. You don't know what is at that memory, so it wants you to initialize it. It is preventing you from assuming that memory was a zero initialized region when it wasn't and getting undefined/unexpected results.
This is true, although I'm a little surprised it doesn't settle on a reasonable default (or maybe it does, and the warning you got was because it thought you might not be aware of the default?)

Anyway my main comment is, do you see the problem you'll have if someone asks you to change your program so that it sums 100 or 1000 numbers? (Have you gotten to arrays yet?)
Programming homework and newbie help thread Quote
05-31-2016 , 05:29 PM
Arrays of ints default to zero in each one, right? (Assuming you don't give values) I don't fully remember. I know it's super easy to do it like that in Ruby but my java is leaving me
Programming homework and newbie help thread Quote
05-31-2016 , 06:51 PM
Yes, in Java arrays initialise to default values for their types. The default value for int is 0.
Programming homework and newbie help thread Quote
05-31-2016 , 08:39 PM
Quote:
Originally Posted by RustyBrooks
This is true, although I'm a little surprised it doesn't settle on a reasonable default (or maybe it does, and the warning you got was because it thought you might not be aware of the default?)

Anyway my main comment is, do you see the problem you'll have if someone asks you to change your program so that it sums 100 or 1000 numbers? (Have you gotten to arrays yet?)
To your last comment, absolutely. In Java I have not gotten to lists / arrays yet.

I think I'm starting to see why the variables like num1 were treated differently by the program than the variables like positive, negative, and zero. The variables like num1 were initialized, then given a value through user input, then used for calculations / output. The variables like positive and negative were initialized, but not given a value before I wanted to manipulate them, and so that's why it didn't work.

So I had a statement like:
if num1 > 0:
pos += 1

Which didn't work because I'm trying to use the variable pos to give itself a value, basically? I know some of my phrasing might be weird, but does the above sound roughly correct?
Programming homework and newbie help thread Quote
05-31-2016 , 09:50 PM
In Java class variables, instance variables, and array components are initialized to their default values. Local variables are not automatically initialized and must be assigned a value before they are accessed.
Programming homework and newbie help thread Quote
05-31-2016 , 11:27 PM
^ This. For your simple program, you probably declared these variables inside the main() method, in which case they are local variables (i.e., local to the main method) and need to be explicitly initialized.
Programming homework and newbie help thread Quote
06-01-2016 , 05:18 AM
Quote:
Originally Posted by LBloom
I think I'm starting to see why the variables like num1 were treated differently by the program than the variables like positive, negative, and zero. The variables like num1 were initialized, then given a value through user input, then used for calculations / output. The variables like positive and negative were initialized, but not given a value before I wanted to manipulate them, and so that's why it didn't work.

So I had a statement like:
if num1 > 0:
pos += 1

Which didn't work because I'm trying to use the variable pos to give itself a value, basically? I know some of my phrasing might be weird, but does the above sound roughly correct?
You got parts of it right. The terminology, though, is wrong.
When you say "initialized" you mean "declared" - understanding the difference is important. So try to get your head around the terms to start using them correctly.

Declaring a normal variable does not initialise it. So the value is unknown - whatever happened to be in the given block of memory at the time will be interpreted as the type of variable.
Java will warn you when you try to read from such a variable.
Setting the variable for the first time initialises it.

If you use a statement like
Code:
pos += 1
it does not "try to give itself a value" - whatever you mean by that. It simply is a short-hand version of this:
Code:
pos = pos + 1
So it needs to read the value of pos, then add 1 to that, then set pos to the result of that addition.
With pos not having been set (initialised), Java will warn you.
Programming homework and newbie help thread Quote
06-08-2016 , 09:36 PM
Question about Java:

I've just learned about a new way to return Boolean values from expressions, and I want to make sure I'm understanding it. So if I want to return a Boolean, I can go through some if / else if / else statements, or I can just do something like:

Public Boolean three (x, y)
return (x == 3) || (y == 3);

And if either x or y is 3, it will return true. So am I right in interpreting this as: program checks to see if x equals 3, returns true if it does and, if it doesn't, checks to see if y equals 3 and returns true if it does, and then false if neither are true? Basically I'm asking if I should be interpreting this as simply short hand for the if / elif / else statements I'm familiar with.

Also, is it good practice to use this technique? It seems like a real time saver, but at the expense of making it less obvious what exactly is happening in the code. Of course I could see how this objection could become meaningless in bigger programs that are inherently more complicated.
Programming homework and newbie help thread Quote
06-08-2016 , 09:41 PM
Yes, your interpretation is correct. And yes, it's the right thing to do. If you can express something in a short boolean expression that is much better than a more complicated set of if/then/else statements. I don't think it makes it less obvious - actually I think it makes it more obvious.
Programming homework and newbie help thread Quote
06-08-2016 , 09:48 PM
Thanks. I'm still fairly new to programming so I think my "it makes it more explicit" point of view comes from it just including English words. Thanks again and now I have to take a break from thinking about programming because I keep expecting quotation marks to auto pair up.
Programming homework and newbie help thread Quote

      
m