2015-09-25 HW05

posted Sep 25, 2015, 1:25 PM by Samuel Konstantinovich   [ updated Sep 26, 2015, 7:58 PM ]
If you don't have access to your stuy.edu mail, fill out this form:

Code From Class:
public class Car{
    public String color;
    public int price;
    public String make,model;

    //default constructor
    public Car(){
        price = 100;
        color = "Black";
        make = "Ford";
        model = "T";
    }

    public Car(String Make, String Model, String color, int Price){
        price = Price;
        this.color = color; 
        //we use the this keyword to reference the current object's instance variables.
        make = Make;
        model = Model;
    }

    //a constructor that takes only some of the instance variables. 
    public Car(String make, String model){
        price = 100000;
        color = "Black"; 
        this.make = Make;
        this.model = Model;
    }

}

public class Driver{
    public static void main(String[]qbert){
        //constructor initializes the values 
        Car c = new Car("Honda","Civic","Habanero",9001);
        
        //this prints the address of the object
        System.out.println(c);

        //we need a better way to print an object... that is your homework!
        System.out.println(c.make);
        System.out.println(c.model);
        System.out.println(c.color);
        System.out.println(c.price);

        //comment

        /*
          multi line
          comments



        */
    }
}




HW05: (due Monday, bring a digital copy...)

I didn't finish explaining all of classes, but I task you with looking at java documentation and reference material

Student object!!!

1. Make a class to test your Student class that has a main. Call it Driver for now. As you add more pieces to your Student class, test as you go in Driver.java.

2. Now make a simple Student Class that has the following:
a) Instance variables:
firstName
lastName
osis
age
gpa

b)constructors:
Student(first,last,ID,years)

c)methods:  (you decide which methods require parameters and which do not)
void printStudent()   //print out the student in some way to the console.
void lowerGPA()  //lower the GPA by some amount
void raiseGPA() //increase the GPA by some amount 



Comments