Show Menu
Cheatography

Adv Integrated Software Dev - Quiz2 Cheat Sheet (DRAFT) by

Adv Integrated Software Dev - Quiz2

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Collec­tions Array

ArrayList<Employee> emplist = new ArrayList<>();
emplist.add(new Employee(123,"Dan1"));
emplist.add(new Employee(1,"Dan2"));
System.out.println(emplist);
Collections.sort(emplist);

Collec­tions Array (2) - Input

int numOfEmp = 5;
Scanner input = new Scanner(System.in);
Employee[] empArr = new Employee[numOfEmp];
int id = 101;
String name;
//empArr[0] = new Employee(id,"Sam");
for(int i=0;i<empArr.length;i++) {
   System.out.println("Enter employee name");
   name = input.nextLine();
   empArr[i] = new Employee(id+i,name);
}

Collec­tions Array (3) - Input

int[] scores = new int[10];
int score, count =0;		
		
System.out.println("Enter quiz score or enter 999 to quiz");
score = input.nextInt();
while(score != 999) {
   scores[count] = score;
   ++count;
   if(count == 10)
      score = 999;
   else {
      System.out.println("Enter quiz score or enter 999 to quiz");
      score = input.nextInt();
      }
}
System.out.println("number of scores entered " + count);
System.out.println("Scores are");
for(int i=0;i<count;i++)
   System.out.print(scores[i] + " ");