1 / 11

CS 240 – Computer Programming I Lab

CS 240 – Computer Programming I Lab . Kalpa Gunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa /. Contact . Contact by e-mail kalpa@knoesis.org Office hours 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm. About me. Kalpa Gunaratna Sri Lanka

eshana
Download Presentation

CS 240 – Computer Programming I Lab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 240 – Computer Programming ILab KalpaGunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/

  2. Contact • Contact by e-mail • kalpa@knoesis.org • Office hours • 376 Joshi • Mondays & Wednesday 3:00 pm – 4:00 pm

  3. About me • KalpaGunaratna • 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/

  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 • <data type> <variable name>; • eg: int x; • Assign a value • <variable name> = <value>; • eg: x = 5; • Some data types • int, short, long, double, float, string, char, boolean,etc.

  8. intintegerNumber = 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 type name Create 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.

More Related