Docsity

Final Study Guide | Introduction to Programming in Java | CS 1054, Study notes of Java Programming

Toggle sidebar
bg1
Java Final Exam
Variables
oBoolean, byte, char, double, int
oExamples:
char letter = ‘a’;
int number = 10;
double average = 65.76;
Graphics
oSimple drawings
oOval, Rectangle, Line
oExample:
GOval, GRect, GLine
Logical Decisions
oIf Statement
It consists of a Boolean Expression followed by one or more
statements
Example:
int x = 10;
if (x<20)
{System.out.print(“This is an if statement”);}
oif…else if…else
You start off with an if statement requiring a condition, then if
need be, do an “else if” which requires another specific condition,
and finish off with an else statement, that applies to a solution to
any condition not mentioned
Example:
int x = 22
if (x<20)
{System.out.print(“This is an if statement”);}
else if (x > 25)
{System.out.print(“too high”);}
else if (x = 22)
(System.out.print(“Just right);}
else
{System.out.print(“you’re warm”);}
oSwitch Statement
A switch statement allows a variable to be tested for equality
against a list of values. Each value is called a case, and the variable
being switched on is checked for each case.
Example:
char grade = args[0].charAt(0);
switch(grade)
{
pf3
pf4

Partial preview of the text

Download Final Study Guide | Introduction to Programming in Java | CS 1054 and more Study notes Java Programming in PDF only on Docsity!

Java Final Exam

 Variables o Boolean, byte, char, double, int o Examples:  char letter = ‘a’;  int number = 10;  double average = 65.76;  Graphics o Simple drawings o Oval, Rectangle, Line o Example:  GOval, GRect, GLine  Logical Decisions o If Statement  It consists of a Boolean Expression followed by one or more statements  Example:  int x = 10; if (x<20) {System.out.print(“This is an if statement”);} o if…else if…else  You start off with an if statement requiring a condition, then if need be, do an “else if” which requires another specific condition, and finish off with an else statement, that applies to a solution to any condition not mentioned  Example:  int x = 22 if (x<20) {System.out.print(“This is an if statement”);} else if (x > 25) {System.out.print(“too high”);} else if (x = 22) (System.out.print(“Just right);} else {System.out.print(“you’re warm”);} o Switch Statement  A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.  Example:  char grade = args[0].charAt(0); switch(grade) {

case 'A' : System.out.println("Excellent!"); break; case 'B' : case 'C' : System.out.println("Well done"); break; case 'D' : System.out.println("You passed"); break; case 'F' : System.out.println("Better try again"); break; default : System.out.println("Invalid grade"); } System.out.println("Your grade is " + grade); }  Events o This is what goes into the mouse clicked section I guess o When something happens, as a result of something  Loops o For loop  A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.  A for loop is useful when you know how many times a task is to be repeated.  Example:  For(int x = 0; x < 10; x++) {System.out.print(“value of x =” + x)} o While Loop  A while loop is a control structure that allows you to repeat a task a certain number of times.  Example:  int x= 10; while( x < 20 ) { System.out.print("value of x : " + x ); x++; System.out.print("\n"); }  Methods o A better means of organization for the programmer. o A section of where you want a specific function in your program to go that is called from the main method.

 Image Manipulation o GImage pic = new GImage (“file.jpg”); o Int [][].x = pic.getPixelArray(); o for(int i=0; i<x.length; i++); ---pertains to rows (i){ for (int j=0; j<x.length; j++); --pertains to coulumns (j){ int pixel = x[i][j]; int red = GImage.getRed(pixel); int green = GImage.getGreen(pixel); } o GImage.createRGBPixel (red, red, red) -- this is kind of confusing. You have to also add like values to it which changes the color. o Manipulation of RGB – what does this due to the image?  R G B  (0, 0, 0) ----------- black  (255, 255, 255) --- white  (128, 128, 128) --- gray