Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5194aad
initial commit
Frank-Montgomery-Jr Jul 23, 2025
5753e94
test result 6
Frank-Montgomery-Jr Jul 23, 2025
89fa4d1
test 7-1
Frank-Montgomery-Jr Jul 23, 2025
98ce076
math. seq.
Frank-Montgomery-Jr Jul 23, 2025
1d378e9
binary conv.
Frank-Montgomery-Jr Jul 23, 2025
f98c022
number conv
Frank-Montgomery-Jr Jul 23, 2025
edac3cd
Array findMax
Frank-Montgomery-Jr Jul 23, 2025
ccc9e81
array average
Frank-Montgomery-Jr Jul 23, 2025
d90110e
completed proj.
Frank-Montgomery-Jr Jul 25, 2025
4386eb2
Exercise 4
Frank-Montgomery-Jr Jul 25, 2025
77eca5c
compare objects
Frank-Montgomery-Jr Jul 25, 2025
bd08fd5
Array Statistics
Frank-Montgomery-Jr Jul 25, 2025
821aceb
boo and Booleans 1-5
Frank-Montgomery-Jr Jul 25, 2025
30104c9
Boolean Object Practice
Frank-Montgomery-Jr Jul 25, 2025
a467801
Logic Simulator
Frank-Montgomery-Jr Jul 25, 2025
ffcd1c0
finished up to pattern printer
Frank-Montgomery-Jr Jul 26, 2025
79d1b1e
if-else-statements 1-3
Frank-Montgomery-Jr Jul 27, 2025
63fddfd
if-statements 4,5
Frank-Montgomery-Jr Jul 28, 2025
837c0d5
object references 1 and subs
Frank-Montgomery-Jr Jul 28, 2025
7856f42
Null Handling 1-6 complete
Frank-Montgomery-Jr Jul 29, 2025
493f262
Finished Array References
Frank-Montgomery-Jr Jul 29, 2025
3d370dd
done 1-4
Frank-Montgomery-Jr Jul 30, 2025
e195b53
completed obj-ref
Frank-Montgomery-Jr Jul 30, 2025
aa51998
Finished while loops, lost some content
Frank-Montgomery-Jr Jul 30, 2025
0147c35
Strings 1-4
Frank-Montgomery-Jr Jul 31, 2025
59bcc82
completed strings
Frank-Montgomery-Jr Jul 31, 2025
349bec9
car class in classes in objects
Frank-Montgomery-Jr Aug 1, 2025
cfda5ab
Merge branch 'main' of https://github.com/FrankMontgomery063/JavaFund…
Frank-Montgomery-Jr Aug 1, 2025
e9102d4
finished classes and objects
Frank-Montgomery-Jr Aug 1, 2025
8f1d0c2
made some changes
Frank-Montgomery-Jr Aug 6, 2025
4f85d04
fixed merge conflicts
Frank-Montgomery-Jr Aug 6, 2025
c94910f
LibraryItem 1
Frank-Montgomery-Jr Nov 10, 2025
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
233 changes: 193 additions & 40 deletions java-org/classes-and-objects/topic.jsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,130 +5,283 @@ import java.util.ArrayList;
// Exercise 1: Basic Class Creation
// Create a Person class with name and age fields
class Person {
// Your fields here
String name;
int age;

// Your constructor here
public Person(String name, int age) {
this.name = name;
this.age = age;
}

public String introduce() {
return "Hello, I'm " + name + " and I'm " + age + " years old.";

// Your introduce() method here
}

}


// Exercise 2: Class with Methods
// Create a BankAccount class with account operations
class BankAccount {
// Your fields here

// Your constructor here

// Your deposit method here

// Your withdraw method here

// Your getBalance method here
public class BankAccount {
String accountNumber;
double balance;

public BankAccount(String accountNumber) {
this.accountNumber = accountNumber;
this.balance = 0.0;
}

public double deposit(double amount) {
balance += amount;
return balance;
}

public double withdraw(double amount) {
if(amount > 0 && amount <= balance) {
balance -= amount;
}
return balance;
}

// Your getAccountInfo method here
public double getBalance() {
return balance;

}

public String getAccountInfo() {
return "accountNumber: " + accountNumber + ", Balance: $" + balance;
}


}

// Exercise 3: Object Creation and Usage
// Create and return a Person object
public Person createPerson(String name, int age) {
// Your code here
Person person = new Person(name, age);
return person;

}

// Create and return a BankAccount object
public BankAccount createBankAccount(String accountNumber) {
// Your code here
BankAccount account = new BankAccount(accountNumber);
return account;

}

// Demonstrate creating and using a Person object
public void demonstratePersonUsage() {
// Your code here
Person person = createPerson("Alice", 30);
System.out.println(person.introduce()); //

}

// Exercise 4: Working with Multiple Objects
// Create a Car class
class Car {
// Your fields here
String brand;
String model;
int year;

// Your constructor here
public Car(String brand, String model, int year) {
this.brand = brand;
this.model = model;
this.year = year;
}

// Your getCarInfo method here
public String getCarInfo() {
return "Car: " + brand + " " + model + ", Year: " + year;
}

// Your isClassic method here (car is classic if > 25 years old)
public boolean isClassic() {
int currentYear = 2025;
return (currentYear - year) > 25;

}

public int getCarYear() {
return year;
}

}

// Compare two cars and return which is older
public Car compareCars(Car car1, Car car2) {
// Your code here
if (car1.getCarYear() < car2.getCarYear()) {
return car1;
} else if (car1.getCarYear() > car2.getCarYear()){
return car2;
}
return null;

}

// Exercise 5: Object State and Behavior
// Create a Counter class that can increment/decrement
class Counter {
// Your fields here

// Your constructor here

// Your increment method here

// Your decrement method here

// Your reset method here

// Your getCount method here
private int count;

public Counter() {
this.count = 0;
}

public int increment() {
count++;
return count;
}

public int decrement() {
if (count > 0) {
count--;
}
return count;
}

public int reset() {
count = 0;
return count;
}

public int getCount() {
return count;
}

}

// Demonstrate the Counter classpublic class HelloWorld {
// public static void main(String[] args)

// Exercise 6: Class with Validation
// Create a Student class with input validation
System.out.println("Student System");
class Student {
// Your fields here

// Your constructor with validation here

// Your isHonorStudent method here

String name;
int grade;
double gpa;

public Student(String name, int grade, double gpa) throws Exception {
if ( name == null || name.isEmpty()) {
throw new Exception("Name cannot be null or empty");
}
this.name = name;

if (grade < 1 || grade > 12) {
throw new Exception("Grade must be between 1 and 12");
}
this.grade = grade;

if (gpa < 0.0 || gpa > 4.0) {
throw new Exception("GPA must be between 0.0 and");
}
this.gpa = gpa;

}

public boolean isHonorStudent() {
return gpa >= 3.5;
}

// Your getStudentInfo method here
public String getStudentInfo(){
return "Student:" + name + ", Grade: " + grade + ", GPA: " + gpa;
}

}

// Exercise 7: Object Interaction
// Create a Book class
System.out.println("Book System");
class Book {
// Your fields here
String title;
String author;
boolean isCheckedOut;

// Your constructor here
public Book(String title, String author, boolean isCheckedOut) {
this.title = title;
this.author = author;
this.isCheckedOut = isCheckedOut;
}

// Add any helpful methods here
public String getTitle() {
return title;
}

public String getAuthor() {
return author;
}

public boolean getIsCheckedOut() {
return isCheckedOut;
}

}

// Create a Library class that manages books
class Library {
System.out.println("Library System");
public class Library {
// Your fields here
ArrayList<Book> books;

// Your constructor here
public Library() {
books = new ArrayList<Book>();
}


// Your addBook method here

public void addBook(Book book) {
books.add(book);
}

// Your checkOutBook method here

public String checkOutBook(String title) {
for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title) && !book.getIsCheckedOut()) {
book.isCheckedOut = true;
return "Checked out; " + title;
} else if (book.getTitle().equalsIgnoreCase(title) && book.getIsCheckedOut()) {
return "Book is already checked out: " + title;
}
}
return "Book not found: " + title;

}

// Your returnBook method here
public String returnBook(String title) {
for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title) && book.getIsCheckedOut()) {
book.isCheckedOut = false;
return "Returned Book; " + title;
} else if (book.getTitle().equalsIgnoreCase(title) && !book.getIsCheckedOut()) {
return "Book is already in the library: " + title;
}
}
return "Book not found: " + title;
}


// Your getAvailableBooks method here
public int getAvailableBooks() {
return books.size();
}

}

// Test your classes here - uncomment and modify as needed
/*

System.out.println("Testing Person class:");
Person person1 = createPerson("Alice", 30);
Person person1 = createPerson("Frank", 30);
Person person2 = new Person("Bob", 25);
System.out.println(person1.introduce());
System.out.println(person2.introduce());
Expand Down Expand Up @@ -192,4 +345,4 @@ System.out.println("After checking out 1984: " + library.getAvailableBooks());

library.returnBook("1984");
System.out.println("After returning 1984: " + library.getAvailableBooks());
*/

6 changes: 5 additions & 1 deletion java-org/nested-objects/topic.jsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Address {

public Address(String street, String city, String state, String zipCode) {
// TODO: Initialize all fields
this.street = street;
this.city = city;
this.state = state;
this.zipCode = zipCode;
}

public String getFullAddress() {
Expand Down Expand Up @@ -428,7 +432,7 @@ class Customer {

public double getTotalBalance() {
// TODO: Sum balances of all accounts
return 0.0;
return 12223343450.0;
}

public String getAccountSummary() {
Expand Down
4 changes: 3 additions & 1 deletion java-org/parameters-and-return-values/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A method's signature defines its interface:
```java
public returnType methodName(parameterType1 param1, parameterType2 param2) {
// Method body
return someValue; // Must match returnType
return someValue;
}
```

Expand All @@ -36,6 +36,7 @@ public double calculateInterest(double principal, double rate, int years) {
public void processNumbers(int count, double amount, boolean isActive) {
// count, amount, isActive are copies of the original values
// Modifying them here doesn't affect the original values

}
```

Expand All @@ -52,6 +53,7 @@ public void processList(ArrayList<String> items) {
public double findAverage(double[] numbers) {
// numbers refers to the same array as the caller
// You can modify array contents, but not the array reference itself
for ()
}
```

Expand Down
Loading