Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a project named StatisticsDemo that i1lustrates the use of interfaces. Th

ID: 3884352 • Letter: C

Question

Create a project named StatisticsDemo that i1lustrates the use of interfaces. This project will have the following: 1) An interface named Measurables with the following abstract methods: int getFirstInt 0 int getSecondInt ) int getThirdInt () double getDouble() 2) A class named student that implements the Measurables and Comparable interfaces. The student class will have the following: a) Instance variables: private String name: private int examli private int exam2: private int finalExam private double courseGrade: b) A conatruetor with four input parameters that give the values of name, examl, exam2, and finalBxam. The constructor does not have an input variable for the value of courseGrado.-Instead,the constructor vrill calculate courseGrade as the average o examl, exam2, and finalExcam c) Methods: public int getFirstInt 11 returns examl public int getsecondInt) // returns exam2 public int getThirdInt) /1 returns finalExam public double getDouble) // returns courseGrade public int compareTo (Object otherobject) /I compares two Student objects // by courseGrade public string tostring) I1 defines a string to print a Student object // as shown in the output

Explanation / Answer

All your classes with output are given below. One point to note. Chegg does not allow to submit answers that have the word (e x a m) in it. So i had to put an underscore in that word wherever it appears. please remove it and use the code.

PROGRAM CODE:

Measurables.java

package StatisticsDemo;

public interface Measurables {

      

   int getFirstInt();

   int getSecondInt();

   int getThirdInt();

   double getDouble();

}

Student.java

package StatisticsDemo;

public class Student implements Measurables, Comparable<Student>{

   private String name;

   private int ex_am1;

   private int ex_am2;

   private int finalex_am;

   private double courseGrade;

  

  

   public Student(String name, int ex_am1, int ex_am2, int finalex_am) {

       this.name = name;

       this.ex_am1 = ex_am1;

       this.ex_am2 = ex_am2;

       this.finalex_am = finalex_am;

       this.courseGrade = (ex_am1 + ex_am2 + finalex_am)/3;

   }

   @Override

   public int compareTo(Student o) {

       if(this.courseGrade == o.getDouble())

           return 0;

       else if(this.courseGrade < o.getDouble())

           return -1;

       else return 1;

   }

   @Override

   public int getFirstInt() {

      

       return ex_am1;

   }

   @Override

   public int getSecondInt() {

  

       return ex_am2;

   }

   @Override

   public int getThirdInt() {

  

       return finalex_am;

   }

   @Override

   public double getDouble() {

      

       return courseGrade;

   }

   @Override

   public String toString() {

       // TODO Auto-generated method stub

       return "(" + name + " " + ex_am1 + "," + ex_am2 + "," + finalex_am + "," + courseGrade + ")";

   }

}

Employee.java

package StatisticsDemo;

public class Employee implements Measurables, Comparable<Employee>{

   private String name;

   private int hours;

   private int rate;

   private int sales;

   private double netPay;

  

  

   public Employee(String name, int hrs, int rate, int sales) {

       this.name = name;

       this.hours = hrs;

       this.rate = rate;

       this.sales = sales;

       double wages;

       if(hours<=40)

           wages = rate*hours;

       else if(hours > 40 && hours<=60)

           wages = rate*40 + 1.5 *rate*(hours-40);

       else

           wages = rate*40 + 1.5*rate*20 + 2*rate*(hours-60);

      

       double commission = 0.15*sales;

       double grossPay = wages + commission;

       double withholdingTax = 0.18*grossPay;

       netPay = grossPay - withholdingTax;

   }

  

   @Override

   public int compareTo(Employee o) {

       if(this.netPay == o.getDouble())

           return 0;

       else if(this.netPay < o.getDouble())

           return -1;

       else return 1;

   }

   @Override

   public int getFirstInt() {

       return hours;

   }

   @Override

   public int getSecondInt() {

       return rate;

   }

   @Override

   public int getThirdInt() {

       return sales;

   }

   @Override

   public double getDouble() {

       return netPay;

   }

   @Override

   public String toString() {

       // TODO Auto-generated method stub

       return "(" + name + " " + hours + "," + rate + "," + sales + "," + netPay + ")";

   }

}

StatisticsDemo.java

package StatisticsDemo;

import java.util.Arrays;

public class StatisticsDemo {

   public static double[] averages(Measurables[] objects)

   {

       double avg1 = 0,avg2 = 0,avg3 = 0,avg4 = 0;

       for(int i=0; i<objects.length; i++)

           avg1 += objects[i].getFirstInt();

       for(int i=0; i<objects.length; i++)

           avg2 += objects[i].getSecondInt();

       for(int i=0; i<objects.length; i++)

           avg3 += objects[i].getThirdInt();

       for(int i=0; i<objects.length; i++)

           avg4 += objects[i].getDouble();

      

       avg1 /= objects.length;

       avg2 /= objects.length;

       avg3 /= objects.length;

       avg4 /= objects.length;

      

       return new double[]{avg1, avg2, avg3, avg4};

   }

  

   public static double median(Measurables[] objects)

   {

       Arrays.sort(objects);

       double median;

       if(objects.length%2 == 0)

       {

           median = (objects[objects.length/2].getDouble() + objects[(objects.length/2)+1].getDouble())/2;

       }

       else

           median = objects[(objects.length/2) + 1].getDouble();

       return median;

   }

  

   public static void main(String[] args) {

       Student studs[] = {new Student("Mary", 85,93, 97), new Student("Bob", 67,77 ,71 ),

                           new Student("Tom", 85, 91, 89), new Student("Anna", 79, 72, 80),

                           new Student("Hal", 96, 88, 99), new Student("Gina", 89, 91, 82)};

      

  

       System.out.println("Students: " + Arrays.toString(studs));

       double averages[] = averages(studs);

       System.out.printf("Average ex_am 1 Grade = %.2f " , averages[0]);

       System.out.printf("Average ex_am 2 Grade = %.2f " , averages[1]);

       System.out.printf("Average Final ex_am Grade = %.2f " , averages[2]);

       System.out.printf("Average Course Grade = %.2f " , averages[3]);

       System.out.println("Students: " + Arrays.toString(studs));

       System.out.println("Median of Course Grades = " + median(studs));

      

       Employee employees[] = {new Employee("Sara", 68,19, 5473), new Employee("Lisa", 47,16 ,3892 ),

               new Employee("Sam", 51, 18, 5829), new Employee("Jim", 33, 21, 4857),

               new Employee("Judy", 39, 23, 4295)};

       System.out.println(" Employees: " + Arrays.toString(employees));

       double averages2[] = averages(employees);

       System.out.println("Average Hours = $" + averages2[0]);

       System.out.println("Average Rate = $" + averages2[1]);

       System.out.println("Average Sales = $" + averages2[2]);

       System.out.println("Average Net Pay = $" + averages2[3]);

       System.out.println("Employees: " + Arrays.toString(employees));

       System.out.println("Median of Net Pay = $" + median(employees));

   }

}

OUTPUT:

Students: [(Mary 85,93,97,91.0), (Bob 67,77,71,71.0), (Tom 85,91,89,88.0), (Anna 79,72,80,77.0), (Hal 96,88,99,94.0), (Gina 89,91,82,87.0)]

Average ex_am 1 Grade = 83.50

Average ex_am 2 Grade = 85.33

Average Final ex_am Grade = 86.33

Average Course Grade = 84.67

Students: [(Mary 85,93,97,91.0), (Bob 67,77,71,71.0), (Tom 85,91,89,88.0), (Anna 79,72,80,77.0), (Hal 96,88,99,94.0), (Gina 89,91,82,87.0)]

Median of Course Grades = 89.5

Employees: [(Sara 68,19,5473,2013.0589999999997), (Lisa 47,16,3892,1141.276), (Sam 51,18,5829,1550.907), (Jim 33,21,4857,1165.671), (Judy 39,23,4295,1263.825)]

Average Hours = $47.6

Average Rate = $19.4

Average Sales = $4869.2

Average Net Pay = $1426.9476

Employees: [(Sara 68,19,5473,2013.0589999999997), (Lisa 47,16,3892,1141.276), (Sam 51,18,5829,1550.907), (Jim 33,21,4857,1165.671), (Judy 39,23,4295,1263.825)]

Median of Net Pay = $1550.907

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote