powerpoint presentation · data conversion: • narrowing or widening • assignment • promotion...

12
ECE 122 Course Website: http://www.ecs.umass.edu/ece/ece122/ Piazza: https://piazza.com/umass/spring2017/ece122 TA Office Hours Wed 4:30PM - 6:00PM Thu 4:30PM - 6:00PM Fri 3:00PM - 6:00PM Location: Marston 34

Upload: others

Post on 21-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

ECE 122

Course Website: http://www.ecs.umass.edu/ece/ece122/

Piazza: https://piazza.com/umass/spring2017/ece122

TA Office Hours

Wed 4:30PM - 6:00PM

Thu 4:30PM - 6:00PM

Fri 3:00PM - 6:00PM

Location: Marston 34

Page 2: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

ECE 122- LAB

Outline:

Compile-time vs Run-time error

Data conversion

Operator precedence

Scanner classes

Classes and Objects

Page 3: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Compile-time error

• Syntax errors

• Mismatch in datatypes

See example CompileError1.java & CompileError2.java

Run-time error

• Exceptions

See example RunError.java & InputOutput.java

Page 4: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Data Conversion:

• Narrowing or Widening• Assignment

• Promotion

• Casting

See example Dataconv.java & Temperature.java

Page 5: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Ref: MargretPosch, Java Basics - Promotion and Casting, https://www.youtube.com/watch?v=FNPEKwQUJwU

Page 6: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Ref: MargretPosch, Java Basics - Promotion and Casting, https://www.youtube.com/watch?v=FNPEKwQUJwU

Page 7: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Ref: MargretPosch, Java Basics - Promotion and Casting, https://www.youtube.com/watch?v=FNPEKwQUJwU

Page 8: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Data Conversion:

far = 40.0

celsius0 = 5 / 9 * (far - 32);

= 5/9 * (40.0 – 32)

= 5/9 * 8.0

= 0 * 8.0 = 0.0 * 8.0 = 0.0

celsius1 = (double) 5 / 9 * (far - 32);

= (double) 5/9 * (40.0 – 32)

= (double) 5/9 * 8.0

= 5.0 / 9 * 8.0

= 0.555 * 8.0 = 4.444

Page 9: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Operator precedence See example Arithmetic.java

Page 10: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Scanner classes:

int nextInt() Returns the next token as an int.

long nextLong() Returns the next token as a long

float nextFloat() Returns the next token as a float

double nextDouble() Returns the next token as a double

String nextLine() Returns the rest of the current line, excluding any line separator at the end.

Page 11: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Classes and Objects

• Creating objectsSee example BankAccount.java

• ReferencesSee example BankAccountref.java

Customer1

Customer2

1111

1050.75

Customer1

Customer2

2222

2020.29

Before

After

Page 12: PowerPoint Presentation · Data Conversion: • Narrowing or Widening • Assignment • Promotion • Casting See example Dataconv.java & Temperature.java

Practice

• Write a program that accepts 3 numbers (1 integer, 1 float,1 double ) through standard input and print the average of numbers.

• Create a Person class with class variables Date ,month, year

Create two objects pA,pB of Person class.

Assign values to these class variables and print the date of birth of 2 persons in mm/dd/yy format.