2016-05-29 45 views
-1
Public Class pros_stack 
Dim stk As New Stack(Of barang) 

Private Sub beli(ByVal brg As barang) 
    stk.Push(brg) 
    stock += brg.jml 
End Sub 

Private Function jual() As barang 
    Dim hps As barang = stk.Pop 
    stock -= hps.jml 
    Return hps 
End Function 

Public Sub proses() 
    Dim putar As Boolean = True 
    Dim pilih As Integer 
    Dim new_brg As barang 
    ' 
    Console.Clear() 
    history.Clear() 
    ' 
    Try 
     Console.WriteLine("    Proses STACK") 
     Console.WriteLine("    ------------") 
     While putar 
      Console.WriteLine("    Menu") 
      Console.WriteLine("    1. Beli") 
      Console.WriteLine("    2. Jual") 
      Console.WriteLine("    3. Selesai") 
      Console.WriteLine() 
      Console.Write("Pilih : ") 
      pilih = Console.ReadLine 
      If pilih = 1 Then ' BELI 
       Console.WriteLine("    Proses Beli") 
       Console.WriteLine("    ----------") 
       Console.Write("Jumlah Barang : ") 
       new_brg.jml = Console.ReadLine 
       Console.Write("Harga Satuan : ") 
       new_brg.hrg = Console.ReadLine 

如何在Visual Basic中實現類似上面的堆棧代碼,有人可以給我參考。如何用多個變量推送數組對象。像new_brg.jml和new_brg.hrg一樣成爲java中的一個堆棧對象。implement從VisualBasic到Java的堆棧netbeans

回答

0

Java在.NET堆棧中的等價物是java.util.Stack。我還在下面包含了與Console.WriteLine和Console.ReadLine方法等效的內容。

import java.util.*; 

//stack: 
Stack<barang> stk = new Stack<barang>(); 
stk.push(b); 
b = stk.pop(); 

//console: 
System.out.println(d); 
x = new Scanner(System.in).nextLine();