Note that there are some explanatory texts on larger screens.

plurals
  1. POInner use of methods in the class- Java
    primarykey
    data
    text
    <p>I wrote a class that implements some kind of method providing specific service to the specific values that will be from this kind of class that I wrote.</p> <p>Now I want to use this utility for another method within the same class.</p> <p>The class using a string for the implemetion, I mean that it's only private value is a string. Let's call it String1</p> <p>the first method that I wrote, let's call it Method1 gets int, and doing some actions to this.String1 and returns an int as well.</p> <p>Now, I'm trying to Implement Method2 and I need to use Method1 in order to get what I want.</p> <p>Method2 afcourse uses this.String1 but in order to use this Method1 you need to be from this new class type.</p> <p>What should I do?</p> <p>I hope it's clear and Thank you.</p> <p>Ok, so this is the code:</p> <pre><code>public class IPAddressString { private String IpAdress; public IPAddressString(int num1, int num2, int num3, int num4) { this.IpAdress = num1 + "." + num2 + "." + num3 + "." + num4; } public String toString() { return this.IpAdress; } public boolean equals(IPAddress other) { return ((other.toString()).equals(IpAdress)); } public int getOctet(int index) { StringBuffer buf = new StringBuffer(); int point = index; int countPoints = 0; for (int i = 0; i &lt;= IpAdress.length() - 1; i++) { if ((IpAdress.charAt(i)) == '.') { countPoints++; } if ((countPoints == point) &amp;&amp; IpAdress.charAt(i) != '.') { buf.append(IpAdress.charAt(i)); } } String result = buf.toString(); return Integer.parseInt(result); } public boolean isPrivateNetwork(){ } </code></pre> <p>}</p> <p>I need isPrivateNetwork to use getOctet. isPrivareNetwork will do things according to a result that is get by using getOctet on a string (string1.getOctet) after we set string1 to be IPAddressString type. the string that I use through writing the class is a string type and not a IPAddressString type obivously. Is it more clear? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload