120 likes | 232 Vues
Explore computing concepts, input/output in Java using Scanner class, system print methods, and problem-solving with input/output. Learn to read different data types, analyze exam grades, and build ExamGrades class.
E N D
CSC1401Input and Output (and we’ll do a bit more on class creation)
Learning Goals • Computing concepts • Input and output in Java • Using the Scanner class
To date • We have been working with pictures, and with drawing, and with turtles • We have not really been getting any input from the user • Our output has mostly been limited to invoking show() or explore() on a picture
This next week • We’ll be looking at textual programming –numbers and words (Strings), before going back to more graphical material after Thanksgiving • Needed in lots of computational areas
Output in Java • System.out.print() • System.out.println() • Place what we want printed inside the () • Use + to concatenate things • System.out is an object (the standard output – the display on our computers)
Input in Java • System.in is the standard input (the keyboard) • However, we need a special class, located in java.util.Scanner
Syntactically import java.util.*; // needed for scanner class IOTesting { public static void main(String [] args) { Scanner scan = new Scanner(System.in); int value = scan.nextInt(); …
Input • What else can you read in besides ints? • See the Javadoc • nextBoolean() • nextDouble() • nextFloat() • nextLine() reads in a String • etc.
Problem solving with Input and Output • Keeping track of exam grades for CSC1401 • Then writing methods for: • Finding out the exam average • Printing out the grades • Calculating the standard deviation (if I remember how to do it) • Who got the highest grade? And what it was… • etc.
ExamGrades class • What variables do we need? • What methods? • Building the class
Summary • We use System.out for output to the terminal • We use System.in in conjunction with a Scanner object for getting input from the keyboard
Reading Assignment • none