Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// ClockDriver Tester 1 public class ClockDriver { 2 3 public static void main(String[] args) { 4 5 BasicClockType[] tester1 = {new BasicClockType(12, 30), new

// ClockDriver Tester

image text in transcribedimage text in transcribed 1 public class ClockDriver {

2 3 public static void main(String[] args) { 4 5 BasicClockType[] tester1 = {new BasicClockType(12, 30), new BasicClockType(12, 30), new BasicClockType(1, 30), new BasicClockType(12, 32)}; 6 7 testMethodBase(tester1, "basic clock tests:"); 8 9 BasicClockType[] tester2 = {new ClockSecondsType(12, 30, 45), new ClockSecondsType(12, 30, 45), new ClockSecondsType(1, 30, 45), new ClockSecondsType(12, 32, 45), new ClockSecondsType(12, 30, 46)}; 10 11 testMethodBase(tester2, "clock seconds tests:"); 12 testMethodSeconds(tester2); 13 14 BasicClockType[] tester3 = {new StopwatchClockType(12, 30, 45, 7), new StopwatchClockType(12, 30, 45, 7), new StopwatchClockType(1, 30, 45, 7), 15 new StopwatchClockType(12, 32, 45, 7), new StopwatchClockType(12, 30, 46, 7), new StopwatchClockType(12, 30, 46, 9)}; // set up appropriate array 16 testMethodBase(tester3, "stopwatch tests:"); 17 testMethodSeconds(tester3); 18 testMethodDeciseconds(tester3); 19 20 BasicClockType[] tester4 = {new DateTimeType(12, 30, 45, 15, 3, 2018), new DateTimeType(12, 30, 45, 15, 3, 2018), new DateTimeType(1, 30, 45, 15, 3, 2018), 21 new DateTimeType(12, 32, 45, 15, 3, 2018), new DateTimeType(12, 30, 46, 15, 3, 2018), new DateTimeType(12, 30, 46, 20, 3, 2018), 22 new DateTimeType(12, 30, 46, 15, 5, 2018), new DateTimeType(12, 30, 46, 15, 3, 2022)}; // set up appropriate array 23 testMethodBase(tester4, "date-time tests:"); 24 testMethodSeconds(tester4); 25 testMethodDateTime(tester4); 26 27 // exception tests 28 int num = 1; 29 checkExceptions(tester1, tester2, num++); 30 checkExceptions(tester2, tester3, num++); 31 checkExceptions(tester3, tester4, num++); 32 checkExceptions(tester4, tester1, num++); 33 checkExceptions(tester2, tester1, num++); 34 checkExceptions(tester3, tester2, num++); 35 checkExceptions(tester4, tester3, num++); 36 checkExceptions(tester1, tester4, num++); 37 } 38 39 public static void checkExceptions(BasicClockType[] one, BasicClockType[] two, int num) { 40 41 try { 42 int a = one[0].compareTo(two[0]); 43 } 44 catch(ClassCastException ex) { 45 System.out.println("exception test " + num + "passed"); 46 } 47 System.out.println("exception test " + num + "failed"); 48 } 49 50 public static void testMethodBase(BasicClockType[] tester, String testType) { 51 52 System.out.println(testType); 53 // equal test 54 if (tester[0].compareTo(tester[1]) == 0) 55 System.out.println("test 1 passed"); 56 else 57 System.out.println("test 1 failed"); 58 59 // greater than hours 60 if (tester[0].compareTo(tester[2]) > 0) 61 System.out.println("test 2 passed"); 62 else 63 System.out.println("test 2 failed"); 64 65 // greater than minutes 66 if (tester[3].compareTo(tester[0]) > 0) 67 System.out.println("test 3 passed"); 68 else 69 System.out.println("test 3 failed"); 70 71 // less than hours 72 if (tester[2].compareTo(tester[0]) 0) 88 System.out.println("test 6 passed"); 89 else 90 System.out.println("test 6 failed"); 91 92 // less than seconds 93 if (tester[0].compareTo(tester[4]) 0) 103 System.out.println("test 8 passed"); 104 else 105 System.out.println("test 8 failed"); 106 107 // less than seconds 108 if (tester[0].compareTo(tester[5])

/// HourlyWorkher.java 2 public class HourlyWorker { 3 4 private String name; 5 private int id; 6 private double hourlyRate; 7 private double[] hoursWorked; 8 private static int COUNT = 0; 9 10 public HourlyWorker() { 11 this("Stranger",0.01,new double[7]); 12 } 13 14 public HourlyWorker(String name, double hourlyRate, double[] hoursWorked) { 15 this.name = name; 16 this.id = COUNT++; 17 this.hourlyRate = hourlyRate; 18 this.hoursWorked = hoursWorked; 19 } 20 21 public String getName() { 22 return name; 23 } 24 25 public int getId() { 26 return id; 27 } 28 29 public double getHourlyRate() { 30 return hourlyRate; 31 } 32 33 public double[] getHoursWorked() { 34 return hoursWorked; 35 } 36 37 public void setName(String name) { 38 this.name = name; 39 } 40 41 public void setHourlyRate(double newRate) { 42 hourlyRate = newRate; 43 } 44 45 @Override 46 public String toString() { 47 return "Worker name = " + name + " ID = " + id + " Hourly Rate = " + hourlyRate + " Hours Worked = " + this.calculateHours(); 48 } 49 50 public void setHours(int day, double newHours) { 51 if (day > 0 && day 0 && day 40) { 75 return ((hours - 40) * 1.25 * hourlyRate) + (40 * hourlyRate); 76 } else { 77 return hours * hourlyRate; 78 } 79 } 80 }

//BasickClockType

2 public class BasicClockType { 3 4 private int hours; 5 private int minutes; 6 7 public BasicClockType() { 8 hours = 0; 9 minutes = 0; 10 } 11 12 public BasicClockType(int newHours, int newMinutes) { 13 hours = newHours; 14 minutes = newMinutes; 15 } 16 17 public BasicClockType(BasicClockType other) { 18 this(other.hours, other.minutes); 19 } 20 21 public int getHours() { 22 return hours; 23 } 24 25 public void setHours(int newHours) { 26 hours = newHours; 27 } 28 29 public int getMinutes() { 30 return minutes; 31 } 32 33 public void setMinutes(int newMinutes) { 34 minutes = newMinutes; 35 } 36 37 public String toString() { 38 String representation = ""; 39 if(hours

/// MoneyType.java

2 public class MoneyType { 3 4 private int dollars; 5 private int cents; 6 7 public MoneyType() { 8 this(0, 0); 9 } 10 11 public MoneyType(int d, int c) { 12 if (d = 100) { 35 dollars++; 36 c-=100; 37 } 38 cents = c; 39 } 40 41 public int getCents() { 42 return cents; 43 } 44 45 public MoneyType add(MoneyType other) { 46 return new MoneyType(dollars + other.getDollars(), cents + other.getCents()); 47 } 48 49 @Override 50 public String toString() { 51 return String.format("$%d:%02d", dollars, cents); 52 } 53 }

// ClockDriver Tester

Given the base class BasicClockType.java, Implement the rest of the class hierarchy from part 4 of lab 5. Add an equals method to each class in this hierarchy so that objects created on this template can only be equal if their contents are same and they are of the same exact type, e.g. an object of type BasicClockType can never be equal to an object of any other type, including its children instances Given the base class BasicClockType.java, Implement the rest of the class hierarchy from part 4 of lab 5. Add an equals method to each class in this hierarchy so that objects created on this template can only be equal if their contents are same and they are of the same exact type, e.g. an object of type BasicClockType can never be equal to an object of any other type, including its children instances

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

Can workers be trained in ethics? How? Defend your answer.

Answered: 1 week ago