first commit
This commit is contained in:
24
Lecture Notes/src/Week1/Inheritance.java
Normal file
24
Lecture Notes/src/Week1/Inheritance.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package Week1;
|
||||
|
||||
|
||||
import Week1.Person.*;
|
||||
|
||||
public class Inheritance {
|
||||
|
||||
//Object Methods
|
||||
// @Override
|
||||
// public String toString()
|
||||
// public boolean equals(Object o)
|
||||
// Overload -> public boolean equals (String s)
|
||||
//
|
||||
// Anything the parent/super class has the child/sub class also has.
|
||||
// -Used to reduce code. Prevents redundant code
|
||||
//
|
||||
public static void main(String[] args) {
|
||||
FullTime ft = new FullTime("Sean", 98, "male", "professor", 5000, "none");
|
||||
System.out.println(ft.getName());
|
||||
System.out.println(ft.getSalary());
|
||||
|
||||
Person p = new Employee("Sean", 98, "male", "professor", 5000);
|
||||
}
|
||||
}
|
||||
16
Lecture Notes/src/Week1/Person/Employee.java
Normal file
16
Lecture Notes/src/Week1/Person/Employee.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package Week1.Person;
|
||||
|
||||
public class Employee extends Person {
|
||||
//Use protected when child needs to access fields
|
||||
protected String job;
|
||||
protected double salary;
|
||||
|
||||
public Employee(String name, int age, String gender, String job, double salary) {
|
||||
//Every inheriting child constructor calls the parent class' constructor
|
||||
super(name, age, gender);
|
||||
this.job = job;
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
15
Lecture Notes/src/Week1/Person/FullTime.java
Normal file
15
Lecture Notes/src/Week1/Person/FullTime.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package Week1.Person;
|
||||
|
||||
public class FullTime extends Employee{
|
||||
private String benefits;
|
||||
|
||||
public FullTime(String name, int age, String gender, String job, double salary, String benefits) {
|
||||
super(name, age, gender, job, salary);
|
||||
this.benefits = benefits;
|
||||
|
||||
}
|
||||
|
||||
public double getSalary() {
|
||||
return super.salary;
|
||||
}
|
||||
}
|
||||
29
Lecture Notes/src/Week1/Person/Person.java
Normal file
29
Lecture Notes/src/Week1/Person/Person.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package Week1.Person;
|
||||
|
||||
public class Person {
|
||||
//Instance variables should be private
|
||||
private String name;
|
||||
private int age;
|
||||
private String gender;
|
||||
|
||||
//Default no parameter constructor is given if no constructor is described
|
||||
|
||||
public Person(String name, int age, String gender) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
//Getters are not required
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
}
|
||||
23
Lecture Notes/src/Week2/Animals/Animal.java
Normal file
23
Lecture Notes/src/Week2/Animals/Animal.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package Week2.Animals;
|
||||
|
||||
public class Animal {
|
||||
|
||||
protected String name;
|
||||
|
||||
public Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String speak() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am an animal called " + name;
|
||||
}
|
||||
}
|
||||
17
Lecture Notes/src/Week2/Animals/Cat.java
Normal file
17
Lecture Notes/src/Week2/Animals/Cat.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Week2.Animals;
|
||||
|
||||
public class Cat extends Animal{
|
||||
public Cat(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String speak() {
|
||||
return "meow!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am a cat and my name is " + name;
|
||||
}
|
||||
}
|
||||
17
Lecture Notes/src/Week2/Animals/Dog.java
Normal file
17
Lecture Notes/src/Week2/Animals/Dog.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Week2.Animals;
|
||||
|
||||
public class Dog extends Animal{
|
||||
public Dog (String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String speak() {
|
||||
return "woof!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
BIN
Lecture Notes/src/Week2/InClassExercise1.zip
Normal file
BIN
Lecture Notes/src/Week2/InClassExercise1.zip
Normal file
Binary file not shown.
18
Lecture Notes/src/Week2/InClassExercise1/Course.java
Normal file
18
Lecture Notes/src/Week2/InClassExercise1/Course.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Course {
|
||||
private ArrayList<Section> sections = new ArrayList<>();
|
||||
private String prefix;
|
||||
private int courseNumber;
|
||||
|
||||
public void display() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
8
Lecture Notes/src/Week2/InClassExercise1/Person.java
Normal file
8
Lecture Notes/src/Week2/InClassExercise1/Person.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
|
||||
public class Person {
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
||||
17
Lecture Notes/src/Week2/InClassExercise1/Section.java
Normal file
17
Lecture Notes/src/Week2/InClassExercise1/Section.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Section {
|
||||
|
||||
private ArrayList<Person> students = new ArrayList<>();
|
||||
private String classroom;
|
||||
|
||||
public int numStudents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void display() {
|
||||
|
||||
}
|
||||
}
|
||||
16
Lecture Notes/src/Week2/InClassExercise1/Student.java
Normal file
16
Lecture Notes/src/Week2/InClassExercise1/Student.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Student {
|
||||
|
||||
private ArrayList<Integer> quizzes = new ArrayList<>();
|
||||
|
||||
public double quizAverage() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public void display(){
|
||||
|
||||
}
|
||||
}
|
||||
10
Lecture Notes/src/Week2/InClassExercise1/Teacher.java
Normal file
10
Lecture Notes/src/Week2/InClassExercise1/Teacher.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Week2.InClassExercise1;
|
||||
|
||||
public class Teacher extends Person {
|
||||
|
||||
public double salary;
|
||||
|
||||
public double calculateTaxes() {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
14
Lecture Notes/src/Week2/InheritanceDriver.java
Normal file
14
Lecture Notes/src/Week2/InheritanceDriver.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package Week2;
|
||||
|
||||
import Week2.Animals.Animal;
|
||||
import Week2.Animals.Cat;
|
||||
|
||||
public class InheritanceDriver {
|
||||
public static void main(String[] args) {
|
||||
Animal a = new Animal("Fred");
|
||||
System.out.println(a);
|
||||
|
||||
Cat c = new Cat("Fluffy");
|
||||
System.out.println(c);
|
||||
}
|
||||
}
|
||||
14
Lecture Notes/src/Week3/AmericanFace.java
Normal file
14
Lecture Notes/src/Week3/AmericanFace.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package Week3;
|
||||
|
||||
public class AmericanFace implements Face {
|
||||
@Override
|
||||
public void nose() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouth() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
10
Lecture Notes/src/Week3/Face.java
Normal file
10
Lecture Notes/src/Week3/Face.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Week3;
|
||||
|
||||
public interface Face {
|
||||
//You may only have constant variables in an interface, unlike abstract classes
|
||||
double NUM_EYES = 2;
|
||||
//Interface methods will always be public and abstract so it's assumed. Unlike abstract
|
||||
// classes which can have both fully and non-fully implemented methods, interfaces do not
|
||||
void nose();
|
||||
void mouth();
|
||||
}
|
||||
7
Lecture Notes/src/Week3/FaceDriver.java
Normal file
7
Lecture Notes/src/Week3/FaceDriver.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package Week3;
|
||||
|
||||
public class FaceDriver {
|
||||
public static void main(String[] args) {
|
||||
Face face = new AmericanFace();
|
||||
}
|
||||
}
|
||||
35
Lecture Notes/src/Week3/GUIExample.java
Normal file
35
Lecture Notes/src/Week3/GUIExample.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package Week3;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.beans.EventHandler;
|
||||
|
||||
public class GUIExample extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
Pane pane = new Pane();
|
||||
Scene scene = new Scene(pane, 300, 300);
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("My Great JavaFX Program!");
|
||||
Button button = new Button("Start");
|
||||
Button stopButton = new Button("Stop");
|
||||
//stopButton.setOnAction(new StopButtonHandler() {
|
||||
// @Override
|
||||
// public void handle(ActionEvent event) {
|
||||
// }
|
||||
// });
|
||||
pane.getChildren().addAll(button,stopButton);
|
||||
stage.show();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
52
Lecture Notes/src/Week5/JavaFXExercise.java
Normal file
52
Lecture Notes/src/Week5/JavaFXExercise.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package Week5;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
|
||||
|
||||
public class JavaFXExercise extends Application {
|
||||
// create a simple GUI interface that has two TextFields and one Button
|
||||
// Make a new Stage and Scene of size 400x400
|
||||
|
||||
// The first textfield should have a label "Username"
|
||||
// The second textfield should have a label "Passcode"
|
||||
|
||||
// The Button should be labeled "Submit"
|
||||
|
||||
// When the Button is pressed, if a username has been entered in the first textfield,
|
||||
// a random six digit passcode should be generated in the second textfield.
|
||||
// The second textfield should not be able to be edited by the user.
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
VBox vBox = new VBox();
|
||||
Scene scene = new Scene(vBox, 400, 400);
|
||||
stage.setScene(scene);
|
||||
TextField username = new TextField("Username");
|
||||
TextField passcode = new TextField("Passcode");
|
||||
Button submit = new Button("Submit");
|
||||
HBox hBox = new HBox();
|
||||
|
||||
hBox.getChildren().addAll(username, passcode);
|
||||
vBox.getChildren().addAll(hBox, submit);
|
||||
|
||||
passcode.setEditable(false);
|
||||
submit.setOnAction(event -> {
|
||||
int code = (int)(Math.random()*1000000);
|
||||
passcode.setText(Integer.toString(code));
|
||||
});
|
||||
|
||||
stage.show();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
|
||||
42
Lecture Notes/src/Week6/FileIOExample.java
Normal file
42
Lecture Notes/src/Week6/FileIOExample.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package Week6;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static java.lang.System.in;
|
||||
|
||||
public class FileIOExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String home = System.getProperty("user.dir");
|
||||
Path path = Paths.get(home,"Week6","FileIO");
|
||||
System.out.println(path);
|
||||
File file = new File("File.txt");
|
||||
Scanner in = new Scanner("historyChannel");
|
||||
try (PrintWriter pw = new PrintWriter("File.txt")){
|
||||
file.createNewFile();
|
||||
while(in.hasNext()) {
|
||||
String temp = in.next();
|
||||
System.out.println(temp);
|
||||
pw.print(temp);
|
||||
}
|
||||
} catch(FileNotFoundException fileException) {
|
||||
System.err.println("File not found");
|
||||
} catch (IOException e) {
|
||||
System.err.println("Could not create file");
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
System.out.println(file.exists());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
12
Lecture Notes/src/Week7/TestQ25.java
Normal file
12
Lecture Notes/src/Week7/TestQ25.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package Week7;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TestQ25 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
File file = new File(System.getProperty("user.dir")+"Penguins.txt");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user