A1 ‣ Simple Classes

Write a class named Pair that has the following properties:

  • two integer fields named x and y
  • a constructor that has two integer parameters named x and y.  The constructor initializes the fields with the values of the arguments passed into the constructor.
  • getters and setters for each of the fields

Write a class named Student that has the following properties:

  • a field named gpa that can hold a double
  • a field named name that holds a string
  • a constructor that has two parameters and that initializes both of the fields with the values of the arguments that are passed into the constructor.
  • getters and setters for each of the fields

Write a driver named Assignment1 that does the following:

  • creates a variable named p1 that references a Pair object modeling the coordinates (0,0)
  • creates a variable named p2 that references a Pair object modeling the coordinates (1,2)
  • creates a Student object modeling you whose reference is stored in a variable named s1
  • creates a Student object modeling an imaginary friend whose reference is stored in a variable named s2.

To compile more than one java file at the same time, just include each of the file names after javac.  For example,

$ javac Pair.java Student.java Assignment1.java

When complete,  push all of the .java files that were created to our GitHub repository.

© 2017 – 2019, Eric. All rights reserved.