Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q. Write a Java Progr A chickens farmer receives from a supplier young chicken that he raises until they have the weight needed for
Q. Write a Java Progr A chickens farmer receives from a supplier young chicken that he raises until they have the weight needed for marketing. A chicken is characterized by its weight and an identification number. The price of a chicken varies according to the price of the day and the weight. Suppose that the price of the day is 5 riyals per kilo. So, for a chicken with a weight of 3.4 kilograms the price will be 17 riyals. The price of the day (dailyPrice) and the necessary weight to market a chicken (necessary Weight) are the same for all chickens. By default, dailyPrice = 8 and necessary Weight=1.5 Write the Chicken class according to the class diagram below: Chicken 1-static double dailyPrice -static double necessaryWeight -double weight -int id +Chicken(int id, double weight) +double getWeight( +void setWeight(double weight) +static void setDailyPrice (double newPrice) +static void setNecessanWeight(double newNecessaryWeight) +boolean canMarket + double price( +void print() getWeight() and setWeight() methods correspond to getter and setter for the weight attribute. .setDailyPrice(): set the new daily price for all chickens. setNecessary Weight(): set the necessary weight to market a chicken. canMarket(): return true if the weight of a chicken is greater or equal to the necessary weight and false otherwise. price(): return the price of chicken (weight * dailyPrice) if the chicken have the necessary weight and 0 otherwise. .print(): print the id and the weight of the chicken. If the chicken is ready for market print "ready for market" and give the price. Otherwise print "dont have the necessary weight". Define a driver class that contains a main method and test the functionality of the above class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Based on the class diagram provided in the image here is an implementation of the Chicken class in J...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started