Software Design 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

concat( )

(concatinate) Notation: s1.concat(s2) - appends s2 to s1

Basic Parts of A Computer

1. Input/Output Devices 2. Storage 3. Memory 4. Processor 6. Clock

Choosing Between a Double and a Int

1. Integer variables are for whole numbers without decimal points 2. Doubles deal with fractions and measured values

Program Testing: Debugging

1. Manually set a variable to a value 2. Insert print statements to observe variable values 3. Comment out unused code 4. Visually inspect the code

Other number types supported by Java

1. byte myVar - 8 bits, (-128 to 127) 2. short myVar - 16 bits (-32,768, to 32,767) 3. int myVar - 32 bits (over 2 billion - 2 billion max) 4. long myVar - 64 bits (VERY BIG)

Other String operations: indexOf( item), indexOf(item,indx), lastIndexOf(item), substring(startIndex,endIndex) Replacement Characters in String Operations: concat(moreString), replace ( findStr, replaceStr), replace(findChar,replaceChar)

1. gets index of first item occurrence in a string 2. starts at index indx 3. find the last occurrence of the item in a string 4. returns substring starting at startIndex and ending at endIndex-1 (inclusive of first index, exclusive of last index)

Brian Kernighan & Dennis Ritchie- AT&T Bell Labs

1978 - both published a book that described the high level programming language known as C that dominated between the 1980s and '90s

Bjarne Stroustrup

1985 - published a book on a programming language that was C-based known as C++ - made headway with the idea of OOP or object oriented programming

James Gosling

1991- helped create (along with Sun Micro-systems) Java and was intended to be used on consumer appliances. It was first publicly released in 1995

equality

== - should not be used with floating-point types (like doubles or strings)

break and switch

A "falling through" will occur if there is not a break statement at the end of a case

Coding Commandment: Method Local Variable

A METHOD'S LOCAL VARIABLE SHALL NOT HAVE THE SAME NAME AS A METHOD PARAMETER NOR NAME A METHOD'S LOCAL VARIABLE AS THE SAME NAME AS THE FIELD (Repetitive!)

Input

A program gets data from input or a file

Process

A program performs computations on that data such as adding two values

Output

A program puts that data somewhere such as to a file, screen, or network

Programs and Processors

A programmer must generate multiple executable programs (sometimes) in order for a program to work with a computer that has a different processor.

Dividing a float-point by zero

Dividing a nonzero floating-point number by zero results in infinity or -infinity (NaN may result when both values are 0)

Java Util: Scanner (User Input)

Format: import java.util.Scanner In-Code: Scanner scan = new Scanner (System.in); int i = scan.nextInt( ) or scan.nextDouble( )

Java Util: Random Numbers

Format: import.java.util.Random; In-Code: Random randGen = new Random; System.out.println(randGen.nextInt( )); \\(Between 0 to 2^32)\\ **randGen.nextInt(N) yields N possible values from 0 to N-1 (Can specify the restricted number of values by typing in a number into the ( )) Specifying the range: randGen.nextInt(6) + 10; (Will generate random numbers between 10 to 15) (values go from 0 to 5, add 10 and you get 15 - 10 to 15 as your final answer)

ranges

If a program has increasing ranges without gaps - multi-branch if-else statement can be used without logical operators. Likewise, when gaps exist, the range's low and high ends must both be explicitly detected, using a logical operator.

Identifier Meaning

It is good practice to create meaningful identifier names that self-describe an item's purpose

unit testing

It is the process of individually testing a smaller part or unit of a program

Input/Output Devices

Monitors and keyboard are part of these kinds of devices

charAt( )

Notation: someString.charAt(x) determines the character at index x of a string

Returning the last character in a string

Notation: userText.charAt(userText.length( ) -1 );

Memory

RAM - temporarily holds data that is read from storage and any address can be accessed in less time than a disk drive - volatile, meaning that contents are lost when a computer is turned off.

Code Writing Commandment

THOU SHALL NOT REPEAT THY SELF IN CODE OR ANYWHERE ELSE. (DRY PRINCIPLE - DON'T REPEAT YOURSELF)

Identifier Commandment

THOU SHALL NOT USE UNDERSCORES TO START IDENTIFIERS AND MUST START WITH A LETTER

Variable Commandment

THOU SHALL STRIVE TO USE TWO OR MORE WORDS FOR NAMING VARIABLES WITHIN REASON

Moore's Law

The doubling of an integrated circuit capacity is roughly every 18 months

equalsIgnoreCase and compareToIgnoreCase

These are used to ignore case when comparing two strings.

Short circuit evaluation

This skips evaluating later operands if the result of the logical operator can already be determined

Note to Self

When doing a method with parameters, DO NOT PUT A SPACE BETWEEN THE METHOD NAME AND YOUR PARAMETERS!!

Escape Sequences

\n - newline \t - tab \' - single quote \\ - backlash

memory

a circuit that can store 0s or 1s in each of a series of thousands of addressed locations (RAM, Hard Drive, SSD, etc.)

type conversion

a conversion of one data type to another (usually through implicit conversions like int and double) double to int is tricky

final or constant variable

a keyword in Java that prevents change from ever happening to a constant variable. The compiler will give an error if a constant variable has been changed later on in the code.

method

a list of statements invoking the method's name, otherwise known as the method call

parameter (the bucket)

a method input specified in a method definition (similar to a variable declaration) ex. public class MultiplePizzaAreas { public static void printPizzaArea (double pizzaDiameter) { } //Method inside class!// } Multiple parameters are separated by commas.

return statements

a method returns one value using this keyword

method stub

a note or method definition whose statements have not yet been written Usually have a: FIXME

floating-point literal

a number with a factional part even if it is 0 (1.0, 0.0, etc.) Always have a digit before the decimal point for a floating-point literal

switch and case statement

a program executes the first case whose expression matches the value of the switch expression, executes that case's statements, and then jumps to the end. If no case matches then the default case statements are executed. (Variable int dogAgeYears must match the 1 in case 1, otherwise it will turn up as the default option. This also works with char or characters with case 'A' and strings.) ex: switch (dogAgeYears) { case 0: System.out.println("That's 0...14 human years."); break; case 1: System.out.println("That's 15 dog years.); break; default System.out.println ("It is something..."); break; } **Can help if needing to replace a multi-branch if-else statement

Program Testing: testbench or testharness

a separate program whose sole purpose is to check that a method returns the correct output in correspondence with input values

executable program

a sequence of machine instructions (otherwise known as an executable)

cache

a small amount of RAM on a single chip that is accessible in one clock tick

program

a specific sequence of instructions that has meaning

expression

a statement that allows a certain variable to be modified in some way.

argument (what is put inside the bucket)

a value provided to a method's parameter during a method call ex. printPizzaArea(12.0)

overflow

a variable cannot store a value large than the maximum supported by the variable's data type (greater than the max. value is when overflow occurs)

field (otherwise known as global variables) - You want to minimize the use of these! Always try to use parameters instead.

a variable that is declared within a class but outside any method within that class

lower camel case and under score

abuts multiple words, capitalizing each word except the first (hiThere or hi_there)

assignment statement

assigns the variable on the left side of the equals with the current value of the right-side expression

bits

binary digits that are either a 0 or 1

boolean operators

boolean variables can be used to simplify expressions

equals method

can compare two strings to see if the strings are equal ex: str1.equals(str2);

char

character can store a single character like the letter m myChar = scnr.next( ).charAt(0); (first character in a string)

compareTo( )

compares two strings to see if they are similar (operators should NOT be used to do these types of comparisons with strings). This compares strings relationally. str1 less than str2 Negative number str1.compareTo(str2) < 0 str1 equal to str2 0 str1.compareTo(str2) == 0 str1 greater than str2 Positive number str1.compareTo(str2) > 0

circuit

connection of switches

**method definition

consists of new method's name and block of statements (every variable in the block is only found in the block throughout the code, unless accessed by a getter method) Methods are defined within a particular class, whether they are private or public

processors

created to process a list of desired calculations (instructions)

access modifiers

ex: public static

type casting

explicitly converts a value of one type to another type Ex: (double)myIntVar

for loops (you already know this, but just because)

for (initialExpression; conditionExpression; updateExpression)

For vs. While

for - Number of iterations is computable before the loop, like iterating N times. while - Number of iterations is not (easily) computable before the loop, like iterating until the input is 'q'

Clock

governs a processor's time it takes to execute instructions that ticks a specific frequency (Hz)

package

group of related classes

machine instructions

instructions that are defined by only 0s and 1s

**method call

invocation of a method's name causing the method's statement to execute (usually located in main method)

Incremental development

is a process in which a programmer writes, compiles and tests a small amount of code, then completes this cycle until the code is considered "correct"

floating-point number

is a real number that contains a decimal point in the number (a double)

Character Operations (starts with Character.isLetter(c))

isLetter(c) isDigit(c) isWhitespace(c) toUpperCase(c) toLowerCase(c)

identifier

it is either a sequence of letters, underscore, dollar signs or digits that start with one of those options

Storage

keeps files and other data in a disk drive - non volatile, maintain their contents even when powered off

void return

means the method returns no value

seed

mostly found in pseudo-random number generation that keeps track of certain integer and double values Random randGen = new Random (5); or using setSeed method randGen.setSeed(5); - same sequence is ran each time (NEED TO WORK ON THIS)

scope

name of a defined variable or method that is only visible to part of a program- In other words, a declared name that is only valid within a region of code (A VARIABLE CAN'T BE ACCESSED OUTSIDE THAT METHOD UNLESS THERE ARE GETTER AND SETTER METHODS)

Reserved Word

part of the programming language (int, short, float, and double) - otherwise known as a keyword

Program Testing: assert

prints an error message and exits the program if the provided test expression evaluates to false ex: assert testExpression : detailedMessage; assert (hrMintoMin(0, 0)==0: "Assertion (hrMintoMin (0, 0) == 0) failed";

Debugging

process of determining and fixing the cause of a problem in a computer program

high-level language (assembly language)

programming more closely to how humans think rather than all machine instructions

compliers

programs that translate the high-level language into machine instructions (0s and 1s)

compound operators

provide a shorthand way to update a variable - myHand +=1, or -=, *=, /=, %=

main method

public static void main (String [] args) { }

variables

references to data

whitespace

refers to blank spaces between items within a statement, and to blank lines between statements

.length( )

returns the length of the particular string

Processor

runs the computer's programs and performs operations as well as executes any specific instructions given to the computer

Integrated Circuit

small transistors connected to each other that fit onto a single chip

transitors

smaller switches that were put into a small circuit in 1958 to create the integrated circuit

variable declaration

statement that declares a new variable and specifies the type (int, double, float, string, etc.) as well as the descriptive name

character literal

surrounded with single quotes (' ') System.output.print("" + let1 + let2);

bytecode

the compiler generates and runs an executable program using machine instructions (virtual processor)

modular development

the process of dividing a program into separate modules that can be developed and tested separately and then integrated into a single program Although it is good to decouple almost every module you make for flexibility in the code.

float and short

these two (float especially) is only used for memory-saving situations

Program Testing: test vector and boarder cases

unique set of input values is a test vector boarder cases: (upper bounds, lower bounds, middle, upper mid, and lower mid) - most extreme to make the method fail in someway

Strings and userInput

userString = scnr.next( ); userString = scnr.nextLine( ); (will include whitespaces)

Getting part of a string section

userText.substring(userText.length( ) - 4, userText.length( )) This is the format for getting a section of a string. You are going to have to assign the new string to the original string you are manipulating Ex: userString = userString.concat(randomString);

arguments

usually appear within ( ) and are the input value into a particular method

Possible Loss of Precision Error in Java

usually means that the compiler is saying that a different float-point needs to be used (long, short vs. int and double)


Set pelajaran terkait

Subtracting Fractions with Unlike Denominators

View Set

Data Science and Machine Learning

View Set

Power Point L 1-3 Vocabulary Quizlet

View Set

AP Micro Unit 6 Practice questions, AP Microeconomics Unit 6, AP Microeconomics Unit 6 Test

View Set

Unit 2B Nature and Functions of Product Market (Surplus, Elasticity, and Utility) Study Guide

View Set