Open
Description
Hi,
I was attempting to use j2py to convert a simple Java program I made into python, but i got an error.
This is the Java code:
import java.util.Scanner;
public class areaCalculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println(
"Hello. I am a calculator that can calculate the area of shapes. All I need is for you to input what shape's area\nyou would like to convert from the following list: \n");
System.out.println("•triangle\n•circle\n•rectangle\n•square\n•trapezoid\n");
String shapeName = input.nextLine();
if (shapeName.equals("triangle")) {
System.out.println("What is the base of the triangle? ");
double triangleBase = input.nextDouble();
System.out.println("What is the height of the triangle? ");
double triangleHeight = input.nextDouble();
System.out.println("The area of the triangle is: " + (triangleBase * triangleHeight) / 2);
} else if (shapeName.equals("circle")) {
System.out.println("What is the radius of the circle? ");
double radius = input.nextDouble();
System.out.println("The area of the circle is: " + Math.PI * Math.pow(radius, 2));
} else if (shapeName.equals("rectangle")) {
System.out.println("What is the height of the rectangle? ");
double rectangleHeight = input.nextDouble();
System.out.println("What is the width of the rectangle? ");
double rectangleWidth = input.nextDouble();
System.out.print("The area of the rectangle is: " + rectangleHeight * rectangleWidth);
} else if (shapeName.equals("square")) {
System.out.println("What is the length of one side of the square? ");
double squareSide = input.nextDouble();
System.out.println("The area if the square is: " + Math.pow(squareSide, 2));
} else if (shapeName.equals("trapezoid")) {
System.out.println("What is one of the bases of the trapezoid? ");
double tBase1 = input.nextDouble();
System.out.println("What is another of the bases of the trapezoid? ");
double tBase2 = input.nextDouble();
System.out.println("What is the height of the trapezoid? ");
double tHeight = input.nextDouble();
System.out.println("The area of the trapezoid is: " + (tBase1 + tBase2) / 2 * tHeight);
} else {
System.out.println("Sorry. An error occured. Please try again");
}
}
}
When I try to run j2py areaCalculator.py
, it returns this error:
# ERROR runTransform: exception while parsing
Traceback (most recent call last):
File "/usr/local/bin/j2py", line 120, in runTransform
tree = buildAST(source)
File "/Users/vasan/Library/Python/2.7/lib/python/site-packages/java2python/compiler/__init__.py", line 15, in buildAST
lexer = Lexer(StringStream(source))
File "/Library/Python/2.7/site-packages/antlr_python_runtime-3.1.3-py2.7.egg/antlr3/streams.py", line 336, in __init__
self.strdata = unicode(data)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 362: ordinal not in range(128)
Can someone please help me figure out what the issue is? Thank you!
Metadata
Metadata
Assignees
Labels
No labels