Pengaturan

Gambar

Lainnya

Tentang KASKUS

Pusat Bantuan

Hubungi Kami

KASKUS Plus

© 2024 KASKUS, PT Darta Media Indonesia. All rights reserved

kodingersAvatar border
TS
kodingers
Tes Masuk Kerja
java : Saya sedang mengikuti tes masuk kerja, dan soalnya adalah program dibawah ini :

Code:

import java.util.List;
import java.util.ArrayList;

public class Test {
public static void main(String... args) throws Exception {
Deque queue = new Deque();

int random = (int)(Math.random() * 100);

queue.addLast(10);
queue.addLast(20);
queue.addLast(random);
queue.addLast(40);
queue.addLast(50);

for(int i = 0; i < 2; i++) {
assertTrue(get(queue, 0) == 10);
assertTrue(get(queue, 1) == 20);
assertTrue(get(queue, 2) == random);
assertTrue(get(queue, 3) == 40);
assertTrue(get(queue, 4) == 50);

try {
get(queue, 5);
assertTrue(false);
} catch(Exception e) {
assertTrue(true);
}
}
}

public static void assertTrue(boolean v) {
if(!v) {
Thread.dumpStack();
System.exit(0);
}
}

public static int get(Deque queue, int index) throws Exception {
// 1) Only fill in your code in this method
// 2) Do not modify anything else
// 3) Use of 'new' keyword is not allowed
// 4) Do not use reflection
// 5) Do not use string concatenation
// 6) If your code cannot compile or fails the test case in 'main()', you will NOT receive a response from us
}
}

class Deque {
private List<Integer> items;

public Deque() {
items = new ArrayList<Integer>();
}

public void addFirst(int item) {
items.add(0, item);
}

public void addLast(int item) {
items.add(item);
}

public int removeFirst() {
if(isEmpty()) throw new RuntimeException();
return items.remove(0);
}

public int removeLast() {
if(isEmpty()) throw new RuntimeException();
return items.remove(items.size() - 1);
}

public boolean isEmpty() {
return items.size() == 0;
}
}


Pertanyaan saya adalah :
1. Setelah baca soalnya, keluaran apa yang diinginkan dari soal tersebut ?
2. Apa saja yang harus saya pelajari supaya bisa menjawab soal tersebut ? 
nona212
nona212 memberi reputasi
1
755
5
GuestAvatar border
Komentar yang asik ya
Tampilkan semua post
kodingersAvatar border
TS
kodingers
#2
Quote:

Savant Degrees
0
Tutup