Advertisement
aril941

class_linked

Nov 23rd, 2020 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.90 KB | None | 0 0
  1. from class_node import*
  2. from main import*
  3. import os,sys
  4. import datetime
  5. import random
  6. import time
  7.  
  8. # ------------------------------------------
  9. # NAMA  : Muhammad Kharirrushofa
  10. # NIM   : A11.2019.11823
  11. # ------------------------------------------
  12.  
  13. class linked(object):
  14.     """docstring for linked"""
  15.     def __init__(self, head=None,tail=None):   
  16.         self.head=head
  17.         self.tail=tail
  18.  
  19.     def regbuku(self,data):
  20.         newbook=class_node.node(data)
  21.         if(self.head is None):
  22.             self.head=newbook
  23.             self.tail=newbook
  24.         else:
  25.             self.tail.next_node=newbook
  26.             self.tail=newbook
  27.  
  28.     def delbuku(self,posisi):
  29.         if self.head==None:
  30.             return
  31.         temp=self.head
  32.         if posisi==0:
  33.             self.head=temp.next_node
  34.             temp=None
  35.             return
  36.         for i in range(posisi -1):
  37.             temp=temp.next_node
  38.             if temp is None:
  39.                 break
  40.  
  41.         if temp is None:
  42.             return
  43.         if temp.next_node is None:
  44.             return
  45.  
  46.         next_node=temp.next_node.next_node
  47.         temp.next_node=None
  48.         temp.next_node=next_node
  49.  
  50.     def menu(self):
  51.         os.system('cls')
  52.         print("---------------------------------FORM REGISTER BOOK APPLICATION---------------------------------")
  53.         print("==================================================================")
  54.         print("\t Menu : ")
  55.         print(" 1. Registrasi Buku Baru")
  56.         print(" 2. Hapus Data Buku")
  57.         print(" 3. Report Modul Data Buku")
  58.         print(" 4. EXIT")
  59.         print("==================================================================")
  60.         print("------------------------------------------------------------------------------------------------")
  61.  
  62.         menu1=int(input("Masukan Nomor pada pilihan menu : "))
  63.         if menu1==1:
  64.             while True:
  65.                 os.system('cls')
  66.                 print("---------------------------------REGISTER NEW BOOK---------------------------------")
  67.                 print("0. Back to Main Menu")
  68.                 print("")
  69.                 judul=str(input("Masukan Judul Buku: "))
  70.                 if judul=="0":
  71.                     self.menu()
  72.                 else:
  73.                     self.regbuku(judul)
  74.                 digit=random.randint(0,999999)
  75.                 print("Kode Registrasi: ",digit)
  76.                 print("\n")
  77.         elif menu1==2:
  78.             os.system('cls')
  79.             print("---------------------------------DELETE DATA BUKU---------------------------------")
  80.             print("------------------------------------------------------------------------------")
  81.             print("| KODE REGISTRASI |      | \tNAMA BUKU\t |       | TANGGAL INPUT |")
  82.             print("| \t {} \t  | \t \t| \t {}\t  \t |\t \t| \t {}\t|")
  83.             # self.result()
  84.             print("------------------------------------------------------------------------------")
  85.             print("------------------------------------------------------------------------------")
  86.             print("0. Back to Main Menu")
  87.             print("")
  88.  
  89.             hapus=str(input("Masukan Code Registrasi buku yang akan dihapus: "))
  90.             if judul=="0":
  91.                 self.menu()
  92.             else:
  93.                 self.hapusBuku(hapus)
  94.                 self.showData()
  95.         elif menu1==3:
  96.             os.system('cls')
  97.             x=datetime.datetime.now()
  98.             print("---------------------------------DETAIL REPORT MODUL DATA BUKU---------------------------------")
  99.             print("")
  100.             print("-----------------------------------------------------------------------------------------")
  101.             print("| KODE REGISTRASI |      | \tNAMA BUKU\t |       | TANGGAL INPUT |")
  102.             self.showData()
  103.             print("-----------------------------------------------------------------------------------------")
  104.             print("-----------------------------------------------------------------------------------------------")
  105.             back=int(input("Tekan 0 untuk kembali ke Main Menu = "))
  106.             if back=="0":
  107.                 self.menu()
  108.             else:
  109.                 print("Perintah Salah")
  110.                 #print(ct) #countdown
  111.                 self.menu()
  112.         elif menu1==4:
  113.             os.system('cls')
  114.  
  115.         else:
  116.             print("Salah Input")
  117.             self.menu()
  118.  
  119.     def showData(self):
  120.         x=datetime.datetime.now()
  121.         CNode=self.head
  122.         if(self.head is None):
  123.             print("Data Not Exist")
  124.         else:
  125.             while CNode is not None:
  126.                 print("| \t {} \t  | \t \t| \t {}\t  \t |\t \t| \t test\t|",CNode.data,CNode.data,)
  127.                 # print(CNode.data,'\n')
  128.                 CNode=CNode.next_node
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement