标签归档:Java

COM6506

Week 02

public class Person {
    String name;
    double weight;
    double height;

    public Person(String name, double weight, double height) {
        this.name = name;
        this.weight = weight;
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public double getWeight() {
        return weight;
    }

    public double getHeight() {
        return height;
    }

    public static void main(String[] args) {
        Person jeff = new Person("Jeff", 72.4, 2.2);
        Person jim = new Person("Jim", 65, 1.7);
        System.out.println("Jeff is " + jeff.getHeight() + "m tall.");
        System.out.println("Jim is " + jim.getHeight() + "m tall.");
    }
}

继续阅读

COM6516

Week01-02

/*
 * HelloWorld.java
 * A traditional Hello World program!
 */

// In Java, all programs reside in a class. This class is called HelloWorld, 
// and should be saved in a file called HelloWorld.java. This class has a single
// method called main, which is the entry point to the program.
//
// Compiling the class with javac HelloWorld.java will produce a bytecode file
// called HelloWorld.class if compilation is successful. This bytecode can then
// be run on any machine with a java bytecode interpreter. You can run the
// bytecode in a console by typing java HelloWorld.

public class HelloWorld {
    public static void main(String[] arg) {

        String helloString = "Hello";
        String worldString = "World!";

        // In Java the System.out.println command displays the argument to the 
        // console. However the command below doesn't work, because helloWorldAString
        // has not been declared. Try compiling this file to see what happens, 
        // and take a careful look at the error message that is produced.

        System.out.println(helloString + " " + worldString);

        // In Java, we can use the '+' operator to concatenate strings, 
        // so to fix this problem, either change the argument passed to the
        // System.out.println method from (helloWorldString) to 
        // (helloString + " " + worldString)
        // or declare the variable helloWorldString before it is used by 
        // System.out.println by inserting 
        // String helloWorldString = helloString + " " + worldString;

        // In Java a variable can be declared anywhere in the code, so it is
        // possible to declare a variable just before it is used, which makes for
        // code that is easier to read and understand.

        // It is conventional to use mixed case for variable names and method 
        // names in Java, with with the first letter lower case, and then the 
        // first letter of each internal word in upper case -- e.g. helloString.
        // Class names start with a capital letter -- e.g. HelloWorld.java

        // details at: http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html

    }
}

继续阅读

Java Lab

Lab 1

新学期,新的语言学习开始了~还是老样子,写代码~

public class TestArgs {
    public static void main (String[] args) {
        System.out.println("Name            = " + args[0] + " " + args[1]);
        System.out.println("BUPT Email Username = " + args[2]);
        System.out.println("Student Number      = " + args[3]);
    }
}

继续阅读