Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

j2py not converting #69

Open
MrKomodoDragon opened this issue Nov 16, 2020 · 2 comments
Open

j2py not converting #69

MrKomodoDragon opened this issue Nov 16, 2020 · 2 comments

Comments

@MrKomodoDragon
Copy link

MrKomodoDragon commented Nov 16, 2020

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!

@ferchault
Copy link

Could it be related to #37? This line looks like it contains non-ascii characters

		System.out.println("•triangle\n•circle\n•rectangle\n•square\n•trapezoid\n");

@MrKomodoDragon
Copy link
Author

oh yea..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants