Exercise
Visual Basic (VB.Net) to Java
Objetive
Create a basic Visual Basic (VB.Net) to Java translator.
It must accept a Visual Basic (VB.Net) source files, and create an equivalent Java source file. It will receive the file name in the command line, and it must translate at least:
"Main()" into "main( String[] args )"
"string" into "String"
"bool" into "boolean"
"Console.WriteLine" into "System.out.println"
" : " into " extends " if it is in the same line as the word "class" (and any further improvements you may think of, such as strings handling, or converting a ReadLine to a try-catch block).
Code
Imports System
Imports System.IO
Class CSharpToJava
Private Shared Sub Main(ByVal args As String())
Dim line As String
Dim name As String
If args.Length < 1 Then
name = Console.ReadLine()
Else
name = args(0)
End If
Dim iFile As StreamReader = File.OpenText(name)
Dim oFile As StreamWriter = File.CreateText(name & ".java")
Do
line = iFile.ReadLine()
If line IsNot Nothing Then
line = line.Replace("bool ", "boolean ")
line = line.Replace("string ", "String ")
line = line.Replace("Console.WriteLine", "System.out.println")
oFile.WriteLine(line)
End If
Loop While line IsNot Nothing
iFile.Close()
oFile.Close()
End Sub
End Class