Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting a method to calculate length/average
    primarykey
    data
    text
    <p>I am trying to write a class with all the methods I need for my main, but am having trouble figuring out how to ascertain the desired values using the methods. The ones I am having trouble with are getAverageLength and getCount.</p> <p>Current Output:</p> <pre><code>The length of Line 1 is 1.0 The length of Line 2 is 10.0 There are 0 lines and the average length is 0 The length of Line 1 is 1.0 The length of Line 2 is 10.0 The length of Line 3 is 7.0 There are 0 lines and the average length is 0 </code></pre> <p>Expected Output:</p> <pre><code>The length of Line 1 is 1 The length of Line 2 is 10 There are 2 lines and the average length is 5.5 The length of Line 1 is 7 The length of Line 2 is 10 The length of Line 3 is 7 There are 3 lines and the average length is 8.0 </code></pre> <p>This is the portion of my main method that I am using.</p> <pre><code>public class TestParts { public static void main(String[] args) { MyLine ml1 = new MyLine(); MyLine ml2 = new MyLine(10); System.out.println("The length of Line 1 is " + ml1.getLength()); System.out.println("The length of Line 2 is " + ml2.getLength()); System.out.println("There are " + MyLine.getCount() + " lines and the average length is " + MyLine.getAverageLength()); MyLine ml3 = new MyLine(7); ml1.setLength(7); System.out.println("The length of Line 1 is " + ml1.getLength()); System.out.println("The length of Line 2 is " + ml2.getLength()); System.out.println("The length of Line 3 is " + ml3.getLength()); System.out.println("There are " + MyLine.getCount() + " lines and the average length is " + MyLine.getAverageLength()); } } </code></pre> <p>And the following is the seperate class that I am writing to calculate the values.</p> <pre><code>class MyLine { private double getLength; MyLine() { getLength = 1; } double getLength() { return getLength; } MyLine(double setLength) { getLength = setLength; } public void setLength(int i) { getLength = getLength(); } public static int getCount() { return 0; } public static int getAverageLength() { return 0; } } </code></pre>
    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.
    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