Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Information problem… ???
Information problem… Input Output
Information problem… Input Variable double price, pricewithtax; price = price = price* pricewithtax = price
VariableString String name = “Obama”; String name = “Obama”; int int age = 30; int age = 30; double double price = 15.25; double price = 15.25; boolean boolean dataplan = true; (or false) boolean dataplan = true; (or false) Variable type Variable name (no space, start With alphabet, case sensitive) Variable value
Memory Model Values in the process are stored in memory. – View memory as a sequence of slots that can hold values of different types Variables name the slots, sometimes called locations of memory Assignment can put values in variables
Standard arithmetic Java supports basic arithmetic operators: +, -, *, /, and %. Add two numbers? int number1, number2, result; numbers1 = 18; number2 = 9; result =number1+number2; System,out.println(result);
double x, y; x = 7.486; y = x+15*x-7/x*x; (?????????) System,out.println(y);
Exercise: To convert from meters to feet, multiply the number of meters by meter = ???? Feet 5.68 feet = ???? meter
Exercise: Implement the following expression:
int number1 = 5; String number2 = “10”; int result; result = number1 + number2; What is the result??? Variable type conversion
double number; String str = “10.735”; number = Double.parseDouble(str) StringStringintint str = Integer.toString(num) num = Integer.parseInt(str); StringStringdoubledouble str = Double.toString(num) num = Double.parseDouble(str); Two questions: 1.What is “Double” and “Integer”??? 2. Why we need type conversion???
int number1, number2, sum; number1 = Integer.parseInt (jTextField1.getText()); number2 = Integer.parseInt (jTextField2.getText()); sum = number1 + number2; jLabel3.setText(Integer.toString(sum)); jTextField jTextField1.getText( ); jLabel jLabel3.setText (?????);
Exercise:
1.What is variable? 2.What is expression? 3.What is Standard arithmetic? 4.What is type conversion? 5.What is GUI? 6.How to add the code to GUI?