A PHP Error was encountered

Severity: Warning

Message: fopen(/var/cpanel/php/sessions/ea-php56/PHPSESSIDqi1b2vqg0le56ieba0u0bq9qnt7g8rs5): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 174

A chikcken farmer receives from a supplier young chickens that he raises until they have the weight needed for marketing. A chicken is characterized by its weight and an identification number
Q:

A chikcken farmer receives from a supplier young chickens that he raises until they have the weight needed for marketing. A chicken is characterized by its weight and an identification number

0

A chikcken farmer receives from a supplier young chickens 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 3.4 kilograms the price will be 17 riyals. The price of the day (dailyPrice) and the necessary weight to market a chicken ( necessaryWeight) are the same for all chickens. By default dailyPrice = 8 and necessaryWeight=1.5

Write the Chicken class according to the class diagram below:

getWeight and setWeight methods corresponds to getter and setter for the weight attribute.

  • setDailyPrice : set the new daily price for all chickens. • setNecessaryWeight: set the necessary weight to market a chicken.
  • canMarket : return true if the weight of a chicken is grater 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.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

package chikendriver;

public class ChikenDriver {

    public static void main(String[] args) {
        Chiken c=new Chiken(1, 2);
        c.Print();
    }

}

class Chiken {

    private static double dailyPrice=8;
    private static double necessaryWeight=1.5;
    private double weight;
    private int id;

    public Chiken(int id, double weight) {
        this.id = id;
        this.weight = weight;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public static void setDailyPrice(double dailyPrice) {
        Chiken.dailyPrice = dailyPrice;
    }

    public static void setNecessaryWeight(double necessaryWeight) {
        Chiken.necessaryWeight = necessaryWeight;
    }

    public boolean canMarket() {
        if (weight >= necessaryWeight) {
            return true;
        } else {
            return false;
        }
    }

    public double Price() {
        if (necessaryWeight > 0) {
            return weight * dailyPrice;
        } else {
            return 0;
        }
    }
    public void Print(){
        System.out.println("chicken id: "+id+", chicken weight: "+weight);
        if(canMarket())
        System.out.println("ready for market, the price is : "+Price()+" riyals");
        else System.out.println("dont have the necessary weight"); 
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now

A PHP Error was encountered

Severity: Warning

Message: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56)

Filename: Unknown

Line Number: 0