Haze-Growroom Community

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?

<-Back

 1 

Continue->


haileyjune
(2 posts so far)
08.12.2022 14:18 (UTC)[quote]
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)
08.07.2023 09:22 (UTC)[quote]
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:

Nickname:

 Text color:

 Font size:
Close tags



Total topics: 3050
Total posts: 8420
Total users: 2615
Online now (registered users): Nobody crying smiley
Diese Webseite wurde kostenlos mit Homepage-Baukasten.de erstellt. Willst du auch eine eigene Webseite?
Gratis anmelden