Review Review Review. Concepts Comments: definition, example, different types of comments Class:...

41
Review Review Review

Transcript of Review Review Review. Concepts Comments: definition, example, different types of comments Class:...

Page 1: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

ReviewReview

Review

Page 2: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Concepts

• Comments: definition, example, different types of comments

• Class: definition, example• Object: definition, example• Data type:

– Byte, short, int, long, float, double– Char, boolean– String

Page 3: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Concepts

• Assignment statement• Boolean expressions• Identifiers, constants• Commands:

– If– Switch– Do/While, While, and For

Page 4: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Concepts

• File extension: *.java, *.class• Compile: Textpad: Compile Java and Run

javaDOS: javac and java

Page 5: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Project 1 (Section 01)

• Average: 93.14 (35 students submitted)

Project 1

020406080

100

0 10 20 30 40

Project 1

Page 6: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Project 1 (Section 2)

• Average: 97 (only 28 students submitted)

93

94

95

96

97

98

99

100

101

0 5 10 15 20 25 30

Series1

Page 7: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Lab section

Page 8: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1 (Section 01)

• Avg =84.3. Max = 99.

Section01

0

20

40

60

80

100

120

0 10 20 30 40

Series1

Page 9: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1 (Section 02)

• Avg = 88, Max = 100

Section 02

0

20

40

60

80

100

120

0 10 20 30 40

Series1

Page 10: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Rules for Midterm exam - Student ID is required- Don’t:

- Leave the exam room after the exam is distributed

- Use cell phone or computers (PC)- Talk with each other during the exam

- Limit of questions you can ask teacher during exam time. If you ask more than two questions, you will have some points off taken from your exam.

Page 11: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Answers to Homework 1

1. In general, commands to compile and execute a java program are

a. compile and run b. compile and link c. javac and java d. java and link

This is the only answer accepted if this question is asked in another

exam

Page 12: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1 - Answer

2. All Java program must have this method to run

a. hello()b. start()c. main()d. method()

Page 13: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

• 3. Which of the following is not mandatory in variable declaration

• a. a semicolon • b. an assignment • c. a variable name• d. a data type

Page 14: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework1

4. You store java source code files with following extension?

a. .javab. .classc. .srcd. .javadoc

Page 15: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework1

5. A single line comment in Java starts with

a. ; b. # c. , d. // e. none of the above

Page 16: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework1

6. Java language is case sensitivea. Trueb. False

Page 17: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework1

7. As long as a computer has a Java Virtual Machine, the same program written in the Java programming language can run on any computer

a. Trueb. False

Page 18: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework1

8. Which of the following is an invalid identifier?

a. oneb. Twoc. _3Fourd. 4Five

Page 19: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework1

9. Which of the following is an invalid variable declaration?

a. String inputStr;b. int i=0;c. boolean flag = true;d. double, int, j=0;

Page 20: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework110. Assuming the following declarations are

executed in sequence, why are the second and the third declarations invalid?int a,b;double a;double b;

a. Both a and b are invalid identifiers.b. Variable a has been declaredc. Variable b has been declaredd. Both variables a and b have been

declared in the first declaration

Page 21: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework1

11. The __new_____operator is used to create a new object

Page 22: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

12. Identifiers may not start with a ___number (digit)________ or contain__special/(non-alpha-numeric)_____characters, other than the underscore or the dollar sign

Page 23: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

13. char data type represents individual _character______

Page 24: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

14. Text data can be stored in _String__objects

Page 25: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

15. Constants __can not be (never be, are not)__changed during program execution

Page 26: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

16. Boolean expressions are built by use of _relational___operators and _boolean__________operators

Page 27: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

17. Every variable that we use in a Java program must be _declared/defined__________

Page 28: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

18. A Java program is composed of one or more ___classes__

Page 29: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

20. int a== b;== can’t be used in variable

declaration

Page 30: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 121. double monthlyInterestRate;

if (monthlyInterestRate >= 0.08) && (monthlyInterestRate <= 0.5 ); {

System.out.println(“Interest rate is invalid”);System.exit(1);

}1. () is needed or remove )( before and

after &&2. ; should be take out3. No value has been initialized for

monthlyInterestRate

Page 31: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

22. char userChoice=’l’;if (userChoice ==’s’) {

System.out.print(“ Drop small cup into position”); (1) Missing ;}else { System.out.println(“ Drop large cup into position”);

}else System.exit(-1);

2. { should be inserted here

Else should be taken out

Page 32: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

23. String choice=”5”;switch(choice) {case 4: System.out.println(“ Right branch”); break;default: System.out.println(“ Default branch”); break;}

1. Switch doesn’t support String data type. It must be char or int(bytes,short,int)

Page 33: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

24. int sum=0;

for (int i=0, i< 100);{sum+= i;

}1; int i=0, this comma should be semicolon2. Missing post body update (increment or

decrement)3. semicolon after 100) should be taken out

Page 34: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 125. int x,y;

x=-10;y=-20;if ( y>0 && x< y)System.out.println(" The output is "+(x+y));elseSystem.out.println(" The output is "+(x-y));

The output is 10(Because -10-(-20) = -10+20 = 10)

Page 35: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 126. int count=0, sum=0;

while (count < 10) {sum += count;count+=3;

}System.out.println(" Sum ="+ sum);count=0 sum =0count = 3 sum = 0+3=3count = 6 sum = 3+6=9count = 9 sum = 9+9=18

Page 36: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 127. int nextToPrint = 1;

int maximum = 10; while(nextToPrint <= maximum){

if (nextToPrint % 2 != 0) System.out.print(nextToPrint+" ");

nextToPrint = nextToPrint +1; }

System.out.println();

1 3 5 7 9

Page 37: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 128. int sum=0;

int i=0;while (i<5) {

int j=4;while (i!=j) {

sum += j;j=j-1;

}i++;

}System.out.println(" Sum ="+sum);

Sum = 30

Page 38: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

• sum=0 i=0• j=4

sum = 0+4 = 4j=3

sum = 4+3 = 7j=2

sum = 7+2 = 9j=1

sum = 9+1=10

Page 39: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

• i=1• j=4

sum = 10+4 = 14j=3

sum = 14+3 = 17j=2

sum = 17+2 = 19

Page 40: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

• i=2• j=4

sum = 19+4 = 23j=3

sum = 23+3 = 26

Page 41: Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Homework 1

• i=3• j=4

sum = 26+4 = 30