U2: Further Java Fundamentals Flashcards
Input Processing Output Model
- Entered from digital input or input device into program
- Info processed (calculations, altered, etc)
- Output to user or output device
Process
- Involves manipulation, transformation of inputs
- Executing instructions, making decisions
- Assessing/modifying data structures
Application of IPO Model
- Applicable across different domains of computer science
- Software development, data processing, networking
- Understand the Problem
Define problem statement; Identify inputs and outputs
- Design the Solution
- Determine steps needed to obtain input data
- Define processing required to produce desired output
- Implement the Solution
- Write code to obtain input data from user
- Implement algorithms to process input data
- Add comments
- Documentation
- Add comments to explain purpose, functionality
- Re-read comments and add additional ones
- Testing
Test program with different input values
Variable
- Named location in computer’s memory
- “Named” as it’s referenced by using name
- Can be initialized by math equations
Functions of Variables
- Declaring a variable = making it exist
- Initializing a variable = giving it’s first value
Variable: int (Integer)
- Positive/negative #’s w/out decimals
- Between -2,147,438,648 and 2,147,438,647
- Takes 32 bits memory
Variable: double (Double)
- Positive/negative #’s w/ decimals
- Up to 15 decimal places accurately
- Takes 64 bits memory
Variable: char (Character)
- Single character; 16 bits memory
- Defined using single quotation marks
- Ex: ‘A’, ‘v’, ‘&’, ‘?’
Variable: boolean (Boolean)
True/false; 1 bit memory
“Not” Variable: String (String)
- Series of characters, words, sentences
- Memory varies by size string
- Defined using double quotation marks
Input as String: Errors
- If invalid input, program can handle errors
- Allows program to validate input before conversion
Input as String: Special Cases
- Allows program to handle special cases
- Ex: measurement units, prompts on context of input
Input as String: Flexibility
- More flexibility over complex inputs
- Ex: multiple values, non-numeric characters
Input as String: Parsing
Numeric string data must be parsed (i.e. converted) to numeric data type
“”
Separates two variables with numbers by decimal with the +
Operations in Java
- +: Addition
- -: Subtraction
- *: Multiplication
- /: Division
- %: Modulus (Remainer of division)
Reserved Word
Word having function in Java; Ex: “int”
Variable Name Requirements
- Describe what variable holds
- Must not be reserved word
- Must not be too long (ex: someInformationAboutTheUser)
“Instantiating an object”
Making the object exist
“Prompt the User”
Ask the user info; Read it into program
Reading in Data From User [A]
Use [import java.util.Scanner;] at top of program
Reading in Data From User [B]
Instantiate scanner [Scanner keyedInput = new Scanner(System.in);]
Reading in Data From User [C]
Use [keyedInput.nextLine/Double/Int()] for strings, doubles, integers
Constants
- Values don’t change as program runs
- Use when constantly giving same value
Constant Attributes
- Declared and initialized on same line
- Preceded by word “final”
- Have capital letters
When to Use Constants
- Dates from past
- Tax rates
- Prices of things
- Longer names
- Provinces, Countries, Cities
Rounding Techniques
- Multiplication/division by 10^x; x = no. of decimal values removed
- variable = Math.round (variable) to nearest whole number
Benefits of Organized Programs
- Easier to write; remember which subtasks already done
- Easier to debug; collaborate on
- Easier to maintain, update or re release
When to Comment [A]
- Where variables declared and initialized
- How user input generated
When to Comment [B]
- Calculations, processing, formatting
- Loops/selection statements
Function of {}
Shows where parts of program start and end
Function of []
Index arrays
Function of ()
Order of operations (B in BEDMAS); provide parameters to method
Console
- Allows output to screen
- Doesn’t allow graphics, dropboxes, text fields
- Programmers test console first, then develop GUI