Attention: My new 10th period

posted Sep 19, 2013, 2:25 PM by Samuel Konstantinovich   [ updated Oct 1, 2013, 4:57 AM ]
Homework:
1. Install the JDK
    -If you are a Mac user it was already installed, just test it.
    -Please check your install of the JDK works by opening a terminal at home, and running the javac command.
    -If the terminal says 'command not found' you may have to set the path variable. (google set java path)

2. Email me from a gmail address
Subject: APCS1 pd10 HW01    
Body:
First (nick) Last

3. Fill out this AAAArrrrrrgyle themed form:
https://docs.google.com/a/stuycs.org/forms/d/1OoDMerRmiqjP5u-I3745KtR_RElKKHpTt8FMEtT0i3w/viewform



Code posted:
The Coordinate class:

public class Coordinate{
    private double x,y;
   
    //default constructor has no parameters, 
    //You may leave it out, but then all values become zero/null
    public Coordinate(){
x = 0.0;
y = 0.0;
    }

    //constructor that allows you to set the x and y
     public Coordinate(double q, double r){
x = q;
y = r;
    }

    //Methods to access information (Accessors)
    public double getX(){
return x;
    }

    public double getY(){
return y;
    }

    //Methods to change things (Mutators)
    public void setX(double a){
x = a;
    }
    public void setY(double a){
y = a;
    }
    
    public void setXY(double ex,double why){
x = ex;
y = why;
    }

    //the overridden toString method:
    public String toString(){
return "("+x+","+y+")";
    }
}

The Coordinate demo:
public class cdemo{
    public static void main(String[]args){
Coordinate a ,b;

a= new Coordinate(12.0,61.0);
a.num=100;
b= new Coordinate(1.0,1.0);
b.num=23;
System.out.println(a.num);
System.out.println(b.num);
    }
}

The Greeter class and demo:
public class Greeter{
    private String message;
    private String mood;

    public Greeter(){
message = "Hello.";
mood = "Neutral";//Choose between: "Happy" "Neutral" "Sad"
    }

    public Greeter(String s){
message = s;
mood = "Neutral";
    }

    public Greeter(String mess, String moo){
message = mess;
mood = moo;
    }

    public String getGreeting(){
if( mood.equals("Happy") ){
   return message+" Wheeeeeee!";
}else if( mood.equals("Sad") ){
   return message+" Sad trombone...";
}else if( mood.equals("Neutral") ){
   return message;
}else{
   return "Error in getGreeting: mood not recognized";    
}
    }
}

DEMO:
public class greetDemo{
    public static void main(String[]args){
Greeter moonbeam = new Greeter("Sup...","Sad");
Greeter chad =  new Greeter("Greetings!","Happy");
Greeter bob  =  new Greeter();
Greeter xiao =  new Greeter("Hola señor.");

System.out.println(moonbeam.getGreeting());
System.out.println(chad.getGreeting());
System.out.println(xiao.getGreeting());
System.out.println(bob.getGreeting());

    }
}


Comments