帮助编写课程作业 [英] Help with coding course assignment

查看:89
本文介绍了帮助编写课程作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行在线java课程,我发现给出的一些作业非常含糊,而且没有为初学者充分描述..



我没有给出任何指示,但我知道它很多,但我真的很想得到这个,而且我对这门课程感到沮丧。我认为它是某种测试,但我不知道如何创建方法!如果有人能解释如何制作这些方法我会非常感激!

I'm doing an online java course and I'm finding that some of the assignments given are very vague and not adequately described for a beginner..

I was given this with next to no instructions.. I know its a lot, but I really want to get this and I'm getting frustrated with this course. I figure its some kind of test, but I wouldn't have a clue as to how to create the methods! If anyone could explain how to make these methods i'd be so grateful!

import static java.lang.System.out;

/**
 * This assignment has you practice writing functions.  Test cases are provided
 * in code, so when you run the program, it will tell you if the functions
 * are working right.
 * 
 * Instructions
 * 
 * 1. Read all of the code all the way through.
 * 2. Figure out what should be in the ___ areas.  Fix them for all the methods, so the code will compile.
 * 3. Compile the code to check your work on data types and names.
 * 4. Figure out what code belongs in the // TODO areas.  Write that code, one function at a time.
 * 5. Compile and run frequently as you work, noting your progress through the test cases.
 * 6. Keep going until they're all written and the tests cases all pass.
 * 7. Celebrate!
 * 
 */
public class ManyFunctions
{
    /**
     * Takes two integer numbers as input and returns whichever number is smaller.
     */
    public static ___ minimum(_, __)
    {
        // TODO
    }

    /**
     * Takes two integer numbers as input and returns whichever number is larger.
     */
    public static ____ maximum(_, ___)
    {
        // TODO
    }

    /**
     * Returns true if the integer input is an odd number (1, 3, 5, 7...)
     */
    public static _____ isOddNumber(_____)
    {
        // TODO
    }

    /**
     * Returns true if the integer input is an even number (0, 2, 4, 6, 8...)
     */
    public static _____ isEvenNumber(_____)
    {
        // TODO
    }

    /**
     * Returns true if the letter is a vowel, or false otherwise.
     * You can assume only letters are being sent as input (not
     * spaces or punctuation marks or anything else).
     */
    public static _____ isVowel(_______)
    {
        // TODO
    }

    /**
     * Returns true if the letter is a consonant, or false otherwise.
     * You can assume only letters are being sent as input (not
     * spaces or punctuation marks or anything else).
     * 
     * This can be written in 1 short line of code without typing out
     * all the consonants in the alphabet.  Can you figure out how?
     */
    public static _____ isConsonant(_____)
    {
        // TODO
    }

    /**
     * Runs a series of test cases against the above methods.
     * 
     * * DO NOT!!!!! CHANGE THE CODE INSIDE main() { }
     * 
     * Just use this as an example of how the methods will be called, so 
     * you can figure out what they are supposed to do.
     * 
     */
    public static void main(String[] args)
    {
        out.println("Testing your functions.");
        int testFailures = 0;

        if (minimum(4, 3) != 3) {
            out.println("Error 1: Minimum failed test.  Expected 3, got " + minimum(4, 3));
            testFailures++;
        }
        if (minimum(4, 4) != 4) {
            out.println("Error 2: Minimum failed test.  Expected 4, got " + minimum(4, 4));
            testFailures++; 
        }
        if (minimum(3, 4) != 3) {
            out.println("Error 3: Minimum failed test.  Expected 3, got " + minimum(3, 4));
            testFailures++; 
        }
        if (minimum(5, 4) != 4) {
            out.println("Error 4: Minimum failed test.  Expected 4, got " + minimum(5, 4));
            testFailures++; 
        }

        if (maximum(4, 3) != 4) {
            out.println("Error 5: Maxmimum failed test.  Expected 4, got " + maximum(4, 3));
            testFailures++; 
        }
        if (maximum(3, 4) != 4) {
            out.println("Error 6: Maxmimum failed test.  Expected 4, got " + maximum(3, 4));
            testFailures++; 
        }
        if (maximum(4, 4) != 4) {
            out.println("Error 7: Maxmimum failed test.  Expected 4, got " + maximum(4, 4));
            testFailures++; 
        }
        if (maximum(-2, 10) != 10) {
            out.println("Error 8: Maxmimum failed test.  Expected 10, got " + maximum(-2, 10));
            testFailures++; 
        }

        if (isEvenNumber(3)) {
            out.println("Error 9: isEven failed test.  Expected isEven(3) to be false, but got true.");
            testFailures++; 
        }
        if (!isEvenNumber(2)) {
            out.println("Error 10: isEven failed test.  Expected isEven(2) to be true, but got false.");
            testFailures++; 
        }
        if (isOddNumber(0)) {
            out.println("Error 11: isOdd failed test.  Expected isOdd(0) to be false, but got true.");
            testFailures++; 
        }
        if (!isOddNumber(5)) {
            out.println("Error 12: isOdd failed test.  Expected isOdd(5) to be true, but got false.");
            testFailures++; 
        }
        if (isOddNumber(18)) {
            out.println("Error 13: isOdd failed test.  Expected isOdd(18) to be false, but got true.");
            testFailures++; 
        }

        if (!isVowel('a')) {
            out.println("Error 14: isVowel failed test.  Expected isVowel('a') to be true, but got false.");
            testFailures++; 
        }
        if (isVowel('x')) {
            out.println("Error 15: isVowel failed test.  Expected isVowel('x') to be false, but got true.");
            testFailures++; 
        }
        if (!isConsonant('z')) {
            out.println("Error 16: isConsonant failed test.  Expected isConsonant('z') to be true, but got false.");
            testFailures++; 
        }
        if (isConsonant('i')) {
            out.println("Error 17: isCononant failed test.  Expect isConsonant('i') to be false, but got true.");
            testFailures++; 
        }
        if (!isConsonant('b')) {
            out.println("Error 18: isConsonant failed test.  Expected isConsonant('b') to be true, but got false.");
            testFailures++; 
        }        
        if (!isConsonant('c')) {
            out.println("Error 19: isConsonant failed test.  Expected isConsonant('c') to be true, but got false.");
            testFailures++; 
        }        
        if (!isConsonant('d')) {
            out.println("Error 20: isConsonant failed test.  Expected isConsonant('d') to be true, but got false.");
            testFailures++; 
        }        
        if (!isConsonant('f')) {
            out.println("Error 21: isConsonant failed test.  Expected isConsonant('f') to be true, but got false.");
            testFailures++; 
        }        
        if (!isConsonant('g')) {
            out.println("Error 22: isConsonant failed test.  Expected isConsonant('g') to be true, but got false.");
            testFailures++; 
        }
        if (!isVowel('A')) {
            out.println("Error 23: isVowel failed test.  Expected isVowel('A') to be true, but got false.");
            testFailures++; 
        }
        if (isVowel('X')) {
            out.println("Error 24: isVowel failed test.  Expected isVowel('X') to be false, but got true.");
            testFailures++; 
        }
        if (!isConsonant('Z')) {
            out.println("Error 25: isConsonant failed test.  Expected isConsonant('Z') to be true, but got false.");
            testFailures++; 
        }
        if (isConsonant('I')) {
            out.println("Error 26: isCononant failed test.  Expect isConsonant('I') to be false, but got true.");
            testFailures++; 
        }

        if (testFailures == 0) {
            out.println("Success!  All test cases passed.");
        } else {
            out.println(testFailures + " tests failed.  Keep trying!");
        }
    }
}





我尝试了什么:



在胎儿位置来回摇摆



What I have tried:

Rocking back and forth in the foetal position

推荐答案

花一些时间用 Java™教程 [ ^ ],您将学到更多。
Spend some time with The Java™ Tutorials[^], you will learn much more.


从我的角度来看,说明是清楚的。但是,它们需要有关函数的基本知识(返回值,参数)。



让我们来看看:

From my point of view the instructions are clear. However, they require basic knowledge about functions (return value, arguments).

Let's have a look:
/**
* Takes two integer numbers as input and returns whichever number is smaller.
*/
public static ___ minimum(_, __)
{
    // TODO
}

您只需要替换 __ ,以便该功能按照描述运行。所以第一个必须用返回类型替换,其他的必须用参数的类型和名称替换。



然后使用参数变量名实现函数体来执行请求操作。



对于上述情况,它可能是

You just have to replace the __ so that the function is working as described. So the first must be replaced with the return type and the others with type and name of the arguments.

Then implement the function body using the argument variable names to perform the requested operation.

For the above, it might be

/**
* Takes two integer numbers as input and returns whichever number is smaller.
*/
public static int minimum(int x, int y)
{
    if (x <= y)
        return x;
    else
        return y;
}



对其他函数执行类似操作:

从函数decsription中减去返回类型和参数类型,选择参数的名称,并实现函数体,以便它执行预期的操作。编译并运行以了解正文是否已正确实现。


Do it similar for the other functions:
Deduce the return type and the type of arguments from the function decsription, select names for the arguments, and implement the function body so that it does what is expected. Compile and run to know if the body has been implemented correctly.


这篇关于帮助编写课程作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆