Download presentation
Presentation is loading. Please wait.
Published byAnastasia Barnett Modified over 9 years ago
1
CS 240 – Computer Programming I Lab Kalpa Gunaratna – kalpa@knoesis.orgkalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/
2
Contact Contact by e-mail kalpa@knoesis.org kalpa@knoesis.org Office hours 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm
3
About me Kalpa Gunaratna Sri Lanka Graduate from University of Colombo, Sri Lanka Computer Science first year PhD student @ Wright State University and member of Kno.e.sis Center of Wright State University. More information if you are interested in knowing my background http://knoesis.wright.edu/researchers/kalpa/ http://knoesis.wright.edu/researchers/kalpa/
4
Some rules and guidelines to remember Lab consists of two parts Part I – in lab which is due on the second lab session of the week. Part II – post lab which is due before next week’s lab session starts. You cannot turn in assignments later than this deadlines. 0 marks otherwise. Make sure you follow these deadlines and normally ignore WebCt deadlines. Because WebCt deadline is set for all set of classes Upload the zipped Net Beans project to WebCt.
5
You will have 4 projects. Each project will have a deadline posted in WebCt. Projects are accepted only until 3 days past deadline and each day accounts for 10% off from your total eligible score. I may sometimes make minor changes to assignments in the lab and make sure you make a note of them! If you use a lab computer please save your net beans project into pen drive or e-mail.
6
Today’s lab! Demo on how to create a project in Net Beans and saving.
7
Basic variable initialization & creation Initialize ; eg: int x; Assign a value = ; eg: x = 5; Some data types int, short, long, double, float, string, char, boolean,etc.
8
int integerNumber = 0; double doubleNumber = 0.0; Scanner keyboard = new Scanner(System.in); System.out.println("Hello World!"); System.out.println("This is my first JAVA program"); System.out.print("Enter any integer (1 or 2 or... up to 9999): "); integerNumber = keyboard.nextInt(); System.out.println("You entered the integer " + integerNumber); System.out.print("Enter any floating point number \n" + "(any # with a decimal point): "); doubleNumber = keyboard.nextDouble(); System.out.println("You entered the floating point number " + doubleNumber); String outputMsg = "The sum of the integer and the double is " + (integerNumber + doubleNumber); JOptionPane.showMessageDialog(null, outputMsg,"Lab1 Output", JOptionPane.INFORMATION_MESSAGE); System.out.println("bye"); Variable creation and assignment
9
Get input from key board Scanner keyboard = new Scanner(System.in); keyboard is the given name to the variable here. You can use any name you like. Object typenameCreate new object and assign to name
10
Hints on how to build a String Example String outputMsg = "The sum of the integer and the double is " + (integerNumber + doubleNumber); Can concatenate Strings with “+” operator.
11
Print with restricted decimal places How to control decimal places in printing System.out.printf(“%.2f \n", 1234.123); You can also use DecimalFormat class in java.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.