Objects

The code creates a public class called "Student", which takes in three different instance variables: class, teacher, and period. With these a string of "AP Computer Science A", another string of "Mr. Mortensen", and an integer of 2 are put together to print out the statement, "I have AP Computer Science A for Mr. Mortensen in period 2"

public class Student {

    // instance variables
    public String class;
    public String teacher;
    public int period;


    public Student (String class, String teacher, int period) {
        this.class = class;
        this.teacher = teacher;
        this.period = period;
    }

    public static void main(String[] args) {
        Student s = new Student("AP Computer Science A", "Mr. Mortensen", 2);
        
        system.out.println("I have " + s.teacher " for " + s.class + " in period " + s.period);
    }
}
|       public String class;
<identifier> expected

|       public String class;
<identifier> expected

|       public Student (String class, String teacher, int period) {
invalid method declaration; return type required

|       public Student (String class, String teacher, int period) {
<identifier> expected

|       public Student (String class, String teacher, int period) {
<identifier> expected

|       public Student (String class, String teacher, int period) {
';' expected

|           this.class = class;
<identifier> expected

|           this.class = class;
illegal start of expression

|           this.class = class;
<identifier> expected

|           this.teacher = teacher;
illegal start of type

|           this.teacher = teacher;
';' expected

|           this.teacher = teacher;
<identifier> expected

|           this.period = period;
illegal start of type

|           this.period = period;
';' expected

|           this.period = period;
<identifier> expected

|       public static void main(String[] args) {
illegal start of expression

|           system.out.println("I have " + s.teacher " for " + s.class + " in period " + s.period);
')' expected

|           system.out.println("I have " + s.teacher " for " + s.class + " in period " + s.period);
not a statement

|           system.out.println("I have " + s.teacher " for " + s.class + " in period " + s.period);
';' expected

|   }
reached end of file while parsing

Hacks

Explain where a Class is defined

  • A class is defined where you need variables, objects, or methods to be added to your code

Explain where an instances of a Class is defined

  • An instance is defined in a Class as an object.

Explain where an object is Calling a Method

  • An object can call a method when the action is needed to be used for the code to go through.

Explain where an object is Mutating data

  • An object is mutation data when there is a change in the original data.

Describe Console, GUI differences, or Code.org differences.

  • A console is where the user input and gets outputs.
  • Ex: Bash shell

  • A GUI is more clickable and user-friendly. There is also visual feedback and display.

  • Code.org used a painter as the visual object which shows the user what the code is doing. It has a public class as "MyNeighborhood". To call a method, you put "variableName.methodName();".