The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 364 Weeks Ago, 2 Days Ago |
| Questions Answered: | 1850 |
| Tutorials Posted: | 1850 |
Graduate in Biology and Nutrition, MBA Finance
Florida State University
Aug-2000 - Jul-2007
Ass. Relationship Manager
Penn-Florida
Mar-2009 - Feb-2016
A lab that combines various elements of OOP programming through the use of several different methods. I have already created code for this lab that seems right for the most part but there are some inaccuracies within it. That don't give me the correct output answers in the main method according to the rubric. You can adjust my code or create a new program, it doesn't matter to me. Thanks and I look forward to a responseÂ
/*
* Stat.java
* Author: Will Jenkins
* Submission Date: 11-11-16
*
* Purpose: This program is supposed to allow for more
* practice with the UML diagram. A stat class is supposed to be created
* with various arrays, getters, and setter methods.Â
*Â
* Statement of Academic Honesty:
*
* The following code represents my own work. I have neither
* received nor given inappropriate assistance. I have not copied
* or modified code from any source other than the course webpage
* or the course textbook. I recognize that any unauthorized
CSCI 1301: Project 1 Page 3
* assistance or plagiarism will be handled in accordance with
* the University of Georgia's Academic Honesty Policy and the
* policies of this course. I recognize that my work is based
* on an assignment created by the Department of Computer
* Science at the University of Georgia. Any publishing
* or posting of source code for this project is strictly
* prohibited unless you have written consent from the Department
* of Computer Science at the University of Georgia.
*/
Â
public class Stat {
Â
private double [] data;
Â
Â
public Stat(){
data = new double[1];
data[0] = 0.0;
}
Â
public Stat(double [] d){
data = new double[d.length];
for(int i=0; i < d.length; i++){
data[i] = d[i];
}
}
Â
public Stat(float [] d){
data = new double[d.length];
for(int i=0; i < d.length; i++){
data[i] = d[i];
}
}
Â
public Stat(int [] d){
data = new double[d.length];
for(int i=0; i < d.length; i++){
data[i] = d[i];
}
}
Â
public Stat(long [] d){
data = new double[d.length];
for(int i=0; i < d.length; i++){
data[i] = d[i];
}
}
Â
public double[] getData(){
double[] data2 = new double[data.length];
for (int i=0; i < data.length; i++){
data2[i] = data[i];
}
return data2;
}
Â
public void setData(double d []){
double [] newdata = new double[d.length];
for(int i=0; i < d.length; i++){
newdata[i] = d[i];
}
data = newdata;
}
Â
public void setData(float d []){
double [] newdata = new double[d.length];
for(int i=0; i < d.length; i++){
newdata[i] = d[i];
}
data = newdata;
}
Â
public void setData(int d []){
double [] newdata = new double[d.length];
for(int i=0; i < d.length; i++){
newdata[i] = d[i];
}
data = newdata;
}
Â
public void setData(long d []){
double [] newdata = new double[d.length];
for(int i=0; i < d.length; i++){
newdata[i] = d[i];
}
data = newdata;
}
Â
public boolean equals(Stat s){
int counter = 0;
if (!(s.data.length == data.length)){
return false;
}
else{
for(int i=0; i < data.length; i++){
if (s.data[i] == data[i]){
counter++;
}
}
}
if (counter == data.length){
return true;
}
else {
return false;
}
}
Â
public void reset(){
double [] data2 = {};
data = data2;
}
public void append(int [] d){
if (d != null){
double [] newarray = new double [d.length + data.length];
for (int i = 0; i < data.length; i++){
newarray[i] = data[i];
}
for (int i = 0; i < d.length; i++){
newarray[data.length] = d[i];
}
data = newarray;
}
}
Â
public void append(float [] d){
if (d != null){
double [] newarray = new double [d.length + data.length];
for (int i = 0; i < data.length; i++){
newarray[i] = data[i];
}
for (int i = 0; i < d.length; i++){
newarray[data.length] = d[i];
}
data = newarray;
}
}
Â
public void append(long [] d){
if (d != null){
double [] newarray = new double [d.length + data.length];
for (int i = 0; i < data.length; i++){
newarray[i] = data[i];
}
for (int i = 0; i < d.length; i++){
newarray[data.length] = d[i];
}
data = newarray;
}
}
Â
Â
public void append(double [] d){
if (d != null){
double [] newarray = new double [d.length + data.length];
for (int i = 0; i < data.length; i++){
newarray[i] = data[i];
}
for (int i = 0; i < d.length; i++){
newarray[data.length] = d[i];
}
data = newarray;
}
}
Â
public boolean isEmpty(){
if (data.length == 0 ){
return true;
}
else {
return false;
}
}
Â
public String toString(){
String s = "";
Â
if(data.length > 0){
for (int i=0; i < (data.length - 1); i++){
Â
s += data[i] + ", ";
}
s += data[data.length - 1];
}
Â
if (data.length == 0){
s = " ";
Â
}
return "[" + s + "]";
}
Â
public double min(){
double min = 0;
if (data.length > 0){
min = data[0];
Â
for (int i = 0; i < data.length; i++){
if (data[i] < min){
min = data[i];
}
}
}
if (data.length == 0){
min = Double.NaN;
}
return min;
}
Â
public double max(){
double max = -100000000;
if (data.length == 0){
max = Double.NaN;
}
if (data.length > 0){
for (int i = 0; i < data.length; i++){
if (data[i] > max){
max = data[i];
}
}
}
return max;
}
Â
public double average(){
double average = Double.NaN ;
if (data.length == 0){
average = Double.NaN;
}
if (data.length > 0){
double sum = 0;
for (int i = 0; i < data.length; i++){
sum += data[i];
}
average = sum / data.length;
}
return average;
}
Â
public double mode(){
double maxValue = 0, maxCount = 0;
if(data.length == 0){
maxValue = Double.NaN;
}
Â
  for (int i = 0; i < data.length; ++i) {
    int count = 0;
    for (int j = 0; j < data.length; ++j) {
      if (data[j] == data[i])
      ++count;
    }
    if (count > maxCount) {
      maxCount = count;
      maxValue = data[i];
    }
    if ((maxCount == count) && (data[i] != maxValue)){
    maxValue = Double.NaN;
    }
   Â
  }
  return maxValue;
}
Â
public double variance(){
double variance = Double.NaN;
if (data.length == 0){
variance = Double.NaN;
}
if (data.length > 0){
double sum = 0;
double sumupdate = 0;
for (int i = 0; i < data.length; i++){
sum += data[i];
}
double average = sum / data.length;
for (int i = 0; i < data.length; i++){
sumupdate += (data[i] - average) * (data[i] - average);
}
variance = sumupdate/data.length;
}
return variance;
Â
Â
}
Â
public double standardDeviation(){
if (data.length == 0){
return Double.NaN;
}
else{
double sum = 0;
double sumupdate = 0;
for (int i = 0; i < data.length; i++){
sum += data[i];
}
double average = sum / data.length;
for (int i = 0; i < data.length; i++){
sumupdate += (data[i] - average) * (data[i] - average);
}
double variance = sumupdate/data.length;
double stdev = Math.sqrt(variance);
return stdev;
}
}
public static void main(String[] args) {
Â
Â
double[] data = {-5.3, 2.5, 88.9, 0, 0.0, 28, 16.5, 88.9, 109.5, -90, 88.9}; Stat stat1 = new Stat();
/*System.out.println("stat1 data = " + stat1.toString()); stat1.append(data);
System.out.println("stat1 has been altered.");
System.out.println("stat1 data = " + stat1.toString());
System.out.println("stat1 min = " + stat1.min());
System.out.println("stat1 max = " + stat1.max());
System.out.println("stat1 average = " + stat1.average());
System.out.println("stat1 mode = " + stat1.mode());
System.out.println("stat1 variance = " + stat1.variance());
System.out.println("stat1 standard deviation = " + stat1.standardDeviation() + "\n");*/
Â
float[] data1 = {10.0F,10.0F};
Stat stat1 = new Stat(data1);
System.out.println("stat1 data = " + stat1.toString());
System.out.println("stat1 min = " + stat1.min());
System.out.println("stat1 max = " + stat1.max());
System.out.println("stat1 average = " + stat1.average());
System.out.println("stat1 mode = " + stat1.mode());
System.out.println("stat1 variance = " + stat1.variance());
System.out.println("stat1 standard deviation = " + stat1.standardDeviation() + "\n");
long[] data2 = {80L, 60L};
stat1.append(data2);
System.out.println("stat1 data" + stat1.toString());
Â
Â
Â
Â
Â
System.out.println("stat1 min = " + stat1.min());
System.out.println("stat1 max = " + stat1.max());
System.out.println("stat1 average = " + stat1.average());
System.out.println("stat1 mode = " + stat1.mode());
System.out.println("stat1 variance = " + stat1.variance());
System.out.println("stat1 standard deviation = " + stat1.standardDeviation() + "\n");Â
Â
Â
}
}
Â
Â
Â
Â
public class StatTester{
Â
public static void main(String[] args) {
double[]data1={50.0,60.0};
float[]data2={70.0F,80.0F};
int[]data3={90,100};
long[]data4={100L,110L};
Statstat1=new Stat();
System.out.println("stat1data=" + stat1.toString());
stat1.setData(data1);
System.out.println("stat1data=" + stat1.toString());
stat1.setData(data2);
System.out.println("stat1data=" + stat1.toString());
stat1.setData(data3);
System.out.println("stat1data=" + stat1.toString());
stat1.setData(data4);
System.out.println("stat1data=" + stat1.toString());
data1=null;
stat1.setData(data1);
System.out.println("stat1data=" + stat1.toString());
Â
}
Â
}
Â
Attachments:Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- -----------Tha-----------nk -----------you----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m Â----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I