Raju Shahi
New member
I am a student from Sweden and i am making my first VB.net asigment, and that is to make a Mainpogram that start another program.What i seem to not understand (i have tryed several books and internet nowhere to find the answer) is how do i call i value or a data from Private to a method.
please se the codes here is the Mainprogram. I think this one is right.
Here is the class program that i have dificulty with. I am trying to get the quantity to display in the last printrecipt part and also to get the calculation result altso to show but nothing is displaying not even the customer name. What wrong have i made please help me i will be greatfull thanks.
please se the codes here is the Mainprogram. I think this one is right.
VB.NET:
Option Explicit On
Option Strict On
'GasStationProg.vb
'Created: by Raju Shahi 06/14/2011
Module GasStationProg
''' <summary>
''' This is where the program begins when started
''' </summary>
''' <remarks></remarks>
Sub Main()
Dim pump As GasPump ' Declare a referens variable
pump = New GasPump()
pump.Start()
'This make the Console window wait on the screen ("Read nothing")
Console.ReadKey()
End Sub
End Module
Here is the class program that i have dificulty with. I am trying to get the quantity to display in the last printrecipt part and also to get the calculation result altso to show but nothing is displaying not even the customer name. What wrong have i made please help me i will be greatfull thanks.
VB.NET:
Option Explicit On
Option Strict On
Class GasPump
'inputvariablar
Private customerName As String
'declare variable type
Private quantity As Double
'declare variable true or false
Private premiumQuality As Boolean
Private gasType As String
'declare total amount payed
Private totalToPay As Double
Const regularPrice As Double = 13.08 ' lund 2011-01-21
' 06/14/2011
Const primePrice As Double = 13.56
Property InputString As String
'Metod som sätter värden från inmatning av användare
Public Sub Start()
'1. ReadInput
ReadInput()
'2. calculate
CalcTotalToPay()
'3. Show results
PrintReceipt()
End Sub
Private Sub ReadInput()
'1. Read Customer name
ReadCustomerName()
'2. Read Quantity
ReadQuantity()
'3. Read Quality
ReadQuality()
End Sub
Private Sub ReadQuality()
Console.Write("Premium quality? (y/n): ")
Dim response As Char = Console.ReadLine().Chars(0)
If ((response = "y") Or (response = "Y")) Then
premiumQuality = True
Console.WriteLine("")
Console.WriteLine("your choice: Prime price!")
Console.WriteLine("")
Else
premiumQuality = False
Console.WriteLine("")
Console.WriteLine("your choice: Regular price")
Console.WriteLine("")
End If
End Sub
Private Sub WriteThankYou()
Console.WriteLine("Thank you, " & customerName)
End Sub
Private Sub ReadCustomerName()
Console.Write("Please let me know your full name:")
Dim customerName As String = Console.ReadLine()
WriteThankYou()
End Sub
Private Sub ReadQuantity()
Console.WriteLine("")
Console.Write("How many units whould you like (only whole numbers please)?")
Dim quantity As String = Console.ReadLine()
Console.WriteLine("")
Console.WriteLine("")
End Sub
Private Sub CalcTotalToPay()
If premiumQuality = True Then
totalToPay = quantity * primePrice
Else
totalToPay = quantity * regularPrice
End If
End Sub
Private Sub PrintReceipt()
Console.WriteLine("")
Console.WriteLine("")
'Tomma rader
Console.WriteLine("++++++++++++++++++++WELCOME TO RAJU SHAHIS GAS STATION+++++++++++++")
Console.WriteLine("")
If premiumQuality = True Then
'går också bra att skriva if (active)
Console.WriteLine("Quality Premium", premiumQuality)
Else
Console.WriteLine("Quality Regular", premiumQuality)
End If
Console.WriteLine("Quantity " & quantity.ToString())
Console.WriteLine("")
Console.WriteLine("")
If premiumQuality = True Then
Console.WriteLine("Price per unit 13.56", premiumQuality)
Else
Console.WriteLine("Price per unit 13.08", premiumQuality)
End If
Console.WriteLine("Sum to pay " & totalToPay)
Console.WriteLine("")
Console.WriteLine("")
Console.WriteLine("Welcome Back!", customerName)
Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
End Sub
End Class
Last edited: