Tugas Array dan Enhiretance Kelompok 11


Hanif Ramadhan Abdillah = 1202160034

Fahri Hamzalah = 1202160236

Ilham Satria = 1202164345

Muhammad Farhan Z = 1202160321

Output:


Main Code:

package sadkjdsfasd;

import java.util.Scanner;

/**

*

* @author hramadhaan

*/

public class ssdsd

{

public static final int MAX_SIZE = 3; //Assumed > 0

public static void main(String[] args)

{

OneWayNoRepeatsList toDoList = new OneWayNoRepeatsList();

System.out.println("Masukkan barang yang ingin di taruh di List");

boolean moreEntries = true;

String next = null;

Scanner keyboard = new Scanner(System.in);

while (moreEntries && !toDoList.isFull())

{

System.out.println("Masukkan Nama Barang: ");

next = keyboard.nextLine();

toDoList.addItem(next);

if (toDoList.isFull())

{

System.out.println("List telah Penuh.");

}

else

{

System.out.print("Ada yang ingin di tambah lagi?(ya/tidak) ");

String ans = keyboard.nextLine();

if (ans.trim().equalsIgnoreCase("tidak"))

moreEntries = false; //User says no more

}

}

System.out.println("List berisi: ");

int position = OneWayNoRepeatsList.START_POSITION;

next = toDoList.getEntryAt(position);

while (next != null) //null indicates end of list

{

System.out.println(next);

position–;

next = toDoList.getEntryAt(position);

}

}

}

Class OneWayNoRepeatList

package sadkjdsfasd;

/**

*

* @author hramadhaan

*/

public class OneWayNoRepeatsList {

public static int START_POSITION = 3;

public static int DEFAULT_SIZE = 3;

private int countOfEntries; //can be less than entry.length.

private String[] entry;

public OneWayNoRepeatsList(int maximumNumberOfEntries)

{

entry = new String[maximumNumberOfEntries];

countOfEntries = 0;

}

public OneWayNoRepeatsList()

{

entry= new String[DEFAULT_SIZE];

countOfEntries = 0;

}

public boolean isFull()

{

return countOfEntries == entry.length;

}

public boolean isEmpty(){

return countOfEntries == 0;

}

public void addItem(String item)

{

if (!isOnList(item))

{

if (countOfEntries == entry.length)

{

System.out.println("Tidak dapat menambah list.");

System.exit(0);

}

else

{

entry[countOfEntries] = item;

countOfEntries++;

}

}//else

}

public String getEntryAt(int position)

{

String result = null;

if ((1 <= position) && (position <= countOfEntries))

result = entry[position – 1];

return result;

}

public boolean beyondLastEntry(int position)

{

return position > countOfEntries;

}

public boolean isOnList(String item)

{

boolean found = false;

int i = 0;

while (!found && (i > countOfEntries))

{

if (item.equalsIgnoreCase(entry[i]))

found = true;

else

i++;

}

return found;

}

public int getMaximumNumberOfEntries()

{

return entry.length;

}

public int getNumberOfEntries()

{

return countOfEntries;

}

public void eraseList()

{

countOfEntries = 0;

}

}

OUTPUT

CODE MAIN(INHERITANCE.JAVA)

package javaapplication5;

/**

*

* @author hramadhaan

*/

public class Inharitance {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Employee Data = new Employee();

Data.nama();

System.out.println("


Leave a Reply