You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importjava.util.Scanner;
publicclassareaCalculator {
publicstaticvoidmain(String[] args) {
Scannerinput = newScanner(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");
StringshapeName = input.nextLine();
if (shapeName.equals("triangle")) {
System.out.println("What is the base of the triangle? ");
doubletriangleBase = input.nextDouble();
System.out.println("What is the height of the triangle? ");
doubletriangleHeight = input.nextDouble();
System.out.println("The area of the triangle is: " + (triangleBase * triangleHeight) / 2);
} elseif (shapeName.equals("circle")) {
System.out.println("What is the radius of the circle? ");
doubleradius = input.nextDouble();
System.out.println("The area of the circle is: " + Math.PI * Math.pow(radius, 2));
} elseif (shapeName.equals("rectangle")) {
System.out.println("What is the height of the rectangle? ");
doublerectangleHeight = input.nextDouble();
System.out.println("What is the width of the rectangle? ");
doublerectangleWidth = input.nextDouble();
System.out.print("The area of the rectangle is: " + rectangleHeight * rectangleWidth);
} elseif (shapeName.equals("square")) {
System.out.println("What is the length of one side of the square? ");
doublesquareSide = input.nextDouble();
System.out.println("The area if the square is: " + Math.pow(squareSide, 2));
} elseif (shapeName.equals("trapezoid")) {
System.out.println("What is one of the bases of the trapezoid? ");
doubletBase1 = input.nextDouble();
System.out.println("What is another of the bases of the trapezoid? ");
doubletBase2 = input.nextDouble();
System.out.println("What is the height of the trapezoid? ");
doubletHeight = 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!
The text was updated successfully, but these errors were encountered:
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:
When I try to run
j2py areaCalculator.py
, it returns this error:Can someone please help me figure out what the issue is? Thank you!
The text was updated successfully, but these errors were encountered: