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 934587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:01:44+00:00 2026-05-15T21:01:44+00:00

I got this exercise, is not a homework , I just trying to solve:

  • 0

I got this exercise, is not a homework, I just trying to solve:

We manage a farm with horses that have
to work on the field.

A horse has

  • a name,
  • a maximum amount of
    working hours per week,
  • the amount
    of hours actually worked and
  • a field to indicate if she is lazy or
    hard-working.

All the attributes of the Horse class
are private and they have no setters.
Initial values are passed through the
constructor.

The Horse class has a method to add
one hour of actual work. That method
is called every hour (that the horse
works). At the begin of the next week,
we reset that counter to 0, by calling
another method taking no parameter.

A lazy horse cannot work more than 34
hours/week, while a hard-working horse
can work up to 80 hours.

Code a Horse class that is shielded
against wrong working hours data.

Your main method will create an horse
and call its methods, but the data
must never be corrupted, ie. the
working hour limits must be respected.
For example, a lazy horse’s maximum
hours cannot be set above 34 and the
number of hours worked cannot be
greater than the maximum.

If the Horse class detects an attempts
to set incorrect data, the data
remains unchanged (and you print a
message to help you debugging).

Example of correct data:

Name: "Blacky" 
lazy: no
max hours / week = 70
actual hours this week = 61

Name: "Sultan" 
lazy: yes
max hours / week = 30
actual hours this week = 1

Example of corrupted data (your code should make such a situation impossible to reach)

Name: "Georges" 
lazy: yes
max hours / week = 50 (wrong because lazy horses work max 34h/week)
actual hours this week = 51 (wrong because 51 > 50).

This is my code:

public class Horse {

    private String name;
    private int maximumAmount;
    private int amountWorked;
    private boolean isLazy;

    public Horse(String name, int maximumAmount, int amountWorked, boolean lasyOrHardworking) {
        this.name = name;
        this.maximumAmount = maximumAmount;
        this.amountWorked = amountWorked;
        this.isLazy = lasyOrHardworking;
    }

    void everyHour(){
        amountWorked = amountWorked + 1;
        System.out.println(amountWorked);

        if((isLazy == true)&&(amountWorked <= 34)){
            resetToZero();
        }
        if((isLazy == false)&&(amountWorked <= 80)){
            resetToZero();
        }
    }

    void resetToZero(){
        this.amountWorked = 0;
    }
}

and my main class

public class MainHorse {
    public static void main(String args[]){
        Horse one = new Horse("Blacky", 34,35,true);
        one.everyHour();
    }
}

my question is how can I get that my method everyhour do the reset method, and in general, what is wrong in my code?

I hoper you can help me

  • 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-05-15T21:01:45+00:00Added an answer on May 15, 2026 at 9:01 pm

    My question is how can I get that my
    method every hour do the reset method,
    and in general, what is wrong in my
    code?

    Try to come up with something with java.util.Timer

    Minor details:

    Typos and spelling inconsistencies will come back to bite you someday (less likely in Java than in languages that do not require explicit declaration), you should stick to one correct spelling of the word “lazy”.

    this.isLazy = lasyOrHardworking;
    

    Why not use isLazy in the parameter as well, instead of lasyOrHardworking

    this.isLazy = isLazy;
    

    I think bool == true isn’t adding any value, this looks better to me:

    if(isLazy && (amountWorked <= 34))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.