Question

Task: Modify the Time class and add more methods. 3.1. The class Time (discussed in class)...

Task: Modify the Time class and add more methods.

3.1. The class Time (discussed in class) has 2 member methods equals and lessThan. It would be easier for the user to have access to new member methods notEquals, lessOrEquals, greaterThan, and greaterOrEquals. Hint: Don’t start from scratch; make use of the already existing methods.

public boolean notEquals(Time otherTime) {... }
public boolean lessOrEquals(Time otherTime) {... }
public boolean greaterThan(Time otherTime) {... }
public boolean greaterOrEquals(Time otherTime) {... }

3.2. Add 2 more methods named toMilitary and toStandard; they should return a String with the military and standard format for a Time object.

Modify the client for complete testing, including the new methods.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Time{

int time;

string s1,s2);

public time(Time t1)

{

time=t1;

s1=" ";

s2=" "

}

public boolean notEquals(Time otherTime)

{

if (time!=otherTime)

return true;

else

return

false

}

public boolean lessOrEquals(Time otherTime)

{

if(time<=otherTime)

return true;

else

return false;

}

public boolean(Time otherTime)

{

if(time>otherTime)

return true;

else

return false;

}

public boolean greaterOrEquals(Time otherTime)

{

if(time>=otherTime)

return true;

else

return false;

}

public string toMilitary(Time otherTime, String str1)

{

time=otherTime;

s1=str1;

s2=" ";

return(otherTime,s1);

}

public string toStandard(Time otherTime, String str2)

{

s2=str2;

return(otherTime, s2);

}

};

import java.io.*

public class Time{

public static void main(String args[])

{

Time t1=new Time("12");

Time t1=new Time("10");

Time str1=new Time("Military");

Time str2=newe Time("Standard");

boolean a,b,c,d;

a=notEquals(t2);

System.out.println(a);

b=lessOrEquals(t2);

System.out.println(b);

c=greaterThen(t2);

System.out.println(c);

d=greaterOrEquals(t2)

System.out.println(d);

String s1,s2;

s1=toMilitary(t2," ");

s2=toStandard(t2, " ");

}

d=greaterOrEquals(t2);

Add a comment
Know the answer?
Add Answer to:
Task: Modify the Time class and add more methods. 3.1. The class Time (discussed in class)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Take the Pizza class from assignment # 1 and modify it in the following way: -...

    Take the Pizza class from assignment # 1 and modify it in the following way: - Rename it to DeluxePizza. - Add a stuffedWithCheese (boolean) attribute to the class. - Add a veggie Topping (integer) attribute to the class. This attribute keeps track of the number of vegetables toppings excluding mushrooms. Add a static attribute numberOfPizzas (integer) which will keep track of the number of DeluxePizza objects created Update the existing non-default constructor such that it increments the numberOfPizzas by...

  • Please try your best to complete this 11 methods under. I have provided the UndirectedGraph class...

    Please try your best to complete this 11 methods under. I have provided the UndirectedGraph class with the single instance data variable. Do not add any additional instance data variables. Do not modify any other classes provided. In addition to writing the 8 required methods of the interface and the constructor, you will also write methods for the two traversals and an isConnected method. import java.util.Queue; public class UndirectedGraph<T> implements BasicGraphInterface <T> {       private DirectedGraph digraph;      ...

  • In c++ show both .cpp and .hpp file for the class: class Task { private: //...

    In c++ show both .cpp and .hpp file for the class: class Task { private: // These three member variables store the basic information about a task string title; string location; // This pointer will point to a dynamically-allocated array // of THREE strings. Each element contains the name of a supply required for this task. // This should start out set to NULL. string * tags; // This integer stores the number of elements in the tags array. int...

  • Java Time Class Class declarations are one of the ways of defining new types in Java....

    Java Time Class Class declarations are one of the ways of defining new types in Java. we will create two classes that both represent time values for a 24 hours period. The valid operations are as follows. int getHours(): returns the number of hours int getMinutes(): returns the number of minutes int getSeconds(): returns the number of seconds String toString(): returns a String representation boolean equals(Time other): returns true if and only if other designates an object that has the...

  • 2. Consider a circular array based Queue as we have discussed in the lectures (class definition...

    2. Consider a circular array based Queue as we have discussed in the lectures (class definition given below for reference) public class CircArrayQueue<E> implements Queue<E private EI Q private int front-0 indicates front of queue l indicates position after end of queue private int end-0: public CircArrayQueue( public int getSize (.. public boolean isEmpty ( public void enqueue (E e)... public E dequeue ) throws EmptyQueueException... Il constructor We are interested in implementing a Stack class based on the above...

  • Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed...

    Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed in class. Once complete, test the class using the CashRegisterTester class. Make sure you have 3 total items in the cash register. I have two classes, the first is CashRegisterTester below: public class CashRegisterTester { public static void main(String[] args) { //Initialize all variables //Construct a CashRegister object CashRegister register1 = new CashRegister(); //Invole a non-static method of the object //since it is non-static,...

  • 8.26 Encapsulate the Name class. Modify the existing code shown below to make its fields private,...

    8.26 Encapsulate the Name class. Modify the existing code shown below to make its fields private, and add appropriate accessor methods to the class named getFirstName, getMiddleInitial, and getLastName. code: class Name { private String firstName; private String middleNames; private String lastName;    //Constructor method public Name(String firstName, String middleNames, String lastName) { this.firstName = firstName; this.middleNames = middleNames; this.lastName = lastName;    } //Accessor for firstName public String getFirstName() { return firstName; } //Accessor for middleNames public String getMiddlesNames()...

  • Your task is to go through and implement the methods getBucketIndex, add, get, and remove. Follow...

    Your task is to go through and implement the methods getBucketIndex, add, get, and remove. Follow the comments inside respective methods. import java.util.ArrayList; import java.util.Scanner; public class HashtableChaining<K, V> {    // Hashtable bucket    private ArrayList<HashNode<K, V>> bucket;    // Current capacity of the array list    private int numBuckets;    // current size of the array list    private int size;       public HashtableChaining(int buckets){        bucket = new ArrayList<>();        numBuckets = buckets;   ...

  • Submissions) Part A Type and run the Array class template discussed in lecture (Templates notes). Modify...

    Submissions) Part A Type and run the Array class template discussed in lecture (Templates notes). Modify the class by adding sort member function (refer to Algorithm Analysis notes for sorting algorithms) Sample usage: a. sort(); Add the needed code in main to test your function. template <class T> 1/you can use keyword typename instead of class class Array { private: T *ptr; int size; public: Array(T arr[], int s); void print(); template <class T> Array<T>:: Array (T arr[], int s)...

  • Add the following methods to the ArrayList class that we wrote during lecture. You may call...

    Add the following methods to the ArrayList class that we wrote during lecture. You may call the existing methods in ArrayList if you want, but do not use anything from the built-in java.util.ArrayList class. 1. (3 pts) Write a new method named addAll(ArrayList anotherList) that adds all the elements in anotherList to the back of the calling list. Be sure to reallocate the data array if necessary. anotherList should not be modified. 2. (4 pts) Write a new method named...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT