Recent Posts

    ETS Strukdat

    Baca Juga



    1. Jelaskan perbedaan struktur data primitif dengan Non primitif, berikan contohnya dalam program sederhana.

    Jawab:

    Tipe data primitif adalah tipe data standar yang tidak diturunkan dari objek manapun. Tipe data primitif telah ditentukan dengan kata kuncinya masing-masing. Terdapat 8 (delapan) tipe data primitif yang Java dukung, antara lain Byte, Sort, Long, int, Float, Double,  Boolean, Char.

    Sedangkan, struktur data non primitif adalah struktur data yang secara default belum terdefinisi di suatu bahasa pemrograman. Struktur data non primitif didefinisikan sendiri oleh pemrogram. Contoh struktur data non primitif adalah Array, List, Stack, dan Queue.

    Contoh Code Data Primitif:
    import java.util.Scanner;
    /**
    * Write a description of class Kalkulator here.
    *
    * @author (your name)
    * @version (a version number or a date)
    */
    public class Kalkulator{
    public static void main(String args[]){
    System.out.println("Menu \n1. Penjumlahan \n2. Perkalian \n3.Pengurangan \n4. Pembagian \n5.Sisa Bagi");
    Scanner scanner = new Scanner(System.in);
    System.out.print("Masukan pilihan:");
    int menu = scanner.nextInt();
    switch(menu){
    case 1:
    penjumlahan();
    break;
    case 2:
    perkalian();
    break;
    case 3:
    pengurangan();
    break;
    case 4:
    pembagian();
    break;
    case 5:
    sisabagi();
    break;
    default:
    break;
    }
    }
    private static void penjumlahan(){
    Scanner scanner = new Scanner(System.in);
    System.out.print("Angka Pertama: ");
    int value1 = scanner.nextInt();
    System.out.print("Angka Kedua: ");
    int value2 = scanner.nextInt();
    int hasil = value1 + value2;
    System.out.println("Hasil penjulahan "+value1+" dan "+value2 + " adalah: "+hasil);
    }
    private static void perkalian(){
    Scanner scanner = new Scanner(System.in);
    System.out.print("Angka Pertama: ");
    int value1 = scanner.nextInt();
    System.out.print("Angka Kedua: ");
    int value2 = scanner.nextInt();
    int hasil = value1 * value2;
    System.out.println("Hasil perkalian "+value1+" dan "+value2 + " adalah: "+hasil);
    }
    private static void pengurangan(){
    Scanner scanner = new Scanner(System.in);
    System.out.print("Angka Pertama: ");
    int value1 = scanner.nextInt();
    System.out.print("Angka Kedua: ");
    int value2 = scanner.nextInt();
    int hasil = value1 - value2;
    System.out.println("Hasil pengurangan "+value1+" dan "+value2 + " adalah: "+hasil);
    }
    private static void pembagian(){
    Scanner scanner = new Scanner(System.in);
    System.out.print("Angka Pertama: ");
    int value1 = scanner.nextInt();
    System.out.print("Angka Kedua: ");
    int value2 = scanner.nextInt();
    int hasil = value1 / value2;
    System.out.println("Hasil pembagian "+value1+" dan "+value2 + " adalah: "+hasil);
    }
    private static void sisabagi(){
    Scanner scanner = new Scanner(System.in);
    System.out.print("Angka Pertama: ");
    int value1 = scanner.nextInt();
    System.out.print("Angka Kedua: ");
    int value2 = scanner.nextInt();
    int hasil = value1 % value2;
    System.out.println("Hasil sisa bagi "+value1+" dan "+value2 + " adalah: "+hasil);
    }
    }


    Output: 



    Contoh Code Data non Primitif:
    import java.util.ArrayList;
    import java.util.List;
    public class UserStack {
    private List<Object> list = new ArrayList<Object>();
    private int currentIndex = -1;
    public void push(Object object) {
    list.add(object);
    currentIndex++;
    }
    public Object pop(){
    Object object = list.remove(currentIndex);
    currentIndex--;
    return object;
    }
    public int count() {
    return list.size();
    }
    public Object peek(){
    return list.get(currentIndex);
    }
    public void clear(){
    list.clear();
    currentIndex = -1;
    }
    }
    view raw Java UserStack hosted with ❤ by GitHub
    public class UserApp {
    public static void main(String[] args) {
    UserStack newStack = new UserStack();
    newStack.push("Abd Wahid");
    newStack.push("Toni");
    newStack.push("Laila");
    System.out.println("Jumlah data pada UserStack: " + newStack.count());
    System.out.println("Data teratas pada userStact: " + newStack.peek());
    System.out.println("==================================");
    System.out.println("User yg dikeluarkan (Pop): " + newStack.pop());
    System.out.println("Jumlah data setalah Pop: " + newStack.count());
    System.out.println("Data teratas setelah Pop: " + newStack.peek());
    }
    }
    view raw Main hosted with ❤ by GitHub


    Ouput:



    2 Jika diketahui notasi infiks = “A + B * C ^ D – E / F” bagaimana bentuk notasi postfiks dari notasi infiks tersebut jika menggunakan operasi stack. Tuliskan dalam bentuk program , dan tampilkan screenshotnya.

    Jawab:
    Infiks     = “A + B * C ^ D – E / F"
    Postfiks = "
    A B C D ^ * + E F / -"

    Code:

    import java.io.IOException;
    import java.util.Scanner;
    class Main {
    public static void main(String[] args) throws IOException{
    String input, output;
    while(true){
    System.out.print("Enter infix: ");
    Scanner scanner = new Scanner(System.in);
    input = scanner.nextLine();
    if( input.equals(""))
    break;
    ToPostfix theTrans = new ToPostfix(input);
    output = theTrans.trabslation();
    System.out.println("Postfix is " + output + '\n');
    }
    }
    }
    view raw Main hosted with ❤ by GitHub
    public class Queue {
    private int size;
    char queueArr[];
    int front;
    int rear;
    int currentSize = 0;
    public Queue(int size) {
    this.size = size;
    front = 0;
    rear = -1;
    queueArr = new char[this.size];
    }
    public void enqueue(char data) {
    if (!isFull()){
    rear++;
    if (rear == size) {
    rear = 0;
    }
    queueArr[rear] = data;
    currentSize++;
    }
    }
    public char dequeue() {
    char fr = 0;
    if (!isEmpty()){
    fr = queueArr[front];
    front++;
    if (front == size) {
    front = 0;
    }
    currentSize--;
    return fr;
    }
    return fr;
    }
    public boolean isFull() {
    if (currentSize == size) {
    return true;
    }
    return false;
    }
    public boolean isEmpty() {
    if (currentSize == 0) {
    return true;
    }
    return false;
    }
    public String getString(){
    String str = "";
    while(!isEmpty()){
    str = str + dequeue();
    }
    return str;
    }
    }
    view raw Queue hosted with ❤ by GitHub
    class Stack
    {
    private int maxSize;
    private char[] stackArray;
    private int top;
    public Stack(int s){
    maxSize = s;
    stackArray = new char[maxSize];
    top = -1;
    }
    public void push(char j){
    stackArray[++top] = j;
    }
    public char pop(){
    return stackArray[top--];
    }
    public char peek(){
    return stackArray[top];
    }
    public boolean isEmpty(){
    return (top == -1);
    }
    public int size(){
    return top+1;
    }
    public char peekN(int n){
    return stackArray[n];
    }
    }
    view raw Stack hosted with ❤ by GitHub
    lass ToPostfix{
    private Stack theStack;
    private String input;
    private Queue queue;
    public ToPostfix(String in){
    input = in;
    int stackSize = input.length();
    int queueSize = input.length();
    queue = new Queue(queueSize);
    theStack = new Stack(stackSize);
    }
    public String trabslation(){
    for(int j=0; j<input.length(); j++)
    {
    char ch = input.charAt(j);
    switch(ch)
    {
    case '+':
    case '-':
    operand(ch, 1);
    break;
    case '*':
    case '/':
    operand(ch, 2);
    break;
    case '(':
    theStack.push(ch);
    break;
    case ')':
    parent(ch);
    break;
    default:
    queue.enqueue(ch);
    break;
    }
    }
    while( !theStack.isEmpty()){
    queue.enqueue(theStack.pop());
    }
    return queue.getString();
    }
    public void operand(char opThis, int prec1){
    while( !theStack.isEmpty()){
    char opTop = theStack.pop();
    if( opTop == '(' ){
    theStack.push(opTop);
    break;
    }else{
    int prec2;
    if(opTop=='+' || opTop=='-')
    prec2 = 1;
    else
    prec2 = 2;
    if(prec2 < prec1){
    theStack.push(opTop);
    break;
    }
    else
    queue.enqueue(opTop);
    }
    }
    theStack.push(opThis);
    }
    public void parent(char ch){
    while( !theStack.isEmpty()){
    char chx = theStack.pop();
    if( chx == '(' )
    break;
    else
    queue.enqueue(chx);
    }
    }
    }
    view raw ToPostfix hosted with ❤ by GitHub

    Output:



    3. Pada sebuah Bank, setiap nasabah yang datang diminta untuk mengambil antrian. Antrian tersebut memuat urutan layanan nasabah, dan jenis layanan yang dibutuhkan, apakah CS atau Teller.

    a. Untuk membuat aplikasinya, struktur data apa yang tepat.
        Jawab:

        Untuk Sistem Tiket Antrian menggunakan Struktur Data Queue.

    b. Tuliskan dan gambarkan struktur data untuk memuat informasinya.
        Jawab:

        

        Setiap nasabah yang akan mengantri akan di berikan tiken berdasarkan keperluannya, ada dua type pelayanan yaitu Teller dan Customer Service, setiap pelayanan ada 2 teller/meja untuk pelayanan yang lebih efisien.

    c. Implementasikan aplikasi antrian tersebut.

        Jawab:
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class Antrian {
    private int cs1 = 0;
    private int cs2 = 0;
    private int teller1 = 0;
    private int teller2 = 0;
    private String getDate(){
    DateFormat newDate = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");
    Date date = new Date();
    return newDate.format(date);
    }
    public void printTicketTeller(String keperluan){
    int nomor;
    int teller;
    if (teller1 <= teller2){
    teller1++;
    nomor = teller1;
    teller = 1;
    }else{
    teller2++;
    nomor = teller2;
    teller = 2;
    }
    System.out.println("=====================================");
    System.out.println("| Selamat Datang \n| Nomor Antrian Anda: " + nomor);
    System.out.println("| Teller No. " + teller);
    System.out.println("| keperluan: " + keperluan);
    System.out.println("| Tanggal: " + getDate());
    System.out.println("=====================================");
    System.out.println();
    }
    public void printTicketCs(String keperluan){
    int nomor;
    int meja;
    if (cs1 <= cs2){
    cs1++;
    nomor = cs1;
    meja = 1;
    }else{
    cs2++;
    nomor = cs2;
    meja = 2;
    }
    System.out.println("=====================================");
    System.out.println("| Selamat Datang \n| Nomor Antrian Anda: " + nomor);
    System.out.println("| Meja No. " + meja);
    System.out.println("| Keperluan: " + keperluan);
    System.out.println("| Tanggal: " + getDate());
    System.out.println("=====================================");
    System.out.println();
    }
    }
    view raw Antrian hosted with ❤ by GitHub
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Scanner;
    public class Main {
    static Antrian antrian = new Antrian();
    static QueueTeller queueTeller = new QueueTeller();
    static QueueCs queueCs = new QueueCs();
    static String menu1 = "Buka Rekening Baru";
    static String menu2 = "Penutupan Rekening";
    static String menu3 = "Setor Tunai";
    static String menu4 = "Transfer";
    static String menu5 = "Pembayaran tagihan";
    static String menu6 = "Ubah PIN";
    static int noCs = 1;
    static int noTeller = 1;
    public static void main(String[] args) {
    System.out.println("SELAMAT DATANG \nPilih Layanan: ");
    System.out.println("1. " + menu1 + " \n" +
    "2. " +menu2+ " \n" +
    "3. " +menu3+ " \n" +
    "4. " +menu4+ " \n" +
    "5. "+menu5+" \n" +
    "6. " + menu6 +" \n" +
    "7. Admin CS \n" +
    "8. Admin Teller");
    menu();
    }
    private static String getDate(){
    DateFormat newDate = new SimpleDateFormat("dd/MM/yyy H:mm:ss");
    Date date = new Date();
    return newDate.format(date);
    }
    private static void menu(){
    Scanner scanner = new Scanner(System.in);
    System.out.print("---> ");
    int menu = scanner.nextInt();
    if (menu == 1 || menu == 2){
    switch (menu){
    case 1:
    queueCs.enqueueCs(menu1, getDate(), noCs);
    antrian.printTicketCs(menu1);
    break;
    case 2:
    queueCs.enqueueCs(menu2, getDate(), noCs);
    antrian.printTicketCs(menu2);
    break;
    }
    noCs++;
    }else if (menu >= 3 && menu <= 6){
    switch (menu){
    case 3:
    queueTeller.enqueueTeller(menu3, getDate(), noTeller);
    antrian.printTicketTeller(menu3);
    break;
    case 4:
    queueTeller.enqueueTeller(menu4, getDate(), noTeller);
    antrian.printTicketTeller(menu4);
    break;
    case 5:
    queueTeller.enqueueTeller(menu5, getDate(), noTeller);
    antrian.printTicketTeller(menu5);
    break;
    case 6:
    queueTeller.enqueueTeller(menu6, getDate(), noTeller);
    antrian.printTicketTeller(menu6);
    break;
    }
    noTeller++;
    }else if(menu == 7 || menu == 8){
    switch (menu){
    case 7:
    queueCs.displayCs();
    queueCs.dequeueCs();
    break;
    case 8:
    queueTeller.displayTeller();
    queueTeller.dequeueTeller();
    break;
    }
    }else {
    System.out.println("Menu tidak ditemukan!!");
    }
    Main.main(null);
    }
    }
    view raw Main hosted with ❤ by GitHub
    class NodeTeller {
    NodeTeller next = null;
    String keperluan, tanggal;
    int no;
    NodeTeller(String keperluan, String tanggal, int no){
    this.keperluan = keperluan;
    this.tanggal = tanggal;
    this.no = no;
    }
    }
    class NodeCs{
    NodeCs next = null;
    String keperluan, tanggal;
    int no;
    NodeCs(String keperluan, String tanggal, int no){
    this.keperluan = keperluan;
    this.tanggal = tanggal;
    this.no = no;
    }
    }
    view raw Node hosted with ❤ by GitHub
    class QueueTeller {
    int size = 0;
    NodeTeller head;
    NodeTeller tail;
    public QueueTeller(){
    head = null;
    tail = null;
    }
    public void enqueueTeller(String keperluan, String tanggal, int no){
    NodeTeller node = new NodeTeller(keperluan, tanggal, no);
    if (head == null){
    head = node;
    tail = node;
    }else {
    tail.next = node;
    tail = node;
    }
    size++;
    }
    public void dequeueTeller(){
    if (head != null){
    head = head.next;
    size--;
    }
    }
    public int getSizeTeller(){
    return size;
    }
    public void displayTeller(){
    if (head == null){
    System.out.println("Tidak Ada Antrial Lagi!");
    }else {
    NodeTeller temp = head;
    System.out.println("=====================================");
    System.out.println("| Anda Melayani Antrian No.: " + temp.no );
    System.out.println("| Antrian Sedang Menunggu: " + (size - 1));
    System.out.println("=====================================");
    System.out.println();
    }
    }
    }
    class QueueCs {
    int size = 0;
    NodeCs head;
    NodeCs tail;
    public QueueCs(){
    head = null;
    tail = null;
    }
    public void enqueueCs(String keperluan, String tanggal, int no){
    NodeCs node = new NodeCs(keperluan, tanggal, no);
    if (head == null){
    head = node;
    tail = node;
    }else {
    tail.next = node;
    tail = node;
    }
    size++;
    }
    public void dequeueCs(){
    if (head != null){
    head = head.next;
    size--;
    }
    }
    public int getSizeCs(){
    return size;
    }
    public void displayCs(){
    if (head == null){
    System.out.println("Tidak Ada Antrial Lagi!");
    }else {
    NodeCs temp = head;
    System.out.println("=====================================");
    System.out.println("| Anda Melayani Antrian No. : " + temp.no);
    System.out.println("| Antrian Sedang Menunggu: " + (size - 1));
    System.out.println("=====================================");
    System.out.println();
    }
    }
    }
    view raw Queue hosted with ❤ by GitHub


        Output:
        





    4. Buatlah dokumentasi dalam bentuk source code , screenshot hasil, dan video Demo Presentasi yang dipost ke Youtube , kemudian diembedded di Blog masing-masing. Pengerjaan bisa berkelompok maksimal 3 orang, terakhir dikumpul 9 Mei 2021.

        Jawab:

            


    Artikel Terkait

    Belum ada Komentar untuk "ETS Strukdat"

    Posting Komentar

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel