How do I put this shoutOutCannedMessage() method in to a new class?

时间:2016-02-12 21:28:54

标签: java

This is the program, and I want to put extension Array where Element : Equatable { func allEqual() -> Bool { if let firstElem = first { return !dropFirst().contains { $0 != firstElem } } return true } } in to its own class called shoutOutCannedMessage(). I don't know how to go about putting the selected method shoutbox in to a new class called shoutOutCannedMessage(). Could someone help me with this? I have a bit of brain fog because it's been some time since I've picked this up and I'm new to Java.

shoutbox

1 个答案:

答案 0 :(得分:1)

You can extrapolate the method in its own class and make it static, since it doesn't modify any state. It's only dependency seems to be the list, which you could just pass as a parameter. Something like this.

 rules: {
        fullname: "required",
        email: {
            required: true,
            email: true,
            remote: {
                url: "validate-email.php",
                type: "post",
                success: function(e) { if(e == false){window.location.replace("http://website");}}
            },
        },

messages: {
 email: {
    required: 'Please enter a valid email address',
    remote: 'Sorry, this email address is already in use',
    }
}

Then you could call the method as public class ShoutBox { public static void shoutOutCannedMessage(List<String> list) { System.out.println("This is a list of options: "); int size = list.size(); for(int i=0; i<size; i++) { System.out.println(list.get(i)); } int userNumber; Scanner scanner = new Scanner(System.in); System.out.println("Please enter number: "); userNumber = scanner.nextInt(); System.out.println(list.get(userNumber)); } }