Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8893577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:16:58+00:00 2026-06-14T23:16:58+00:00

For the given class below, I was asked to test this class with a

  • 0

For the given class below, I was asked to test this class with a new TimeTest class that has a method doTest() to try out these methods in my Time class. I have tested classes before via the main method, but I have no idea how to test a class using a class. Could anyone help me get started?

public class Time {

    private int minute;
    private int hour;
    private int totalMinute;

    public Time() {
        minute = 0;
        hour = 0;
    }

    public Time(int hours, int minutes) {
        setHour(hours);
        setMinute(minutes);
    }

    private void setHour(int hours) {
        if (hours < 24 && hours >= 0) {
            hour = hours;
        } else {
            hour = 0;
        }
    }

    private void setMinute(int minutes) {
        if (minutes < 60 && minutes >= 0) {
            minute = minutes;
        } else {
            minute = 0;
        }
    }

    public void setTime(int hours, int minutes) {
        setHour(hours);
        setMinute(minutes);
    }

    public int getElapsedTime(Time that) {
        int thisTime = this.getTotalMinutes();
        int thatTime = that.getTotalMinutes();
        if (thisTime > thatTime) {
            return thisTime - thatTime;
        }
        return thatTime - thisTime;
    }

    private int getTotalMinutes() {
        totalMinute = (hour * 60) + minute;

        return totalMinute;
    }

    public String getAsString() {
        if (hour < 10 && minute < 10) {
            return "0" + hour + ":0" + minute;
        } else if (hour < 10 && minute >= 10) {
            return "0" + hour + ":" + minute;
        } else if (hour >= 10 && minute < 10) {
            return hour + ":0" + minute;
        } else {
            return hour + ":" + minute;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:16:59+00:00Added an answer on June 14, 2026 at 11:16 pm

    Here is the class which may meet your requirement. If you do not want main method in this class then write the main method in another class and Create object of TimeTest and call the doTest(time) method from that class which has main method.

    public class TimeTest {
    
    public static void main(String[] args) {
        Time time = new Time();
        time.setTime(10, 10);
        doTest(time);
    
    }
    
    private static void doTest(Time time) {
        //set the time to 10 hours and 10 minutes
        System.out.println("Get as String: " + time.getAsString());
        // set the new time to test the getElapsedTime(time) method
        Time newTime = new Time(11, 30);
        System.out.println("Get Elapsed Time: " + time.getElapsedTime(newTime) + " minutes");
    }
    

    }

    Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The test class below verifies that a simple HttpService gets content from a given
I am new to Mockito. Given the class below, how can I use Mockito
I have method that returns module path of given class name def findModulePath(path, className):
In the class below, would this mean that onPaintCallback is NULL, or must I
This question has been asked before, but none that I have reviewed give a
I have a data structure which is as given below: class File { public
I have a class with a set of properties As given below. class ContactInfo
I understand that CoCreateInstance finds the COM server for the given class id, creates
Given a custom, new-style python class instance, what is a good way to hash
I have a css class (given below). The border element is working fine in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.