1 / 14

Computer Science A 1: 3/2

Computer Science A 1: 3/2. CS A. Course plan. Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor, libraries. A bit about software engineering – methods used in constructing programs. A bit about graphics Freeware book.

rafe
Download Presentation

Computer Science A 1: 3/2

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. Computer Science A 1: 3/2 CS A

  2. Course plan • Introduction to programming • Basic concepts of typical programming languages. • Tools: compiler, editor, integrated editor, libraries. • A bit about software engineering – methods used in constructing programs. • A bit about graphics • Freeware book

  3. Computer Science A What you have to do • 6 * home work • 3 * mini-project • 1 * oral test based on mini-project All information available on http://akira.ruc.dk/~madsr/csa-f09.html

  4. Java programs public class Hello{ public static void main(String[] args){ System.out.println(”Hello world”); } } A program contains classes (here Hello) chapters classes contains methods (here main) paragraphs methods contains statements (here System.out…) One class has the same name as the file (Hello.java) One method in that class is called main

  5. Java programs Extra spaces and newlines does not matter, except: • No newlines in text strings (”… ”) • At least one space between words (public static) • Use indentations to make programs readable. The compiler ignores it, but I don’t Case does matter String, class Hello and Hello.java

  6. Java statements Print out System.out.println(…. Reading input … Declare variables int counter; Change values of variables counter = 1; this can be combined into int counter = 1; Method calls if statements while statements

  7. Expressions and values For now: strings and numbers String name=”Hello”; int counter = 2; (case does matter) (three more types of values; some ways to construct more complex values from simple ones.) Operations + on strings concatenate +,-, *,/ on numbers add, subtract, multiply, divide

  8. Assignment int counter; create a variable called counter counter=1; store the value 1 in the variable counter=counter+1; compute the value of the expression counter+1 and store that in the variable. counter now has the value 2

  9. Input input via command prompt screen java.util.Scanner in= new java.util.Scanner(System.in); System.out.println("type a name"); String line=in.nextLine(); System.out.println("type a number"); int num=in.nextInt(); System.out.println("read: "+line+" "+num); Read a line and a number and save what you read in newly created variables

  10. Input nextLine reads text until next linebreak, returns the text and skips the linebreak nextInt skips spaces and newlines until start of a number, it reads and returns the number Notice that java and DOS does not read anything until you have finished a line. After a nextInt call the next symbol is probably a newline character.

  11. Input input via dialog windows String name= javax.swing.JOptionPane.showInputDialog( "type a name"); String num = javax.swing.JOptionPane.showInputDialog( "type a number"); Output: javax.swing.JOptionPane.showMessageDialog( null,"read: "+name+" "+num); Read a line and a number and save what you read in newly created variables

  12. TextIO Eck has written his own class to do Input/output. To use it you need to download it from his web page and place it in the same directory as your program. To read a number write int num = TextIO.getlnInt(); To read a String write String s = TextIO.getln();

  13. Java programs public class Hello{ public static void main(String[] args){ System.out.println(”Hello world”); } } Public: you can hide stuff from other parts of your program. Here: everything can be seen everywhere static: some stuff may only exist for some of the time a program is executed. Here: it exists all the time void: methods may return values. Here: it does not return anything. String[] args: When you start a program it may have some command line arguments (you drop a file on a program etc). Here: it is not used.

  14. Objects On Friday: expressions, variables etc Eck chapter 2: 2.1 – 2.5 The important part is 2.1-2.3.2. The rest you can always look up when you need it

More Related