AST10106辅导、讲解Java程序、Java编程语言辅导、辅导Java设计
辅导Python程序|辅导Python编程
AST10106 Introduction to Programming
Lab 03
Basic Java Input / Output and Arithmetic Operations
Submission Details
In this lab, you are to write THREE Java programs to solve the given problems in the Lab Exercises
section. After your coding completes, submit three source files named Shapes.java, Face.java and
Cylinder.java to the assignment page of Canvas. The deadline is TWO weeks after your lab session
is conducted. Please verify your solution to ensure that everything is correct before submission.
Note: You are required to write down your name, student id, and lab section id in a comment block at
the beginning of your source file.
Objectives
The objectives of this lab are (1) to reinforce your programming concepts (e.g. variable declarations)
taught in the last lecture; (2) to introduce how to get user input from the keyboard; (3) to show you how
to display information on screen; (4) to demonstrate some basic arithmetic operations.
Software Required
1. Java Development Kit, e.g. Java SE 8
2. An Integrated Development Environment, e.g. Eclipse
Please start your lab PC with Windows 10 and refer to the previous lab exercise for the installation and
operation guide of Eclipse.
Introduction
In this lab, you will practice how to:
1. Obtain input values from the user with the aid of the Scanner class and store them in variables.
2. Display output to the user using the print and println methods of the System.out object.
3. Perform simple arithmetic operations on numeric variables.
Background
1. Display information to the user (console):
Java provides the following two methods to display information on the monitor’s screen. (Note:
there is indeed one more method called printf, which was added since JDK 1.5 to resemble Cstyle
output, but we only focus on the following two now).
i. System.out.print()
ii. System.out.println()
For your information,
? System is a class under the java.lang package. By default, all this package is implicitly
imported for every Java program by the Java compiler. So, you can use this class readily.
? out is a static field (also known as class variable) of the System class. Its data type is a
standard library class called PrintStream. Currently, you can ignore the meaning of static,
but try to remember that there is only a single copy of out that is associated with the class
(System) rather than with many instances of the class.AST10106 Introduction to Programming
2
? Finally, print() and println() are methods associated with the PrintStream object
whose name is out. By using the