Volt package added

This commit is contained in:
LinlyBoi
2022-01-28 23:04:00 +02:00
parent 3173c9caa1
commit 7335f69a53
3 changed files with 132 additions and 0 deletions

View File

@@ -48,5 +48,15 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

82
src/voltag/volt.java Normal file
View File

@@ -0,0 +1,82 @@
package voltag;
import java.util.Arrays;
public class volt
{
double[] voltage = new double[72];
double mean;
public volt(){}
public volt(double[] Voltage)
{
this.voltage=Voltage;
}
public double calc_mean()
{
double avg=0;
for (int i=0;i<voltage.length;i++)
{
avg+=voltage[i];
}
mean = avg/72;
return getMean();
}
public double getMean()
{
return mean;
}
public void setMean(double newmean)
{
mean = newmean;
}
public String report()
{
//hours more than mean by 10%
double[] hours10 = new double[72];
double bigger = 1.10 * mean;
double smaller = 0.90 * mean;
int count = 0;
for(int i = 0; i < voltage.length; i++)
{
if(voltage[i] > bigger || voltage[i] < smaller )
{
hours10[count] = voltage[i];
count++;
}
}
//from one to another by 15%
double[] hours15 = new double[72];
int count2 = 0;
while(count2 < 71)
{
for(int j = 0; j < voltage.length; j++)
{
int limit = voltage.length - 2;
if(j <= limit)
{
double change = Math.abs(voltage[j] - voltage[j + 1]);
if(change > mean * 1.15)
{
hours15[j] = voltage[j];
hours15[j+1] = voltage[j+1];
}
}
}
count2++;
}
return "The hours more than 10% of mean are: " + Arrays.toString(hours10) + "\nAdjacent hours of voltage difference more than 15% of mean are: " + Arrays.toString(hours15);
}
}

40
src/voltag/voltTest.java Normal file
View File

@@ -0,0 +1,40 @@
package voltag;
import java.util.Arrays;
import java.util.Random;
import static org.junit.Assert.*;
public class voltTest
{
@org.junit.Test
public void calc_mean()
{
Random r = new Random();
double[] feb = new double[72];
Arrays.fill(feb, 100);
volt v1 = new volt(feb);
v1.calc_mean();
double mean = v1.getMean();
assertEquals(100,v1.getMean(),0);
}
@org.junit.Test
public void report()
{
Random r = new Random();
double[] hours = new double[72];
for(int i = 0; i < hours.length; i++)
hours[i] = r.nextInt(50,80);
volt v1 = new volt(hours);
v1.setMean(10);
System.out.println(v1.report());
}
}