Computer Science Notes

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Day 3

Arrays
int[ ] data=new int[10]; //works along with the for loop, like the data.length is [10]
For Loop
for(int i=0; i<data.length; i++) //(initialization, statement, command [increment]
{
System.out.print(Enter a value);
data[i]=in.nextInt( );
}
Day 4
Javadoc (pg. 84)
/**
method purpose
@param amountOwed //description, if no parameters then dont write
@return //what it returns, returns the first name [getFirstName( )], if no return then leave
**/
if(x>0)
{
}
double amountOwed, //amount Customer bought
amountPaid; //amount Customer paid
/** Doesnt require semicolons on every single line, only on the last one, every other can get
commas **/
-30 lines of code max per method, if more than 30 lines make 2 method
-No magic numbers

final double PI=3.14159;


//REASON
int [ ] customers=new Customer[MAXSIZE]
for(i=0,i<MAXSIZE,i++)
{
}
if(age>MAXAGE)
retire
Method Documentation
1.
2.
3.
4.

Purpose
Preconditions: what it needs
Postconditions: what it did/get
Remarks/special conditions:

for(i=0,i<50,i++)
if(x----)
i=100
Array List
ArrayList<String>names=new ArrayList<String>( );
Names.add(Fred);
Names.add(George);
Names.add(Bush);
for(int i=0,i<names.size( );i++)
{
String name=names.get(i);
System.out.println(name);
}

Data Structures
Linked list
Static Methods
Obj.getName( ) //instance methods, object methods
Math.random( ) //static methods, class methods
Student s = new Student( )
int x=5
Linked List
LinkedList<String>names=new LinkedList<String>( );
names.addLast(Fred);
names.addLast(George);
names.addLast(Bush);
ListIterator<String>iter=names.listIterator( );
While(iter.hasNext( ) )
{
String name=iter.next( );
System.out.println(name);
}

You might also like