These series of videos have been out there for over 11 years and I never knew they existed. I've been programming professionally for about 5 years now, and even though I know most of the stuff he talks about, I can't stop watching these videos just because of the simplistic way in which he explains things, hoping that I could pick one or two things from him that I haven't learnt yet. Undoubtedly the best lecture series I've ever watched. Thank you so much Professor Sahami or Mehran as he'd like to be referred as.
I hope someone read all this comments and tell to Mehran he is the best at what he does!! He makes you want to learn more and more. I wish all teachers where like him.
Great class! Thank you to the administrators, the faculty, but above all, thank the students at Stanford who make this possible. You're wonderful people for sharing education with the world.
i'm a classroom training is best kinda person... Mehran changed my opinion... I can stick to my chair for more than 2 hours... man he is THE MASTER!!! Long live his lectures.. i spent 27 hours already on his lectures... Bravo Bravo!!!
Day 1 - Finished watching lectures 1 through 7 - Got Eclipse, sun-java6-sdk, Karel, and acm.jar set-up - Read Chapter 1 of The Art and Science of Java (early-draft, it was free, hopefully legal, I found it just Google'ing the title) Day2-3 -Gonna hurdle through assignment 1 - 7 and read some more.
Just a small note for those following the book as well: In Chapter 4.3 we're introduced to the ternary operator ?: but the explanation is quite confusing (which surprised me because everything up until that point was perfectly disclosed). If you want to understand the ?: operator in less than one minute please do yourselves a favor and follow this link: stackoverflow.com/questions/10336899/java-what-is-a-question-mark-and-colon-within-the-parentheses-of-a-prin The 1st. answer nails it perfectly. The book lacks the alternate order to the if else statement: boolean statement ? true result : false result;
New to Java..but this is all example right? I’ve learned that you have to start with public static void main[String] args) Great instructor! Just hard to run the terminal with his examples
Don't forget to review often when you go back you see things in a different way some of it seems easier than the first run and other stuff clicks too; it's always smart to go back and review. Pushing ahead is good but you need to understand those fundamentals first, push review push review. My advice to a comment from two years ago :/
It must be awesome for students who is going to take this class next semester at Stanford to watch this whole class in advance. I wish I could do that:(
the 4 dislikers were students who got always got hit by rogue candies. ;) but on a side note, these lectures are making things so much easier. I'm actually learning more here than from my college instructors. You the man Sahami!!
A parameter is like a variable that you got from somewhere else. Think about that CD player the professor showed. The player comes with electronics and stuff. That's equivalent to having internally declared variables, right? Then, you stick a CD (a parameter) in. Depending on what the CD has written on it (what the variable points to), different things will happen. Params behave like vars, but they're applicable in more than one situation.
Does anyone know if this information is still relevant for java in 2018? I noticed that some things seem slightly different, although the similarities seem to much overpower the differences, will I just be confusing myself by learning about an older version of java? Coming from a beginner who is just starting to grasp the basics of java.
Hey i am also new(and i know the comment is from 6 years ago) but this will give me a good foundation right? And later on can learn what the new version do?( well this is my plan, can you pls help me? If i should do this or not?)
I finally got the checkerboard to print, albeit with an error warning. I noticed that the acm imports were in karel.jar. So I altered the checkerboardkarel so it was similar to checkerboard.java
2:05.while loop/loop and a half 3:33.sentinel 9:55. for vs ,loop 11:10. checker board 19:00. little smart thing and checker board 22:00. methods in java 30:12. creating methods in java 34:00. return statement/expression 35:00. example of a method 40:42. factorial example 46:46. returning objects 49:24. how to add in to run method
The default color of a graphics object (sq) is black. He calls setFilled() without ever calling setColor(), so it will be black until he chooses to change it.
in the factorial example. In the run method in the for loop it says factorial(i). Could you have put factorial + i? Or is the correct way factorial(i)? Also when you call a method, is factorial a special case where you can put arguments in the parentheses when you call the factorial method?
Hey guys, if interested there is another CS106A from Stanford! (web.stanford.edu/class/cs106a/) It's kinda the same, but there is a lot of information there!
***** Thanx a lot for the link ... But I don't understand, what is this ? Is this some other class ? Or just additional material ? What's the difference between the two ?
i'm not done yet doing the checkerboard prog myself. I'm kinda leap without looking person... alright! Ideally X should be assigned the value of i in the for loop and Y should be assigned the value of j in the for loop, if we are printing Square boxes row wise but this program looks like we are printing it column wise... like x1y1 , x2y1, x3y1.... and then after the column completes. y goes for an increment which means the focus goes tothe second column... i'm fine with it otherwise.
Best teacher ever, but unfortunately alot of outdated things. For the loop and a half thing you only need a do{} while(); loop. public class Add { public static void main(String[] args) { int total = 0; int val; do{ Scanner reader = new Scanner(System.in); System.out.println("Enter val:"); val = reader.nextInt(); total += val; }while (val !=0); System.out.println("your total is " + total); } } no constant SENTINEL, no break needed. works perfectly fine. It also happens, theres no more ConsoleProgram Class. Instead you need to create an object of a class that can read user input. For instance Scanner. stackoverflow.com/questions/5287538/how-to-get-basic-user-input-for-java btw. 6 weeks ago, i knew as much about programming as my grandmother. Learning all online on youtube and through pdf.s. Hell of a ride.
No unfortunately. What he did still works. There is no need for a sentinel value, but the sentinel value is used as good practice, that's what that was. And you need to download the acm.jar file to use the console program you're supposed to import it into eclipse. The scanner thing is not new it's old. Java doesn't change. He is using the readint(); method because they don't have to worry about the syntax of creating a scanner and the subtleties that go with it. That's why he uses public void run() {} instead of public static void main(String [] args) {} because he hasn't introduced methods or arrays yet.
Trying to! haha... Need more insight... hence further lessons followed by the C++ lessons :) I intend to write a complete program of some kind at some point here soon. Just need the basics.
You should not put "factorial + i" because it will treat "factorial" as a variable adding "i". To define it as a method you must put "()" at its end like this: "factorial()". Also in this case the factorial method must take in an integer(argument) as its parameter in order to run, so the "i" in "factorial(i)" must be there. (The "i" here is referring to the one of the for-loop in the run(), not the "i" in the factorial method!)
Trying to figure out how to run checkerboard.java in Stanford's Eclipse. Apparently I am missing the part that says how to create projects and classes. Or, is the project already in Stanford's version of Eclipse?
I can't see where the value of "n" is defined in the factorial program, as "i " has to be measured against it. It seems that a part of the code is missing. Surely "n" must be increasing by 1 every time before the factorial program can work on it.
instead of having the (int n) in the parameters for the private function, could you also leave the parameters empty and define a variable in the method itself?
hey i took care of it,so what u need to do is download acm..and then import it in ur project...if u need details ill expalin it,its no biggy,trust me :-)
@papawilk check out Sun's web site I know at one time they had testing materials on there. Otherwise a certification book would have a practice test in it. There is self test software you can get as well. I'd check with a teacher on it , I got mine for free from a class I took so not sure if there is a cost with it.
QUestion: if all calculations with pixels are done with ints why do the methods, getHeight(), getWidth(), and label.getAscent(), label.getWidth() return doubles?
Anyone know where I can find the class package to download they use so I can import it into Eclipse? they are using import acm.program.Console and in this example for readInt function it's using acm.program.console eclipse doesn't have the acm libraries by default and I can't find any way to download these libraries if someone can help me out send me a private message on youtube I'd greatly appreciate it
hey i need help,i just saw this lecture and wanteed to run this program on my computer but the thing is that i am workin in eclipse so it always says that this GRect cannot be resolved to a type,so can u tell me which class should i import? i would be really grateful :-)
this is a lifesaver. my teacher doesnt explain anything, the book sucks and he doesnt tell us what is covered on the exams! it might f up my gpa. a 4 credit class! if i get less than a b im screwed. transfer school requires a 3.5 !#!$
oh hi..it took a while for someone to reply,yes i know about that,i did get that library and stuff but the thing is i was typing java.acm.graphics, not acm.graphics without that java infront...i hate stupid mistakes,but thank you anyway,
I tried duplicating his checkerboard example, and it either fills all the squares or unfills all the squares. Anyone know if something has changed in the newest Java to cause this?
Having limited usage with Wild Blue Satellite Internet restricts me from watching them all... It's B.S. 250mb DL/Day these are 150-200mb... Damn good lectures though! I'd hate to be in the class getting beamed with candies though... | ! | : )
for getting user input, I do not see why he doesnt have to create a Scanner instance. Using readDataType seems way more simple, but still going to use a Scanner
You need to import acm.graphics.*; and import acm.program.*; You will find the whole program here -> see.stanford(dot)edu/materials/icspmcs106a/12-control-statements.pdf
i have problem, i am trying to rewrite CheckerBoard program as video show. in the last line, the "add(sq)", my Eclipse remind me:"The method add(Component) in the type Container is not applicable for the arguments (GRect)". rest of my code are totally same as video. anyone could teach me how to fix it?
Did you import the graphics program? Your code should look like this... /* File: CheckerBoard.java * * This is a graphics program that * draws a checker board */ import acm.program.*; import acm.graphics.*; public class CheckerBoard extends GraphicsProgram{ //number of rows private static final int NROWS = 8; //number of columns private static int NCOLUMNS = 8; //runs the program public void run(){ int sqSize = getHeight() / NROWS; for( int i = 0; i < NROWS; i++){ for(int j = 0; j < NCOLUMNS; j++){ int x = j * sqSize; int y = i * sqSize; GRect sq = new GRect(x, y, sqSize, sqSize); sq.setFilled(((i + j) % 2) != 0); add(sq); } } } }
Craig Walker i have the same problem but i do as u say and nothing happened, this is my code: import acm.program.*; import acm.graphics.*; import java.awt.*; public class theRobotFace extends ConsoleProgram { private static final double HEAD_WIDTH = 1; private static final double HEAD_HEIGHT = 3; private static final double EYE_RADIUS = 2; private static final double MOUTH_WIDTH = 2; private static final double MOUTH_HEIGHT = 2; public void run() { double placeX,placeY; placeX = (getWidth()/2)-(HEAD_WIDTH/2); placeY = (getHeight()/2)-(HEAD_HEIGHT/2); drawRect(placeX,placeY,HEAD_WIDTH,HEAD_HEIGHT,Color.gray);
} private void drawRect(double x,double y,double width,double height, Color color){ GRect rect = new GRect(x,y,width,height); rect.setFilled(true); rect.setFillColor(color); add(rect); } }
I'm pretty new to java as well, but I'll try to help you the best I can. 1. Your class should be capitalized. 2. You shouldn't be extending Console Program when working with Graphics. 3. The parameters for your robot are way too small. The Width of your head is only 1 pixel. Play around with different numbers until you get the size of rectangle you want.
Yeah that is right, local variable shoulde be in the place of static variable in this case, confused with c/c++ (static variable // dynamic variable), take this Candy 🍬 .
+The gamer 49:55 -- r is radius in order to make a circle you need a point and a radius. At the end he calls his method passes (10,10,2,Color.red) as arguments to his method --- After that , what happens is the values he passed in are passed INSIDE the braces to the GOval object's parameters so that it can make a new GOval and then set it's properties and return the variable circle back to the program at the same spot that called the filled circle function.PS---Don't let the words parameter and argument confuse you----there the same thing ---they just say parameter when you create a method and argument when you "call" a method --- either way its the stuff in inside the parentheses. Good LUck and Thank you Professor Mehran
@6:40, more or less. Isn't the "break" instruction just like the infamous "goto" that gave rise to "spaghetti code", so many years ago and which "structured programming" was invented to avoid??? Personnaly, I think the first solution to this problem was better. Even if it meant "repeating" the same instruction twice...
+Joseph Edm It depends on how big the graphics window is when your program runs, and changes if you resize the window. You can display the value of getHeight() on the screen by sending it to a GLabel object: //code import acm.program.*; import acm.graphics.*; public class foo extends GraphicsProgram{ public void run(){ GLabel lab = new GLabel(String.valueOf(getHeight()),20,20); add(lab); } }
+Joseph Edm If you change the constant NROWS, the number of rectangles (or rows) will change but the screen height stays the same. Therefore, you need to know the screen height to get the height of the rectangle. You have to specify the height of the rectangle to create it.
This man is programming rockstar! I love him! If every teacher teach like him the world should be the better place :D
I wish I had better understood the what the term "Good education" meant when I was younger. After seeing this professor, now I understand.
These series of videos have been out there for over 11 years and I never knew they existed. I've been programming professionally for about 5 years now, and even though I know most of the stuff he talks about, I can't stop watching these videos just because of the simplistic way in which he explains things, hoping that I could pick one or two things from him that I haven't learnt yet. Undoubtedly the best lecture series I've ever watched. Thank you so much Professor Sahami or Mehran as he'd like to be referred as.
@arpan Kathmandu, Nepal
@arpan Convergetree Technologies
This man is simply awesome! Teaching with so much energy throughout!!
RESPECT Professor Mehran Sahami !
I hope someone read all this comments and tell to Mehran he is the best at what he does!! He makes you want to learn more and more. I wish all teachers where like him.
25:44 I like that analogy about comparing functions-as-objects with a CD Player
2017, watching 360p lectures. 10/10, would do again
It's 480p It's next gen ( ͡° ͜ʖ ͡°)
Hello from 2024, still worth it!
Best lecture on video I have ever seen. If they ever tape my classes, I hope to emulate Sahami's energy and engagement.
Prof. Sahami is the Mr. Rogers of Computer Science.
Can anyone imagine Professor Sahami sitting in a room silently working on code for 8 hours straight?
lol
LoL and eating chocolats :p
and singing "Do todo todo" :D
@@msharno 😂😂😆
@@msharno 🤣🤣
Great class! Thank you to the administrators, the faculty, but above all, thank the students at Stanford who make this possible. You're wonderful people for sharing education with the world.
It's like he never takes a breath.
i'm a classroom training is best kinda person... Mehran changed my opinion... I can stick to my chair for more than 2 hours... man he is THE MASTER!!! Long live his lectures.. i spent 27 hours already on his lectures... Bravo Bravo!!!
Stanford and Mr.Sahami, thanks for bringing it to us. Great teacher, som useful material.
its getting harder.. loving the tectures...
Its so easy to absorb what he was teaching its amazing.
Wow! Just decided to watch this for time pass. Insane lecture. Loved it. -from India
I already thought Mehran was awesome, but then he goes and brings in AiC and becomes the greatest professor of all time.
Finally, factorial problem solved without recursion presented into an official course...
truly inspirational course.
2021, watching Mehran lectures over and over again
I went to Stanford back in the dark ages before desktop computers were invented and it's great how much this reminds me of home.
This brings back memories... The good old days
Well this one escalated quickly ... considerably harder than Lecture 6 ! Need to watch it a couple of more times !
+Hiken Ace Keep it up man, I am watching this one my third time.
+Hiken Ace Same here, man... same here...
Day 1
- Finished watching lectures 1 through 7
- Got Eclipse, sun-java6-sdk, Karel, and acm.jar set-up
- Read Chapter 1 of The Art and Science of Java (early-draft, it was free, hopefully legal, I found it just Google'ing the title)
Day2-3
-Gonna hurdle through assignment 1 - 7 and read some more.
Just a small note for those following the book as well: In Chapter 4.3 we're introduced to the ternary operator ?: but the explanation is quite confusing (which surprised me because everything up until that point was perfectly disclosed). If you want to understand the ?: operator in less than one minute please do yourselves a favor and follow this link: stackoverflow.com/questions/10336899/java-what-is-a-question-mark-and-colon-within-the-parentheses-of-a-prin
The 1st. answer nails it perfectly. The book lacks the alternate order to the if else statement:
boolean statement ? true result : false result;
I'm really starting to appreciate the fact that I am learning all this in highschool. I'm learning University level programming in Grade 11.
New to Java..but this is all example right? I’ve learned that you have to start with public static void main[String] args)
Great instructor! Just hard to run the terminal with his examples
Notice how the viewership drops with each class. 147K views for Lecture 7, 120K views for Lecture 8, 70K for Lecture 12.... etc.
It's usually the case for a lot of series on UA-cam. The first video gets a lot of views, and it decreases from there.
Jesse Hello Nope it's not, it's more like the case for a lot of students in College ... Drop outs and stuff!
This is the part where I'm kind of lost but push myself through
keep pushing brother
Thanks man. I needed that.
Don't forget to review often when you go back you see things in a different way some of it seems easier than the first run and other stuff clicks too; it's always smart to go back and review. Pushing ahead is good but you need to understand those fundamentals first, push review push review. My advice to a comment from two years ago :/
Great series, but an HD version could make parts of the lecture much more legible.
It must be awesome for students who is going to take this class next semester at Stanford to watch this whole class in advance. I wish I could do that:(
the 4 dislikers were students who got always got hit by rogue candies. ;)
but on a side note, these lectures are making things so much easier. I'm actually learning more here than from my college instructors. You the man Sahami!!
A parameter is like a variable that you got from somewhere else. Think about that CD player the professor showed. The player comes with electronics and stuff. That's equivalent to having internally declared variables, right? Then, you stick a CD (a parameter) in. Depending on what the CD has written on it (what the variable points to), different things will happen.
Params behave like vars, but they're applicable in more than one situation.
you have to get the acm library first, then import acm.graphics*; and import acm.program.*;
associate the library with your project first.
This video explains polymorphism EXREMELY well
This guy is a genius!
@PapaWilk go to Stanford cs106a website they have assignment for this lectures.
Does anyone know if this information is still relevant for java in 2018? I noticed that some things seem slightly different, although the similarities seem to much overpower the differences, will I just be confusing myself by learning about an older version of java? Coming from a beginner who is just starting to grasp the basics of java.
Hey i am also new(and i know the comment is from 6 years ago) but this will give me a good foundation right? And later on can learn what the new version do?( well this is my plan, can you pls help me? If i should do this or not?)
damn those snacks. I can't focus the lecture!:)) I want one too!!
I finally got the checkerboard to print, albeit with an error warning. I noticed that the acm imports were in karel.jar. So I altered the checkerboardkarel so it was similar to checkerboard.java
2:05.while loop/loop and a half
3:33.sentinel
9:55. for vs ,loop
11:10. checker board
19:00. little smart thing and checker board
22:00. methods in java
30:12. creating methods in java
34:00. return statement/expression
35:00. example of a method
40:42. factorial example
46:46. returning objects
49:24. how to add in to run method
The default color of a graphics object (sq) is black. He calls setFilled() without ever calling setColor(), so it will be black until he chooses to change it.
@Myshcan No, you should write your own new class.
Alice in Chains? man Mehran just gets more awesome every lecture
in the factorial example. In the run method in the for loop it says factorial(i). Could you have put factorial + i? Or is the correct way factorial(i)? Also when you call a method, is factorial a special case where you can put arguments in the parentheses when you call the factorial method?
Hey guys, if interested there is another CS106A from Stanford! (web.stanford.edu/class/cs106a/)
It's kinda the same, but there is a lot of information there!
***** Unfortunately all materials are locked. How did you get access to course materials?
IlyaHarri It was available until march... Try this one: web.stanford.edu/class/archive/cs/cs106a/cs106a.1134/lecture.html
***** Thanks a lot!!!
:)
***** Thanx a lot for the link ... But I don't understand, what is this ? Is this some other class ? Or just additional material ? What's the difference between the two ?
at 04:55 a much better way to do that would be to use a "do while" loop. It's just so much easier that way.
In 7 lectures talking at the speed of sound, I have not seen this guy take one sip of water. What a machine
i'm not done yet doing the checkerboard prog myself. I'm kinda leap without looking person...
alright!
Ideally X should be assigned the value of i in the for loop and Y should be assigned the value of j in the for loop, if we are printing Square boxes row wise but this program looks like we are printing it column wise... like x1y1 , x2y1, x3y1.... and then after the column completes. y goes for an increment which means the focus goes tothe second column... i'm fine with it otherwise.
Best teacher ever, but unfortunately alot of outdated things. For the loop and a half thing you only need a do{} while(); loop.
public class Add {
public static void main(String[] args) {
int total = 0;
int val;
do{
Scanner reader = new Scanner(System.in);
System.out.println("Enter val:");
val = reader.nextInt();
total += val;
}while (val !=0);
System.out.println("your total is " + total);
}
}
no constant SENTINEL, no break needed. works perfectly fine.
It also happens, theres no more ConsoleProgram Class. Instead you need to create an object of a class that can read user input. For instance Scanner.
stackoverflow.com/questions/5287538/how-to-get-basic-user-input-for-java
btw. 6 weeks ago, i knew as much about programming as my grandmother. Learning all online on youtube and through pdf.s. Hell of a ride.
No unfortunately. What he did still works. There is no need for a sentinel value, but the sentinel value is used as good practice, that's what that was. And you need to download the acm.jar file to use the console program you're supposed to import it into eclipse. The scanner thing is not new it's old. Java doesn't change. He is using the readint(); method because they don't have to worry about the syntax of creating a scanner and the subtleties that go with it. That's why he uses public void run() {} instead of public static void main(String [] args) {} because he hasn't introduced methods or arrays yet.
Well, the video is 9 years old
Maybe it wasn't outdated then
n is defined as a parameter in fractional(int n) method
oneTnx for the Lecture n one more for Apocalyptica
So cool
not sure which lecture to start at as I already learned Java...just looking for some reinforcement :P
Trying to! haha... Need more insight... hence further lessons followed by the C++ lessons :) I intend to write a complete program of some kind at some point here soon. Just need the basics.
You should not put "factorial + i" because it will treat "factorial" as a variable adding "i". To define it as a method you must put "()" at its end like this: "factorial()". Also in this case the factorial method must take in an integer(argument) as its parameter in order to run, so the "i" in "factorial(i)" must be there. (The "i" here is referring to the one of the for-loop in the run(), not the "i" in the factorial method!)
Trying to figure out how to run checkerboard.java in Stanford's Eclipse. Apparently I am missing the part that says how to create projects and classes. Or, is the project already in Stanford's version of Eclipse?
thanks! all working now :)
I can't see where the value of "n" is defined in the factorial program, as "i " has to be measured against it. It seems that a part of the code is missing. Surely "n" must be increasing by 1 every time before the factorial program can work on it.
How can i get all the assignments, related to this class? Someone please help, I'm trying to learn java from the scratch.
instead of having the (int n) in the parameters for the private function, could you also leave the parameters empty and define a variable in the method itself?
And it's free !
HD version will be nice indeed
Somehow it doesn't surprise me that a guy this awesome listens to Apocalyptica.
Head first java. Best book on java out there.
it happens with most of online lectures available on youtube.....@ mac
hey i took care of it,so what u need to do is download acm..and then import it in ur project...if u need details ill expalin it,its no biggy,trust me :-)
Hi,
Can the definition of the factorial function be written in the run method ?
If not, why ?
Thanks.
@papawilk check out Sun's web site I know at one time they had testing materials on there. Otherwise a certification book would have a practice test in it. There is self test software you can get as well. I'd check with a teacher on it , I got mine for free from a class I took so not sure if there is a cost with it.
Some people learn out of pure interest, thus the 5 degrees. 5 topics of interest.
QUestion: if all calculations with pixels are done with ints why do the methods,
getHeight(), getWidth(), and label.getAscent(), label.getWidth() return doubles?
@nkvd1000 Thankfully I learned a little bit of Java before so I didn't get lost in this video.
Is there some way to test ourselves on this information. Can anyone recommend an online quiz for java beginners or something?
Anyone know where I can find the class package to download they use so I can import it into Eclipse?
they are using import acm.program.Console
and in this example for readInt function it's using acm.program.console
eclipse doesn't have the acm libraries by default
and I can't find any way to download these libraries if someone can help me out send me a private message on youtube I'd greatly appreciate it
hey i need help,i just saw this lecture and wanteed to run this program on my computer but the thing is that i am workin in eclipse so it always says that this GRect cannot be resolved to a type,so can u tell me which class should i import? i would be really grateful :-)
this is a lifesaver. my teacher doesnt explain anything, the book sucks and he doesnt tell us what is covered on the exams! it might f up my gpa. a 4 credit class! if i get less than a b im screwed. transfer school requires a 3.5 !#!$
oh hi..it took a while for someone to reply,yes i know about that,i did get that library and stuff but the thing is i was typing java.acm.graphics, not acm.graphics without that java infront...i hate stupid mistakes,but thank you anyway,
nice eraser!
hi does anyone know what is the best youtube literature after these mahani's luctures,thanks
I tried duplicating his checkerboard example, and it either fills all the squares or unfills all the squares. Anyone know if something has changed in the newest Java to cause this?
You could say... (Takes off glasses)... Those for loops don't go eye to eye.
Having limited usage with Wild Blue Satellite Internet restricts me from watching them all... It's B.S. 250mb DL/Day these are 150-200mb... Damn good lectures though! I'd hate to be in the class getting beamed with candies though... | ! | : )
10:00 wait, the init part's scope is different..
multiple "for"s with int i=0 is okay but multiple "int i=0"s would break stuff.
for getting user input, I do not see why he doesnt have to create a Scanner instance. Using readDataType seems way more simple, but still going to use a Scanner
I need those details
@dorohanter uh.. in the java environment
You need to import acm.graphics.*; and import acm.program.*;
You will find the whole program here -> see.stanford(dot)edu/materials/icspmcs106a/12-control-statements.pdf
enjoying the lectures but this one is starting to get tough.........so much terminology to remember
Why does the method setFilled automatically fill the square with black?
@dorohanter I recommend using Eclipse, the IDE that their using in the videos, works great for me! ;D
i have problem, i am trying to rewrite CheckerBoard program as video show. in the last line, the "add(sq)", my Eclipse remind me:"The method add(Component) in the type Container is not applicable for the arguments (GRect)". rest of my code are totally same as video. anyone could teach me how to fix it?
Did you import the graphics program?
Your code should look like this...
/* File: CheckerBoard.java
*
* This is a graphics program that
* draws a checker board
*/
import acm.program.*;
import acm.graphics.*;
public class CheckerBoard extends GraphicsProgram{
//number of rows
private static final int NROWS = 8;
//number of columns
private static int NCOLUMNS = 8;
//runs the program
public void run(){
int sqSize = getHeight() / NROWS;
for( int i = 0; i < NROWS; i++){
for(int j = 0; j < NCOLUMNS; j++){
int x = j * sqSize;
int y = i * sqSize;
GRect sq = new GRect(x, y, sqSize, sqSize);
sq.setFilled(((i + j) % 2) != 0);
add(sq);
}
}
}
}
Craig Walker thank you so much, it's working.
Craig Walker i have the same problem but i do as u say and nothing happened, this is my code:
import acm.program.*;
import acm.graphics.*;
import java.awt.*;
public class theRobotFace extends ConsoleProgram {
private static final double HEAD_WIDTH = 1;
private static final double HEAD_HEIGHT = 3;
private static final double EYE_RADIUS = 2;
private static final double MOUTH_WIDTH = 2;
private static final double MOUTH_HEIGHT = 2;
public void run() {
double placeX,placeY;
placeX = (getWidth()/2)-(HEAD_WIDTH/2);
placeY = (getHeight()/2)-(HEAD_HEIGHT/2);
drawRect(placeX,placeY,HEAD_WIDTH,HEAD_HEIGHT,Color.gray);
}
private void drawRect(double x,double y,double width,double height, Color color){
GRect rect = new GRect(x,y,width,height);
rect.setFilled(true);
rect.setFillColor(color);
add(rect);
}
}
I'm pretty new to java as well, but I'll try to help you the best I can.
1. Your class should be capitalized.
2. You shouldn't be extending Console Program when working with Graphics.
3. The parameters for your robot are way too small. The Width of your head is only 1 pixel. Play around with different numbers until you get the size of rectangle you want.
I think Its should give you a tiny dot in center of screen.
It is safe to declare a local variable inside a loop because it dies when arriving to loop end
Static variables are initialized only once, at the beginning - when the class is loading. They won't die at the end of the loop.
Yeah that is right, local variable shoulde be in the place of static variable in this case, confused with c/c++ (static variable // dynamic variable), take this Candy 🍬 .
:)
in 46:46
fillcolor (double x
double y
double r)
what is r ?
+The gamer 49:55 -- r is radius
in order to make a circle you need a point and a radius. At the end he calls his method passes (10,10,2,Color.red) as arguments to his method --- After that , what happens is the values he passed in are passed INSIDE the braces to the GOval object's parameters so that it can make a new GOval and then set it's properties and return the variable circle back to the program at the same spot that called the filled circle function.PS---Don't let the words parameter and argument confuse you----there the same thing ---they just say parameter when you create a method and argument when you "call" a method --- either way its the stuff in inside the parentheses. Good LUck and Thank you Professor Mehran
+Jason Gonzalez thanks for ur help
The level of difficulty just went up lol. But it's still manageable. If it's worth having, it's worth working hard for.
What does he import to get readInt?
@6:40, more or less. Isn't the "break" instruction just like the infamous "goto" that gave rise to "spaghetti code", so many years ago and which "structured programming" was invented to avoid??? Personnaly, I think the first solution to this problem was better. Even if it meant "repeating" the same instruction twice...
Mehran Sahami, 1st place in Candy Throwing.
how match is the value of getHeight()?
+Joseph Edm It depends on how big the graphics window is when your program runs, and changes if you resize the window.
You can display the value of getHeight() on the screen by sending it to a GLabel object:
//code
import acm.program.*;
import acm.graphics.*;
public class foo extends GraphicsProgram{
public void run(){
GLabel lab = new GLabel(String.valueOf(getHeight()),20,20);
add(lab);
}
}
yes, but you will always have 8 rectangles no matter your height of the screen right?
+Joseph Edm If you change the constant NROWS, the number of rectangles (or rows) will change but the screen height stays the same. Therefore, you need to know the screen height to get the height of the rectangle. You have to specify the height of the rectangle to create it.
that's a hard part of programming, it's not easy to come up with that algorithm!
what is the addition of double r ( reduce ) ?
r is the radius of the circle (the distance from the center)