Link to home
Start Free TrialLog in
Avatar of boban dimovski
boban dimovski

asked on

I need help to solve this code.

/**
 * Add your code in the space below the comment line that says:
 * "*** Add your code BELOW this line (do not change ANYTHING above this line"
 *
 * Do not change ANYTHING in the main method give below.
 *
 * Write a good javadoc comment for EVERY method that you write.  Include one
 * or two sentences that give a good overview of what the method does, plus
 * the @param and @return directives (when appropriate).
 *
 * The output your program should be exactly the same output as shown in the
 * sample output, including the same spacing, same placement of commas and
 * periods, upper and lowercase, etc.
 *
 * Use good, descriptive variable names where appropriate.
 *
 * Your code will be run against the main method as shown below, and also
 * against a different main method that will test your code more completely.
 * You should therefore test your code as fully as possible.
 *
 * You do not need to define "public static final" values for the constants
 * (not required, but you can practice defining those if you wish).
 */
public class ManyMethods {

    /**
     * Students should write method definitions for the all of the
     * methods called in this main method.  The code in the main method
     * should be left EXACTLY as it is.
     *
     * @param args the command line arguments (not used in this program)
     */
   
    public static void main(String[] args) {
        // The add method takes in two integers and returns their sum.
        int x = add(3, 15);
        System.out.printf("x is: %d\n", x);
       
        // Print two digits after the decimal point for monetary values and
        // one digit after the decimal point for the tax rate.
        totalCost(150.00, 0.06);
        totalCost(3099.95, 0.03);
       
        // Takes in a integer that represents a month of the year, where
        // 1 is January, 2 is February, etc., and returns a string representing
        // the SEASON that that month appears in.  Use this mapping of
        // months to seasons:  
        //    11, 12, 1, and 2 are "Winter" (all upper case except upper case 'W')
        //    3, 4, and 5 are "Spring"
        //    6, 7, and 8 are "Summer"
        //    9 and 10 are "Fall"
        //    Return "Invalid month" for any other integer values
        //
        String season1 = getSeason(5);
        String season2 = getSeason(20);
        System.out.println(season1 + " and " + season2);
        System.out.println(getSeason(12));
       
        // This method is similar to the getSeason method, except that
        // instead of returning a value (this method returns nothing) this
        // method prints one line to the console of the format:
        //   "3 is Spring"
        // For invalid values print a message to the console of the
        // format:
        //   "15 is Invalid month"
        reportSeasonForMonth(3);
        reportSeasonForMonth(12);
        reportSeasonForMonth(15);
       
        // This method takes in an integer parameter that represents
        // the width of a screen in pixels.  It prints a message to the
        // console of the format:
        //    333 pixels is a phone
        //    2300 pixels is a computer
        //    7 pixels is too small to be a phone
        //    9000 pixels is bigger than a computer
        // The ranges are:
        //    Less than 100 pixels is "too small to be a phone"
        //    100 to 500 pixels, inclusive, is "a phone"
        //    500 to 899 pixels is "a tablet"
        //    900 to 3999 pixels is "a computer"
        //    4000 pixels and above is "bigger than a computer"
        //
        screenType(333);
        screenType(2300);
        screenType(7);
        screenType(9000);
       
        // The isAdult method takes in an age and returns true if they
        // are 18 years old or older, and returns false otherwise.
        if (isAdult(7) == true)
            System.out.println("Yes, is an adult!");
        else
            System.out.println("No, is NOT an adult!");
       
        if (isAdult(35))
            System.out.println("Yes, is an adult!");
        else
            System.out.println("No, is NOT an adult!");
       
        // The multiply method takes in two doubles and returns the
        // product of those two numbers.
        int result = multiply(3, 5);
        System.out.printf("d is: %d\n", result);
       
        System.out.println(multiply(10, 37));    
        System.out.println(multiply(2, multiply(3, 4)) );  
        System.out.println(add( multiply(10, 10), add(2, 2)));
       
        // The getAverage method takes in three doubles and returns their
        // average.
        double ave1 = getAverage(14.0, 16.0, 15.0);
        double ave2 = getAverage(99.9, 75.5, 84.0);
        System.out.printf("Averages: %.1f and %.1f\n", ave1, ave2);
       
        // The passed method takes in three test scores as double values,
        // and returns the boolean true value if they passed the tests with
        // and average test score of 70.0 or greater, otherwise it returns
        // the boolean false value.
        boolean status = passed(100.0, 88.0, 90.0);
        System.out.println("passed: " + status);
       
        System.out.println("passed: " + passed(73.0, 70.0, 61.0));
    }





   
    // *** Add your code BELOW this line (do not change ANYTHING above this line
   
    // This first method is done for you:
   
    /**
     * Adds two integers and returns their sum.
     *
     * @param num1 The first of two integers to add.
     * @param num2 The second integer to add.
     * @return The sum of the two integers.
     */
   
    public static int add(int num1, int num2) {
        return num1 + num2;
    }
Avatar of ste5an
ste5an
Flag of Germany image

Start by identifying each called, but undeclared method. Then declare the methods. Write the Javadoc comment. Implement the methods body as described in the comments (or did you get further material?).
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.