minor changes, removed code related to lab 4

This commit is contained in:
Alexander Karpov 2023-12-12 12:36:03 +03:00
parent d634f98d9e
commit 5498cfa5a3
10 changed files with 40 additions and 233 deletions

View File

@ -60,78 +60,4 @@
## UML Diagram
![UML Diagram](https://new.akarpov.ru/media/files/sanspie/tFfur/diagram.svg "https://new.akarpov.ru/files/PRaEOtISfNJAvOZYJbiO")
# itmo-prog-lab-4
## Class Description
### StoryTeller
- The primary class of the application. It establishes the story's framework, incorporating the city, house, and characters, and initiates the storytelling process.
### Package: characters
- **Character.java**: This abstract class forms the foundation for all character types, implementing `Listenable` and `Conversable` interfaces.
- **Child.java**: Represents child characters who listen to and inquire about stories.
- **Traveler.java**: Depicts traveler characters who share tales of their adventures.
- **Znayka.java**: A specialized traveler character with extended capabilities.
### Package: enums
- **CharacterType.java**: Enumerates different character types, such as `TRAVELER` and `CHILD`.
### Package: interfaces
- **Listenable.java**: An interface for characters that can listen to stories.
- **Conversable.java**: An interface for characters that can engage in discussions about specific story subjects.
### Package: model
- **City.java**: Symbolizes a city in the story, featuring a method to simulate life resuming with changes.
- **House.java**: Represents a house where characters reside and where storytelling happens.
- **StoryElement.java**: An abstract base class for story components like City and House.
### Package: story
- **Narrative.java**: Manages a series of story events.
- **StoryContext.java**: Provides the narrative backdrop, linking the city, house, and the main story theme.
- **StoryEvent.java**: Constitutes individual events within the narrative.
### Package: exceptions
- **StoryException.java**: Handles exceptions specific to the storytelling process.
- **StoryRuntimeException.java**: Manages runtime exceptions within the story.
## Interactions and Configurations
- **StoryTeller**: Sets up the storytelling environment by creating a city, a house (Znayka's house), and characters (Znayka, Malish, and Malishka), then initiates the storytelling sequence in Znayka's house.
- **Character Classes**: Each character type (`Child`, `Traveler`, `Znayka`) interacts uniquely within the narrative. Children listen and pose questions, while travelers focus on recounting their adventures.
- **Interfaces**: `Listenable` and `Conversable` are implemented distinctly across character classes, enabling varied behaviors during the storytelling sessions.
- **Model Classes**: `City` and `House` form the physical backdrop of the story. The `House` class, in particular, is central to the gathering of characters and the exchange of stories.
- **Story Classes**: `StoryContext` connects the narrative's physical and thematic elements. `Narrative` and `StoryEvent` orchestrate the progression and individual occurrences of the story.
- **Exception Handling**: The `exceptions` package ensures robust error handling during the storytelling process, with `StoryException` and `StoryRuntimeException` tailored to specific storytelling scenarios.
## Output
```
Translating story on Bus 0 Device 0: ID 0x0:JMTek, LLC. USB PnP Audio Device
Translating story on Bus 1 Device 1: ID 0x10101:Creative Technology, Ltd SoundBlaster MP3+
Translating story on Bus 2 Device 2: ID 0x20202:Sennheiser Communications USB Headset
Translating story on Bus 3 Device 3: ID 0x30303:Bluetooth Audio Device
[DEBUG] Story Element Created: Цветочный город
[DEBUG] Story Element Created: Домик Знайки
[DEBUG] Story Element Created: TRAVELER Знайка
[DEBUG] Story Element Created: CHILD Малыш
[DEBUG] Story Element Created: CHILD Малышка
[DEBUG] Interaction with 'Домик Знайки': Starting evening stories session
Жители собираются в Домик Знайки чтобы рассказать истории
Все жители, и малыши и малышки, приходили по вечерам к Домик Знайки и слушали рассказы путешественников.
Жизнь в Цветочный город потекла по-старому... хотя нет, нельзя сказать, чтобы совсем по-старому.
Жители собираются в Домик Знайки чтобы рассказать истории
Знайка рассказывает историю о путешествие в Зеленый город
Малыш слушает историю о путешествия Знайки и спрашивает вопросы о путешествие в Зеленый город
Внезапный флешбенгер
[DEBUG] Interaction with 'Домик Знайки': Внезапный флешбенгер
Малышка слушает историю о путешествия Знайки и спрашивает вопросы о путешествие в Зеленый город
Знайка рассказывает историю о жизнь в Цветочном городе
Малыш слушает историю о путешествия Знайки и спрашивает вопросы о жизнь в Цветочном городе
Малышка слушает историю о путешествия Знайки и спрашивает вопросы о жизнь в Цветочном городе
Истории захватывали дух, и каждый вечер собирались всё больше жителей, чтобы слышать новые приключения.
Error in storytelling: No stories available to tell.
```
## UML Diagram
![UML Diagram](https://new.akarpov.ru/media/files/sanspie/DmZte/diagram.svg "https://new.akarpov.ru/files/YsvFMeuMCbOpfnOlOlyN")
![UML Diagram](https://new.akarpov.ru/media/files/sanspie/tFfur/diagram.svg "https://new.akarpov.ru/files/PRaEOtISfNJAvOZYJbiO")

View File

@ -1,5 +1,4 @@
import characters.Character;
import exceptions.StoryException;
import model.*;
import characters.*;
import story.StoryContext;
@ -9,26 +8,6 @@ import java.util.List;
public class StoryTeller {
public static void main(String[] args) {
class DevStoryListener {
private int devNum = 0;
void listenToStory(String device) {
System.out.println("Translating story on Bus " + devNum + " Device " + devNum + ": ID " + hashCode(devNum) + ":" + device );
devNum++;
}
private String hashCode(int devNum) {
return "0x" + Integer.toHexString(devNum * 0x10000 + devNum * 0x100 + devNum);
}
}
DevStoryListener listener = new DevStoryListener();
listener.listenToStory("JMTek, LLC. USB PnP Audio Device");
listener.listenToStory("Creative Technology, Ltd SoundBlaster MP3+");
listener.listenToStory("Sennheiser Communications USB Headset");
listener.listenToStory("Bluetooth Audio Device");
// На этом знаменитое путешествие Знайки и его товарищей окончилось.
// Жизнь в Цветочном городе потекла по-старому... хотя нет, нельзя сказать, чтобы совсем по-старому.
// С тех пор как наши отважные путешественники вернулись домой, в городе только и говорили о них.
@ -55,15 +34,5 @@ public class StoryTeller {
znaykasHouse.tellEveningStories(context, stories);
stories.clear();
try {
if (stories.isEmpty()) {
throw new StoryException("No stories available to tell.");
}
znaykasHouse.tellEveningStories(context, stories);
} catch (StoryException e) {
System.err.println("Error in storytelling: " + e.getMessage());
}
}
}

View File

@ -3,7 +3,7 @@ package characters;
import enums.CharacterType;
import interfaces.Conversable;
import interfaces.Listenable;
import model.StoryElement;
import story.StoryElement;
public abstract class Character extends StoryElement implements Listenable, Conversable {
protected CharacterType type;

View File

@ -1,7 +0,0 @@
package exceptions;
public class StoryException extends Exception {
public StoryException(String message) {
super(message);
}
}

View File

@ -1,7 +0,0 @@
package exceptions;
public class StoryRuntimeException extends RuntimeException {
public StoryRuntimeException(String message) {
super(message);
}
}

View File

@ -1,5 +1,7 @@
package model;
import story.StoryElement;
public class City extends StoryElement {
private final String name;

View File

@ -1,9 +1,8 @@
package model;
import characters.Character;
import exceptions.StoryRuntimeException;
import interfaces.Interactable;
import story.StoryContext;
import story.StoryElement;
import java.util.ArrayList;
import java.util.List;
@ -18,13 +17,6 @@ public class House extends StoryElement {
this.name = name;
this.residents = new ArrayList<>();
}
public void checkReadinessForStorytelling() {
if (this.residents.isEmpty()) {
throw new StoryRuntimeException("The house is empty, no one to tell stories to.");
}
}
public String getName() {
return this.name;
}
@ -44,8 +36,6 @@ public class House extends StoryElement {
}
public void tellEveningStories(StoryContext context, List<String> subjects) {
checkReadinessForStorytelling();
logger.logInteraction("Starting evening stories session");
context.gatherResidentsForStories();
context.getCity().returnToDailyLifeWithChanges();
@ -61,16 +51,6 @@ public class House extends StoryElement {
// now can just converse for everyone
event = resident.converse(context, subject);
System.out.println(event);
if (Math.random() > 0.80) {
new Interactable() {
@Override
public void interact(StoryContext context) {
System.out.println("Внезапный флешбенгер");
logger.logInteraction("Внезапный флешбенгер");
}
}.interact(context);
}
}
}

View File

@ -1,78 +0,0 @@
package model;
import java.time.LocalDateTime;
import java.util.Objects;
public abstract class StoryElement {
protected String description;
protected StoryMetadata metadata;
protected StoryLogger logger = new StoryLogger();
public StoryElement(String description) {
this.description = description;
this.metadata = new StoryMetadata();
logger.logCreation();
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "{" +
"description='" + description + '\'' +
'}';
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
StoryElement that = (StoryElement) obj;
return Objects.equals(description, that.description);
}
@Override
public int hashCode() {
return description != null ? description.hashCode() : 0;
}
public class StoryLogger {
public void logCreation() {
System.out.println("[DEBUG] Story Element Created: " + description);
}
public void logInteraction(String interaction) {
System.out.println("[DEBUG] Interaction with '" + description + "': " + interaction);
}
}
public static class StoryMetadata {
private final LocalDateTime creationDate;
private LocalDateTime lastUpdatedDate;
public StoryMetadata() {
this.creationDate = LocalDateTime.now();
this.lastUpdatedDate = creationDate;
}
// Getter and setters
public LocalDateTime getCreationDate() {
return creationDate;
}
public void setLastUpdatedDate(LocalDateTime lastUpdatedDate) {
this.lastUpdatedDate = lastUpdatedDate;
}
public String toString() {
return "StoryMetadata{" +
"creationDate=" + creationDate +
", lastUpdatedDate=" + lastUpdatedDate +
'}';
}
}
}

View File

@ -0,0 +1,35 @@
package story;
import java.util.Objects;
public abstract class StoryElement {
protected String description;
public StoryElement(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "{" +
"description='" + description + '\'' +
'}';
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
StoryElement that = (StoryElement) obj;
return Objects.equals(description, that.description);
}
@Override
public int hashCode() {
return description != null ? description.hashCode() : 0;
}
}

View File

@ -1,13 +0,0 @@
package story;
class StoryEvent {
private final String description;
public StoryEvent(String description) {
this.description = description;
}
public void occur() {
System.out.println(description);
}
}