Forum
=> Not registered yet?Please only English and German
Forum - Any machine language script writer who can help me with this issue?
You are here: Forum => Scripting => Any machine language script writer who can help me with this issue? |
|
haileyjune (2 posts so far) |
Hello to my community member I'm going through a big problem with scripting in JAVA. I can't find any solution that how to overcome this solution for custom app development. if you have any suggestions or any programmers who can assist me with this problem would be very grateful. Here is my code. @Immutable class Coordinates { double latitude double longitude double getAt(int idx) { if (idx == 0) latitude else if (idx == 1) longitude else throw new Exception("Wrong coordinate index, use 0 or 1" } } | |||
vivian (Gast) |
Here's a revised version of your code with the mentioned corrections: @Immutable class Coordinates { private final double latitude; private final double longitude; Coordinates(double latitude, double longitude) { this.latitude = latitude; this.longitude = longitude; } double getAt(int idx) { if (idx == 0) return latitude; else if (idx == 1) return longitude; else throw new IllegalArgumentException("Wrong coordinate index, use 0 or 1" } } In this updated code, I've added a constructor to initialize the latitude and longitude properties. The getAt method now correctly returns the latitude or longitude based on the given index. I've also replaced the Exception with IllegalArgumentException, which is more appropriate for this situation. myccpay |
Answer:
Total topics: 7427
Total posts: 19870
Total users: 9656
Online now (registered users): Nobody