Skip to content

Conformed to Java conventions and updated all directories of Chapter 7. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/main/java/chapter07/datetest/DateComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Code written as part of the Java-Methods-Program-AP-Comp-A-2021-2022 repository on GitHub.
package chapter07.datetest;

import java.util.Scanner;

public class DateComparator {
/**
* Compares two dates. No input verification.
* @return {@code true} if the first date is strictly later in the year and {@code false} otherwise.
*/
public static boolean isLater(int month1, int day1, int year1, int month2, int day2, int year2) {
if (year1 == year2) {
if (month1 == month2) {
return day1 > day2;
}
return month1 > month2;
}
return year1 > year2;
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the first date (month day year): ");
int month1 = scanner.nextInt();
int day1 = scanner.nextInt();
int year1 = scanner.nextInt();

System.out.print("Enter the second date (month day year): ");
int month2 = scanner.nextInt();
int day2 = scanner.nextInt();
int year2 = scanner.nextInt();

System.out.println(); // newline

String message = month1 + "/" + day1 + "/" + year1 + " ";
if (isLater(month1, day1, year1, month2, day2, year2)) {
message += "IS";
} else {
message += "is NOT";
}
message += " later than " + month2 + "/" + day2 + "/" + year2 + ".";
System.out.println(message);
}
}
53 changes: 0 additions & 53 deletions src/main/java/chapter07/datetest/TheClass.java

This file was deleted.

36 changes: 36 additions & 0 deletions src/main/java/chapter07/findbestfit/BestFitFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Code written as part of the Java-Methods-Program-AP-Comp-A-2021-2022 repository on GitHub.
package chapter07.findbestfit;

import java.util.Scanner;

public class BestFitFinder {
public static int findBestFit(int size1, int size2, int space) {
int sizeSum = size1 + size2;
int returnValue;

if (sizeSum <= space) {
returnValue = 3;
} else if (size2 > size1 && size2 <= space) {
returnValue = 2;
} else if (size1 >= size2 && size1 <= space) {
returnValue = 1;
} else {
returnValue = 0;
}

return returnValue;
}

public static void main(String[] args) {
Scanner theScanner = new Scanner(System.in);

System.out.print("Enter the first file size: ");
int size1 = theScanner.nextInt();
System.out.print("Enter the second file size: ");
int size2 = theScanner.nextInt();
System.out.print("Enter the total storage space: ");
int space = theScanner.nextInt();

System.out.println(findBestFit(size1, size2, space));
}
}
42 changes: 0 additions & 42 deletions src/main/java/chapter07/findbestfit/TheClass.java

This file was deleted.

36 changes: 36 additions & 0 deletions src/main/java/chapter07/leapyear/LeapYearChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Code written as part of the Java-Methods-Program-AP-Comp-A-2021-2022 repository on GitHub.
package chapter07.leapyear;

import java.util.Scanner;

/**
* A class that provides a method that determines if a year is a leap year.
*/
public class LeapYearChecker {
/**
* Determines if the given year is a leap year in the Gregorian calendar.
* <p>
* Accurate only for positive integers as there is no 0 CE. Since the common era and before it starts at year
* 1, negative numbers are not accurately computed as years BCE.
*
* @param year a positive integer year.
* @return {@code true} if it is a leap year in the common era, undefined otherwise.
*/
public static Boolean isLeapYear(int year) {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

public static void main(String[] args) {
Scanner theScanner = new Scanner(System.in);

System.out.print("Please input your year: ");
int years = theScanner.nextInt();
theScanner.close();

if (isLeapYear(years)) {
System.out.println("This is a leap year");
} else {
System.out.println("This is NOT a leap year");
}
}
}
41 changes: 0 additions & 41 deletions src/main/java/chapter07/leapyear/TheYear.java

This file was deleted.