diff --git a/com/study/demo3/Bicycle.class b/com/study/demo3/Bicycle.class new file mode 100644 index 0000000..8cb0107 Binary files /dev/null and b/com/study/demo3/Bicycle.class differ diff --git a/com/study/demo3/Bicycle.java b/com/study/demo3/Bicycle.java new file mode 100644 index 0000000..5a2d76a --- /dev/null +++ b/com/study/demo3/Bicycle.java @@ -0,0 +1,7 @@ +package com.study.demo3; +public class Bicycle extends Vehicle { + @Override + public void start() { + System.out.println("The bike is started"); + } +} diff --git a/com/study/demo3/Book.class b/com/study/demo3/Book.class new file mode 100644 index 0000000..3c8d5f2 Binary files /dev/null and b/com/study/demo3/Book.class differ diff --git a/com/study/demo3/Book.java b/com/study/demo3/Book.java new file mode 100644 index 0000000..bcb0cc2 --- /dev/null +++ b/com/study/demo3/Book.java @@ -0,0 +1,61 @@ +package com.study.demo3; + +public class Book { + protected String isbn; + protected String title; + protected boolean available; + + + public Book() { + this.available = true; + } + + + public Book(String isbn, String title) { + this.isbn = isbn; + this.title = title; + this.available = true; + } + + + public Book(String isbn, String title, boolean available) { + this.isbn = isbn; + this.title = title; + this.available = available; + } + + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public boolean isAvailable() { + return available; + } + + public void setAvailable(boolean available) { + this.available = available; + } + + + public void returnBook() { + if (!this.available) { + this.available = true; + System.out.println(this.title + " (ISBN: " + this.isbn + ") has been returned and is now available."); + } else { + System.out.println(this.title + " (ISBN: " + this.isbn + ") is already available."); + } + } +} diff --git a/com/study/demo3/Car.class b/com/study/demo3/Car.class new file mode 100644 index 0000000..7a34b27 Binary files /dev/null and b/com/study/demo3/Car.class differ diff --git a/com/study/demo3/Car.java b/com/study/demo3/Car.java new file mode 100644 index 0000000..91dc698 --- /dev/null +++ b/com/study/demo3/Car.java @@ -0,0 +1,8 @@ +package com.study.demo3; +public class Car extends Vehicle { + @Override + + public void start() { + System.out.println("The car is started"); + } +} diff --git a/com/study/demo3/EBook.class b/com/study/demo3/EBook.class new file mode 100644 index 0000000..4800637 Binary files /dev/null and b/com/study/demo3/EBook.class differ diff --git a/com/study/demo3/EBook.java b/com/study/demo3/EBook.java new file mode 100644 index 0000000..ccbac3f --- /dev/null +++ b/com/study/demo3/EBook.java @@ -0,0 +1,30 @@ +package com.study.demo3; +public class EBook extends Book { + private double fileSize; + + + public EBook() { + super(); + } + + + + public EBook(String isbn, String title, double fileSize) { + super(isbn, title); + this.fileSize = fileSize; + } + + + public double getFileSize() { + return fileSize; + } + + public void setFileSize(double fileSize) { + this.fileSize = fileSize; + } + + @Override + public String toString() { + return "EBook [ISBN=" + isbn + ", Title=" + title + ", FileSize=" + fileSize + "MB, Available=" + available + "]"; + } +} diff --git a/com/study/demo3/Library.class b/com/study/demo3/Library.class new file mode 100644 index 0000000..ce16e21 Binary files /dev/null and b/com/study/demo3/Library.class differ diff --git a/com/study/demo3/Library.java b/com/study/demo3/Library.java new file mode 100644 index 0000000..b64d39c --- /dev/null +++ b/com/study/demo3/Library.java @@ -0,0 +1,42 @@ +package com.study.demo3; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.ArrayList; + +public class Library { + + private Map books; + + public Library() { + this.books = new HashMap<>(); + } + + + + public void addBook(Book b) { + String isbn = b.getIsbn(); + + + if (books.containsKey(isbn)) { + System.out.println("The book already exists, adding it failed."); + } else { + books.put(isbn, b); + System.out.println("Book added successfully: " + b.getTitle()); + } + } + + + + public List searchAvailableBooks() { + List availableBooks = new ArrayList<>(); + + + for (Book book : books.values()) { + if (book.isAvailable()) { + availableBooks.add(book); + } + } + return availableBooks; + } +} diff --git a/com/study/demo3/LibraryTest.class b/com/study/demo3/LibraryTest.class new file mode 100644 index 0000000..25a3772 Binary files /dev/null and b/com/study/demo3/LibraryTest.class differ diff --git a/com/study/demo3/LibraryTest.java b/com/study/demo3/LibraryTest.java new file mode 100644 index 0000000..46baa61 --- /dev/null +++ b/com/study/demo3/LibraryTest.java @@ -0,0 +1,44 @@ +package com.study.demo3; +import java.util.List; + +public class LibraryTest { + public static void main(String[] args) { + Library lib = new Library(); + + + EBook e1 = new EBook("E001", "Java Basics", 5.2); + + e1.setAvailable(false); + + + PrintedBook p1 = new PrintedBook("P001", "Design Patterns", 3); + + + lib.addBook(e1); + lib.addBook(p1); + + + lib.addBook(p1); + + + System.out.println("\n--- 可借阅图书列表 (available = true) ---"); + List availableList = lib.searchAvailableBooks(); + + if (availableList.isEmpty()) { + System.out.println("No books are currently available for loan."); + } else { + for (Book book : availableList) { + + System.out.println("- " + book.getTitle() + " (ISBN: " + book.getIsbn() + ")"); + } + } + + + e1.returnBook(); + System.out.println("\n--- 恢复 e1 后可借阅图书列表 ---"); + availableList = lib.searchAvailableBooks(); + for (Book book : availableList) { + System.out.println("- " + book.getTitle() + " (ISBN: " + book.getIsbn() + ")"); + } + } +} diff --git a/com/study/demo3/Main2.class b/com/study/demo3/Main2.class new file mode 100644 index 0000000..fadc973 Binary files /dev/null and b/com/study/demo3/Main2.class differ diff --git a/com/study/demo3/Main3.java b/com/study/demo3/Main3.java new file mode 100644 index 0000000..1d41593 --- /dev/null +++ b/com/study/demo3/Main3.java @@ -0,0 +1,34 @@ +package com.study.demo3; +public class Main { + public static void main(String[] args) { + + System.out.println("--- 测试 EBook ---"); + + EBook ebook = new EBook("123-456", "Java Programming", 2.5); + System.out.println("EBook Status (Initial): " + ebook.toString()); + + + ebook.setAvailable(false); + System.out.println("EBook Status (Borrowed): " + ebook.toString()); + + + ebook.returnBook(); + System.out.println("EBook Status (After Return): " + ebook.toString()); + + + System.out.println("\n--- 测试 PrintedBook ---"); + PrintedBook pbook = new PrintedBook(); + pbook.setIsbn("789-012"); + pbook.setTitle("Python Guide"); + pbook.setStock(10); + System.out.println("PBook Status (Initial): " + pbook.toString()); + + + pbook.setAvailable(false); + System.out.println("PBook Status (Borrowed): " + pbook.toString()); + + + pbook.returnBook(); + System.out.println("PBook Status (After Return): " + pbook.toString()); + } +} diff --git a/com/study/demo3/PrintedBook.class b/com/study/demo3/PrintedBook.class new file mode 100644 index 0000000..2583d90 Binary files /dev/null and b/com/study/demo3/PrintedBook.class differ diff --git a/com/study/demo3/PrintedBook.java b/com/study/demo3/PrintedBook.java new file mode 100644 index 0000000..18f9be1 --- /dev/null +++ b/com/study/demo3/PrintedBook.java @@ -0,0 +1,29 @@ +package com.study.demo3; +public class PrintedBook extends Book { + private int stock; + + + public PrintedBook() { + super(); + } + + + public PrintedBook(String isbn, String title, int stock) { + super(isbn, title); + this.stock = stock; + } + + + public int getStock() { + return stock; + } + + public void setStock(int stock) { + this.stock = stock; + } + + @Override + public String toString() { + return "PrintedBook [ISBN=" + isbn + ", Title=" + title + ", Stock=" + stock + ", Available=" + available + "]"; + } +} diff --git a/com/study/demo3/StudentManager.class b/com/study/demo3/StudentManager.class new file mode 100644 index 0000000..4e06966 Binary files /dev/null and b/com/study/demo3/StudentManager.class differ diff --git a/com/study/demo3/StudentManager.java b/com/study/demo3/StudentManager.java new file mode 100644 index 0000000..be20826 --- /dev/null +++ b/com/study/demo3/StudentManager.java @@ -0,0 +1,28 @@ +package com.study.demo3; +import java.util.*; + +public class StudentManager { + public static void main(String[] args) { + List studentNames = new ArrayList<>(); + Map studentScores = new HashMap<>(); + + studentNames.add("张三"); + studentNames.add("李四"); + studentNames.add("王五"); + + studentScores.put("张三", 85); + studentScores.put("李四", 77); + studentScores.put("王五", 99); + + System.out.println("--- 所有学生姓名 ---"); + for (String name : studentNames) { + System.out.println(name); + } + + studentScores.put("张三", 70); + + Integer zhangsanScore = studentScores.get("张三"); + System.out.println("\n--- 修改后张三的成绩 ---"); + System.out.println("张三的成绩: " + zhangsanScore); + } +} diff --git a/com/study/demo3/Train.class b/com/study/demo3/Train.class new file mode 100644 index 0000000..2405a80 Binary files /dev/null and b/com/study/demo3/Train.class differ diff --git a/com/study/demo3/Train.java b/com/study/demo3/Train.java new file mode 100644 index 0000000..d99c2ff --- /dev/null +++ b/com/study/demo3/Train.java @@ -0,0 +1,7 @@ +package com.study.demo3; +public class Train extends Vehicle { + @Override + public void start() { + System.out.println("The train is started"); + } +} diff --git a/com/study/demo3/Vehicle.class b/com/study/demo3/Vehicle.class new file mode 100644 index 0000000..fba2811 Binary files /dev/null and b/com/study/demo3/Vehicle.class differ diff --git a/com/study/demo3/Vehicle.java b/com/study/demo3/Vehicle.java new file mode 100644 index 0000000..7d86d57 --- /dev/null +++ b/com/study/demo3/Vehicle.java @@ -0,0 +1,20 @@ +package com.study.demo3; +public class Vehicle { + protected String name; + + public Vehicle(String name) { + this.name = name; + } + + public Vehicle() { + this.name = "Unknown Vehicle"; + } + + public void start() { + System.out.println("Vehicle Start"); + } + + public void stop() { + System.out.println("Vehicle Stop"); + } +}