College Board Units HW
List of all unit HWs
HW Scores
Unit | Score | Comments |
---|---|---|
Unit 6 Array | 0.9/1 | Took lots of notes and did extra problems |
Unit 7 ArrayLists | 0.9/1 | Notes are good, homework completed |
Unit 8 2D Arrays | 0.95/1 | no comment |
Unit 9 Inheritance | 1/1 | Completed all of the tasks in an organized matter and had very detailed code. |
Unit 10 Recursion | 0.9/1 | Good class participation. No extra files showing recursion were submitted |
total | 4.65/5 |
// Write array methods for the Array Methods class below out of the options given above.
public class ArrayMethods {
private int[] values = {1, 2, 3, 4, 5, 6, 7, 8};
public void printElements(){
for(int i = 0; i < values.length; i++){
System.out.println(values[i]);
}
}
public void swapElements(){
int lastElement = values[values.length-1];
values[values.length-1] = values[0];
values[0] = lastElement;
}
public void replaceAllZero(){
for(int i = 0; i < values.length; i++){
values[i] = 0;
}
}
public static void main(String[] args){
System.out.println("First and Last Element Swap: ");
ArrayMethods swapElements = new ArrayMethods();
swapElements.swapElements();
swapElements.printElements();
System.out.println("Replacing All Elements w/ Zero: ");
ArrayMethods replaceAllZero = new ArrayMethods();
swapElements.replaceAllZero();
swapElements.printElements();
}
}
ArrayMethods.main(null);
// Initializing an ArrayList filled with strings
ArrayList<String> strings = new ArrayList<>();
strings.add("5");
strings.add("5.0");
strings.add("5AB3");
strings.add("Eighty Six");
strings.add("86");
strings.add("Your mom");
strings.add("Cool");
// 2nd bullet point (Find and display the hashCode of an Arraylist before and after being sorted)
// hashCode before being sorted
System.out.println("Unsorted hashCode: " + strings.hashCode());
// sorted hashCode
Collections.sort(strings);
System.out.println("Sorted hashCode: " + strings.hashCode());
import java.util.Scanner;
public class Arrays{
int[][] numbers;
public Arrays(){
int[][] newArray = new int[4][4];;
for (int i = 0; i < newArray.length; i++){
for (int j = 0; j < newArray[i].length; j++){
newArray[i][j] = (j+1) * (int) (Math.random()*10);
}
}
this.numbers = newArray;
}
public void printArray(){
for(int i = 0; i < numbers.length; i++){
for(int j = 0; j < numbers[i].length; j++){
System.out.print(numbers[i][j] + " ");
}
System.out.println();
}
}
public void reverseArray(){
System.out.println("\n\nPrinting out values backward");
for(int i = numbers.length-1;i>=0;i--){
for(int j = numbers[i].length-1; j >= 0;j--){
System.out.print(numbers[i][j] + " ");
}
System.out.println(" ");
}
}
public void askForIndex(){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Row Index: ");
int rowIndex = scanner.nextInt();
System.out.println(rowIndex);
System.out.print("Enter Column Index: ");
int columnIndex = scanner.nextInt();
System.out.println(columnIndex);
System.out.print("Result: ");
System.out.println(numbers[rowIndex][columnIndex]);
}
public void multiplyThenSum(){
int sum = 0;
for(int i = 0; i < numbers.length; i++){
int multiply = 1;
for(int j = 0; j < numbers[i].length; j++){
multiply *= numbers[i][j];
}
sum += multiply;
}
System.out.print("Sum: ");
System.out.println(sum);
}
public static void main(String[] args){
Arrays array = new Arrays();
array.printArray();
array.reverseArray();
array.askForIndex();
array.multiplyThenSum();
}
}
Arrays.main(null);
public class QuarterFinalTeam{
String jerseyColor;
boolean quarterFinals;
boolean semiFinals;
public QuarterFinalTeam(){
this.quarterFinals = true;
}
public static void determineResults(QuarterFinalTeam team1, QuarterFinalTeam team2){
team1.quarterFinalResult();
team2.quarterFinalResult();
}
public void quarterFinalResult(){}
public static void main(String[] args){
Netherlands netherlands = new Netherlands();
Argentina argentina = new Argentina();
Croatia croatia = new Croatia();
Brazil brazil = new Brazil();
England england = new England();
France france = new France();
Morocco morocco = new Morocco();
Portugal portugal = new Portugal();
QuarterFinalTeam.determineResults(netherlands, argentina);
QuarterFinalTeam.determineResults(croatia, brazil);
QuarterFinalTeam.determineResults(england, france);
QuarterFinalTeam.determineResults(morocco, portugal);
System.out.println("Netherlands: " + "jerseyColor = " + netherlands.jerseyColor + ", quarterFinals = " + netherlands.quarterFinals + ", semiFinals = " + netherlands.semiFinals);
System.out.println("Argentina: " + "jerseyColor = " + argentina.jerseyColor + ", quarterFinals = " + argentina.quarterFinals + ", semiFinals = " + argentina.semiFinals);
System.out.println("Croatia: " + "jerseyColor = " + croatia.jerseyColor + ", quarterFinals = " + croatia.quarterFinals + ", semiFinals = " + croatia.semiFinals);
System.out.println("Brazil: " + "jerseyColor = " + brazil.jerseyColor + ", quarterFinals = " + brazil.quarterFinals + ", semiFinals = " + brazil.semiFinals);
System.out.println("England: " + "jerseyColor = " + england.jerseyColor + ", quarterFinals = " + england.quarterFinals + ", semiFinals = " + england.semiFinals);
System.out.println("France: " + "jerseyColor = " + france.jerseyColor + ", quarterFinals = " + france.quarterFinals + ", semiFinals = " + france.semiFinals);
System.out.println("Morocco: " + "jerseyColor = " + morocco.jerseyColor + ", quarterFinals = " + morocco.quarterFinals + ", semiFinals = " + morocco.semiFinals);
System.out.println("Portugal: " + "jerseyColor = " + portugal.jerseyColor + ", quarterFinals = " + portugal.quarterFinals + ", semiFinals = " + portugal.semiFinals);
}
}
public class Netherlands extends QuarterFinalTeam{
public Netherlands(){
super();
super.jerseyColor = "Orange";
}
public void quarterFinalResult(){
super.semiFinals = false;
}
}
public class Argentina extends QuarterFinalTeam{
public Argentina(){
super();
super.jerseyColor = "Blue & White";
}
public void quarterFinalResult(){
super.semiFinals = true;
}
}
public class Croatia extends QuarterFinalTeam{
public Croatia(){
super();
super.jerseyColor = "Red & White";
}
public void quarterFinalResult(){
super.semiFinals = true;
}
}
public class Brazil extends QuarterFinalTeam{
public Brazil(){
super();
super.jerseyColor = "Yellow";
}
public void quarterFinalResult(){
super.semiFinals = false;
}
}
public class England extends QuarterFinalTeam{
public England(){
super();
super.jerseyColor = "White & Blue";
}
public void quarterFinalResult(){
super.semiFinals = false;
}
}
public class France extends QuarterFinalTeam{
public France(){
super();
super.jerseyColor = "Blue White & Red";
}
public void quarterFinalResult(){
super.semiFinals = true;
}
}
public class Morocco extends QuarterFinalTeam{
public Morocco(){
super();
super.jerseyColor = "Red & Green";
}
public void quarterFinalResult(){
super.semiFinals = true;
}
}
public class Portugal extends QuarterFinalTeam{
public Portugal(){
super();
super.jerseyColor = "Red & Green";
}
public void quarterFinalResult(){
super.semiFinals = false;
}
}
QuarterFinalTeam.main(null);
import java.util.Date;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
public class Person {
private String name;
private String birthday;
public Person (String name, String birthday){
this.name = name;
this.birthday = birthday;
}
public String getName(){
return name;
}
public int getAge(){
if (this.birthday != null) {
// LocalDate birthDay = this.birthday.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
// return Period.between(birthDay, LocalDate.now()).getYears();
// too lazy to use a name thing
}
return -1;
}
}
public class Student extends Person {
private int grade;
private double gpa;
public Student (String name, String birthday, int grade, double gpa) {
super(name, birthday);
this.grade = grade;
this.gpa = gpa;
}
public int getGrade(){
return grade;
}
@Override
public String toString(){
return "wow crazy string, im too lazy to write a proper to string";
}
}
public class Teacher extends Person {
private String subject;
public Teacher (String name, String birthday, String subject){
super(name, birthday);
this.subject = subject;
}
@Override
public String toString(){
return "woah";
}
}
public class Main{
public static void main(String[] args){
Student nathan = new Student("Nathan", "Sometime in April? I think?", 11, 4.0);
System.out.println(nathan.toString());
Teacher mrMort = new Teacher("John Mortensen", "Old.", "Computer Science");
System.out.println(mrMort.toString());
}
}
Main.main(null);