oop with java - homework 02: arrays and...

15
OOP with Java Homework 02: Arrays and I/O Thomas Weise · [email protected] · http://iao.hfuu.edu.cn Hefei University, South Campus 2 /2Faculty of Computer Science and Technology Institute of Applied Optimization 230601 Shushan District, Hefei, Anhui, China 230601 Econ. & Tech. Devel. Zone, Jinxiu Dadao 99 发区 99

Upload: others

Post on 18-Mar-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

OOP with JavaHomework 02: Arrays and I/O

Thomas Weise · 汤卫思

[email protected] · http://iao.hfuu.edu.cn

Hefei University, South Campus 2 合肥学院 南艳湖校区/南2区Faculty of Computer Science and Technology 计算机科学与技术系

Institute of Applied Optimization 应用优化研究所

230601 Shushan District, Hefei, Anhui, China 中国 安徽省 合肥市 蜀山区 230601Econ. & Tech. Devel. Zone, Jinxiu Dadao 99 经济技术开发区 锦绣大道99号

Page 2: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Outline

1 Introduction

2 Tasks

OOP with Java Thomas Weise 2/5

website

Page 3: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Introduction

• We want to practice I/O, i.e., reading of input and writing of outputdata

• We want to practice working with arrays

• This homework is comprised of one task

• Send me a zip archive named hw02_[your_student_id].zip (where

[your_student_id] is replaced with your student id) with one

answer-folder for each homework task (names hw02-1 )

OOP with Java Thomas Weise 3/5

Page 4: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which

OOP with Java Thomas Weise 4/5

Page 5: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices

OOP with Java Thomas Weise 4/5

Page 6: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

OOP with Java Thomas Weise 4/5

Page 7: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

• Asks the user for the “height” of the matrices via System.err (and reads

the height as int from the input)

OOP with Java Thomas Weise 4/5

Page 8: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

• Asks the user for the “height” of the matrices via System.err (and reads

the height as int from the input)

• Allocates a two-dimensional array of type double[height][width]

OOP with Java Thomas Weise 4/5

Page 9: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

• Asks the user for the “height” of the matrices via System.err (and reads

the height as int from the input)

• Allocates a two-dimensional array of type double[height][width]

• Reads the height*width numbers row by row into the array

OOP with Java Thomas Weise 4/5

Page 10: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

• Asks the user for the “height” of the matrices via System.err (and reads

the height as int from the input)

• Allocates a two-dimensional array of type double[height][width]

• Reads the height*width numbers row by row into the array

• Repeats the above step for the second matrix

OOP with Java Thomas Weise 4/5

Page 11: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

• Asks the user for the “height” of the matrices via System.err (and reads

the height as int from the input)

• Allocates a two-dimensional array of type double[height][width]

• Reads the height*width numbers row by row into the array

• Repeats the above step for the second matrix• Allocates a new double[][] two-dimensional array of proper size to receive

the result

OOP with Java Thomas Weise 4/5

Page 12: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

• Asks the user for the “height” of the matrices via System.err (and reads

the height as int from the input)

• Allocates a two-dimensional array of type double[height][width]

• Reads the height*width numbers row by row into the array

• Repeats the above step for the second matrix• Allocates a new double[][] two-dimensional array of proper size to receive

the result• Adds the two matrices that were read and stores the result in the freshly

allocated array

OOP with Java Thomas Weise 4/5

Page 13: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

• Asks the user for the “height” of the matrices via System.err (and reads

the height as int from the input)

• Allocates a two-dimensional array of type double[height][width]

• Reads the height*width numbers row by row into the array

• Repeats the above step for the second matrix• Allocates a new double[][] two-dimensional array of proper size to receive

the result• Adds the two matrices that were read and stores the result in the freshly

allocated array• Prints the resulting matrix row by row to System.out

OOP with Java Thomas Weise 4/5

Page 14: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Task hw02-1

• Write a Java program which:• Prints a greeting to the user to System.err , stating that it is a program for

adding matrices• Asks the user for the “width” of the matrices via System.err (and reads

the width as int from the input)

• Asks the user for the “height” of the matrices via System.err (and reads

the height as int from the input)

• Allocates a two-dimensional array of type double[height][width]

• Reads the height*width numbers row by row into the array

• Repeats the above step for the second matrix• Allocates a new double[][] two-dimensional array of proper size to receive

the result• Adds the two matrices that were read and stores the result in the freshly

allocated array• Prints the resulting matrix row by row to System.out

• The answer-folder for this task contains the complete Eclipse project,including source code (.java) and compiled (.class) file.

OOP with Java Thomas Weise 4/5

Page 15: OOP with Java - Homework 02: Arrays and I/Oiao.hfuu.edu.cn/images/teaching/lectures/oop_with_java/hw02_arrays_and_io.pdfTaskhw02-1 • Write a Java program which: • Prints a greeting

Caspar David Friedrich, “Der Wanderer über dem Nebelmeer”, 1818http://en.wikipedia.org/wiki/Wanderer_above_the_Sea_of_Fog

谢谢谢谢谢谢Thank you

Thomas Weise [汤卫思][email protected]

http://iao.hfuu.edu.cn

Hefei University, South Campus 2Institute of Applied OptimizationShushan District, Hefei, Anhui,

China

OOP with Java Thomas Weise 5/5