diff --git a/.DS_Store b/.DS_Store index c6e43b4..32aa02b 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Class Diagram.pdf b/Class Diagram.pdf new file mode 100644 index 0000000..e2cea7d Binary files /dev/null and b/Class Diagram.pdf differ diff --git a/Java_Project/.classpath b/Java_Project/.classpath new file mode 100644 index 0000000..9affd48 --- /dev/null +++ b/Java_Project/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Java_Project/.metadata/.lock b/Java_Project/.metadata/.lock new file mode 100644 index 0000000..e69de29 diff --git a/Java_Project/.metadata/.log b/Java_Project/.metadata/.log new file mode 100644 index 0000000..44d55bf --- /dev/null +++ b/Java_Project/.metadata/.log @@ -0,0 +1,20 @@ +!SESSION 2024-03-29 15:44:48.794 ----------------------------------------------- +eclipse.buildId=4.31.0.20240307-1200 +java.version=21.0.2 +java.vendor=Oracle Corporation +BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN +Framework arguments: -product org.eclipse.epp.package.java.product +Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product + +!ENTRY ch.qos.logback.classic 1 0 2024-03-29 15:44:51.287 +!MESSAGE Activated before the state location was initialized. Retry after the state location is initialized. + +!ENTRY ch.qos.logback.classic 1 0 2024-03-29 15:45:06.774 +!MESSAGE Logback config file: C:\Users\Tian\Desktop\adProgram\-CNSCC.212-Advanced-Programming\Java_Project\.metadata\.plugins\org.eclipse.m2e.logback\logback.2.6.0.20240217-1525.xml + +!ENTRY org.eclipse.egit.ui 2 0 2024-03-29 15:45:12.786 +!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git +user global configuration and to define the default location to store repositories: 'C:\Users\Tian'. If this is +not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and +EGit might behave differently since they see different configuration options. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. diff --git a/Java_Project/.metadata/.mylyn/.taskListIndex/segments_1 b/Java_Project/.metadata/.mylyn/.taskListIndex/segments_1 new file mode 100644 index 0000000..f5edc0f Binary files /dev/null and b/Java_Project/.metadata/.mylyn/.taskListIndex/segments_1 differ diff --git a/Java_Project/.metadata/.mylyn/.taskListIndex/write.lock b/Java_Project/.metadata/.mylyn/.taskListIndex/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/Java_Project/.metadata/.mylyn/repositories.xml.zip b/Java_Project/.metadata/.mylyn/repositories.xml.zip new file mode 100644 index 0000000..b298d02 Binary files /dev/null and b/Java_Project/.metadata/.mylyn/repositories.xml.zip differ diff --git a/Java_Project/.metadata/.mylyn/tasks.xml.zip b/Java_Project/.metadata/.mylyn/tasks.xml.zip new file mode 100644 index 0000000..71b48ad Binary files /dev/null and b/Java_Project/.metadata/.mylyn/tasks.xml.zip differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location new file mode 100644 index 0000000..5368b14 Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version new file mode 100644 index 0000000..25cb955 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/history.version @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index new file mode 100644 index 0000000..d237251 Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version new file mode 100644 index 0000000..6b2aaa7 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.version @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree new file mode 100644 index 0000000..96754ac Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources new file mode 100644 index 0000000..c9bc4da Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..30841eb --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding=UTF-8 +version=1 diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..c5f59ce --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.ui.formatterprofiles.version=23 +spelling_locale_initialized=true +typefilter_migrated_2=true +useAnnotationsPrefPage=true +useQuickDiffPrefPage=true diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jsch.core.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jsch.core.prefs new file mode 100644 index 0000000..d56c53f --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jsch.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jsch.core.hasChangedDefaultWin32SshHome=true diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs new file mode 100644 index 0000000..67b1d96 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.m2e.discovery.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.m2e.discovery.pref.projects= diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.context.core.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.context.core.prefs new file mode 100644 index 0000000..43e97e4 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.context.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +mylyn.attention.migrated=true diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.monitor.ui.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.monitor.ui.prefs new file mode 100644 index 0000000..8d462a6 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.monitor.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.mylyn.monitor.activity.tracking.enabled.checked=true diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.tasks.ui.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.tasks.ui.prefs new file mode 100644 index 0000000..2b60c21 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.mylyn.tasks.ui.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +migrated.task.repositories.secure.store=true +org.eclipse.mylyn.tasks.ui.filters.nonmatching=true +org.eclipse.mylyn.tasks.ui.filters.nonmatching.encouraged=true +org.eclipse.mylyn.tasks.ui.welcome.message=true diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs new file mode 100644 index 0000000..e5bca88 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.ide.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +platformState=889949826458941 +quickStart=false +tipsAndTricks=true diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs new file mode 100644 index 0000000..08076f2 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +showIntro=false diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs new file mode 100644 index 0000000..7e380fb --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs @@ -0,0 +1,12 @@ +//org.eclipse.ui.commands/state/org.eclipse.ui.navigator.resources.nested.changeProjectPresentation/org.eclipse.ui.commands.radioState=false +PLUGINS_NOT_ACTIVATED_ON_STARTUP=;org.eclipse.m2e.discovery; +eclipse.preferences.version=1 +org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_END=41,41,41 +org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START=43,44,45 +org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_TEXT_COLOR=204,204,204 +org.eclipse.ui.workbench.ACTIVE_TAB_BG_END=41,41,41 +org.eclipse.ui.workbench.ACTIVE_TAB_BG_START=43,44,45 +org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR=221,221,221 +org.eclipse.ui.workbench.INACTIVE_TAB_BG_END=49,53,56 +org.eclipse.ui.workbench.INACTIVE_TAB_BG_START=59,64,66 +org.eclipse.ui.workbench.INACTIVE_TAB_TEXT_COLOR=187,187,187 diff --git a/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.urischeme.prefs b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.urischeme.prefs new file mode 100644 index 0000000..b48c0c4 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.urischeme.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +processedSchemes=,eclipse+mpc,eclipse+command diff --git a/Java_Project/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/Java_Project/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi new file mode 100644 index 0000000..9a77ffd --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi @@ -0,0 +1,2432 @@ + + + + activeSchemeId:org.eclipse.ui.defaultAcceleratorConfiguration + + + + + + + + topLevel + shellMaximized + + + + + persp.actionSet:org.eclipse.mylyn.tasks.ui.navigation + persp.actionSet:org.eclipse.ui.cheatsheets.actionSet + persp.actionSet:org.eclipse.search.searchActionSet + persp.actionSet:org.eclipse.text.quicksearch.actionSet + persp.actionSet:org.eclipse.ui.edit.text.actionSet.annotationNavigation + persp.actionSet:org.eclipse.ui.edit.text.actionSet.navigation + persp.actionSet:org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo + persp.actionSet:org.eclipse.ui.externaltools.ExternalToolsSet + persp.actionSet:org.eclipse.ui.actionSet.keyBindings + persp.actionSet:org.eclipse.ui.actionSet.openFiles + persp.actionSet:org.eclipse.debug.ui.launchActionSet + persp.actionSet:org.eclipse.jdt.ui.JavaActionSet + persp.actionSet:org.eclipse.jdt.ui.JavaElementCreationActionSet + persp.actionSet:org.eclipse.ui.NavigateActionSet + persp.viewSC:org.eclipse.jdt.ui.PackageExplorer + persp.viewSC:org.eclipse.jdt.ui.TypeHierarchy + persp.viewSC:org.eclipse.jdt.ui.SourceView + persp.viewSC:org.eclipse.jdt.ui.JavadocView + persp.viewSC:org.eclipse.search.ui.views.SearchView + persp.viewSC:org.eclipse.ui.console.ConsoleView + persp.viewSC:org.eclipse.ui.views.ContentOutline + persp.viewSC:org.eclipse.ui.views.ProblemView + persp.viewSC:org.eclipse.ui.views.TaskList + persp.viewSC:org.eclipse.ui.views.ProgressView + persp.viewSC:org.eclipse.ui.navigator.ProjectExplorer + persp.viewSC:org.eclipse.ui.texteditor.TemplatesView + persp.viewSC:org.eclipse.pde.runtime.LogView + persp.newWizSC:org.eclipse.jdt.ui.wizards.JavaProjectWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewPackageCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewClassCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewEnumCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewRecordCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewAnnotationCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewSourceFolderCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewSnippetFileCreationWizard + persp.newWizSC:org.eclipse.jdt.ui.wizards.NewJavaWorkingSetWizard + persp.newWizSC:org.eclipse.ui.wizards.new.folder + persp.newWizSC:org.eclipse.ui.wizards.new.file + persp.newWizSC:org.eclipse.ui.editors.wizards.UntitledTextFileWizard + persp.perspSC:org.eclipse.jdt.ui.JavaBrowsingPerspective + persp.perspSC:org.eclipse.debug.ui.DebugPerspective + persp.editorOnboardingImageUri:platform:/plugin/org.eclipse.jdt.ui/$nl$/icons/full/onboarding_jperspective.png + persp.editorOnboardingText:Open a file or drop files here to open them. + persp.showIn:org.eclipse.jdt.ui.PackageExplorer + persp.showIn:org.eclipse.team.ui.GenericHistoryView + persp.showIn:org.eclipse.ui.navigator.ProjectExplorer + persp.editorOnboardingCommand:Find Actions$$$Ctrl+3 + persp.editorOnboardingCommand:Show Key Assist$$$Ctrl+Shift+L + persp.editorOnboardingCommand:New$$$Ctrl+N + persp.editorOnboardingCommand:Open Type$$$Ctrl+Shift+T + persp.viewSC:org.eclipse.mylyn.tasks.ui.views.tasks + persp.newWizSC:org.eclipse.mylyn.tasks.ui.wizards.new.repository.task + persp.actionSet:org.eclipse.debug.ui.breakpointActionSet + persp.actionSet:org.eclipse.jdt.debug.ui.JDTDebugActionSet + persp.showIn:org.eclipse.egit.ui.RepositoriesView + persp.newWizSC:org.eclipse.m2e.core.wizards.Maven2ProjectWizard + persp.actionSet:org.eclipse.eclemma.ui.CoverageActionSet + persp.showIn:org.eclipse.eclemma.ui.CoverageView + persp.viewSC:org.eclipse.tm.terminal.view.ui.TerminalsView + persp.showIn:org.eclipse.tm.terminal.view.ui.TerminalsView + persp.viewSC:org.eclipse.jdt.bcoview.views.BytecodeOutlineView + persp.newWizSC:org.eclipse.jdt.junit.wizards.NewTestCaseCreationWizard + persp.actionSet:org.eclipse.jdt.junit.JUnitActionSet + persp.viewSC:org.eclipse.ant.ui.views.AntView + + + + org.eclipse.e4.primaryNavigationStack + active + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:General + + + View + categoryTag:Java + + + + + View + categoryTag:Git + + + + + + + + + + View + categoryTag:Mylyn + + + + org.eclipse.e4.secondaryNavigationStack + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:Java + + + View + categoryTag:Ant + + + + + + org.eclipse.e4.secondaryDataStack + + View + categoryTag:General + + + View + categoryTag:Java + + + View + categoryTag:Java + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:General + + + View + categoryTag:Terminal + + + + + + + + + View + categoryTag:Help + + + View + categoryTag:General + + + View + categoryTag:Help + + + + + + + View + categoryTag:Help + + + + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + + + View + categoryTag:Help + + + + org.eclipse.e4.primaryDataStack + EditorStack + + + + + + + View + categoryTag:Java + active + activeOnClose + + ViewMenu + menuContribution:menu + + + + + + + View + categoryTag:Java + + + + + View + categoryTag:General + + + + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + + + View + categoryTag:Java + + + + + View + categoryTag:Java + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + + View + categoryTag:General + + ViewMenu + menuContribution:menu + + + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + + View + categoryTag:Mylyn + + ViewMenu + menuContribution:menu + + + + + + + View + categoryTag:Git + + + + + View + categoryTag:Terminal + + + + + View + categoryTag:Java + + + + + View + categoryTag:Java + + + + + View + categoryTag:Ant + + + + toolbarSeparator + + + + Draggable + + + + toolbarSeparator + + + + Draggable + + + + + toolbarSeparator + + + + Draggable + + + Draggable + + + Draggable + + + toolbarSeparator + + + + Draggable + + + + toolbarSeparator + + + + toolbarSeparator + + + + Draggable + + + stretch + SHOW_RESTORE_MENU + + + Draggable + HIDEABLE + SHOW_RESTORE_MENU + + + + + stretch + + + Draggable + + + Draggable + + + + + TrimStack + Draggable + + + + + + + + + + + + + + + + + + + + platform:win32 + + + + + + + + + locale:zh + + + + + + + + + + + + + + + + + + + + + + locale:zh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + locale:zh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + locale:zh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + platform:win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Editor + removeOnHide + + + + + View + categoryTag:Ant + + + + + View + categoryTag:Gradle + + + + + View + categoryTag:Gradle + + + + + View + categoryTag:Debug + + + + + View + categoryTag:Debug + + + + + View + categoryTag:Debug + + + + + View + categoryTag:Debug + + + + + View + categoryTag:Debug + + + + + View + categoryTag:Debug + + + + + View + categoryTag:Debug + + + View + categoryTag:Debug + + + + + View + categoryTag:Java + + + + + View + categoryTag:Git + + + + + View + categoryTag:Git + + + + + View + categoryTag:Git + + + + + View + categoryTag:Git + NoRestore + + + + + View + categoryTag:Git + + + + + View + categoryTag:Help + + + + + View + categoryTag:Java + + + + + View + categoryTag:Java + + + + + View + categoryTag:Debug + + + + + View + categoryTag:Java + + + + + View + categoryTag:Java + + + + + View + categoryTag:Java + + + + + View + categoryTag:Java Browsing + + + + + View + categoryTag:Java Browsing + + + + + View + categoryTag:Java Browsing + + + + + View + categoryTag:Java Browsing + + + + + View + categoryTag:Java + + + + + View + categoryTag:General + + + + + View + categoryTag:Java + + + + + View + categoryTag:Java + + + + + View + categoryTag:Language Servers + + + + + View + categoryTag:Language Servers + + + + + View + categoryTag:Language Servers + + + + + View + categoryTag:Maven + + + + + View + categoryTag:Maven + + + + + View + categoryTag:Maven + + + + + View + categoryTag:Mylyn + + + + + View + categoryTag:Mylyn + + + + + View + categoryTag:Mylyn + + + + + View + categoryTag:Mylyn + + + + + View + categoryTag:Mylyn + + + + + View + categoryTag:Mylyn + + + + + View + categoryTag:Oomph + + + + + View + categoryTag:General + + + + + View + categoryTag:Version Control (Team) + + + + + View + categoryTag:Version Control (Team) + + + View + categoryTag:Help + + + + + View + categoryTag:Terminal + + + + + View + categoryTag:Other + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:Help + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + + View + categoryTag:General + + + + glue + move_after:PerspectiveSpacer + SHOW_RESTORE_MENU + + + move_after:Spacer Glue + HIDEABLE + SHOW_RESTORE_MENU + + + glue + move_after:SearchField + SHOW_RESTORE_MENU + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Java_Project/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.project b/Java_Project/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.project new file mode 100644 index 0000000..3c10856 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.project @@ -0,0 +1,11 @@ + + + .org.eclipse.egit.core.cmp + + + + + + + + diff --git a/Java_Project/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.settings/org.eclipse.core.resources.prefs b/Java_Project/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.egit.core/.org.eclipse.egit.core.cmp/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/assumedExternalFilesCache b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/assumedExternalFilesCache new file mode 100644 index 0000000..593f470 Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/assumedExternalFilesCache differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/externalFilesCache b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/externalFilesCache new file mode 100644 index 0000000..593f470 Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/externalFilesCache differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/javaLikeNames.txt b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/javaLikeNames.txt new file mode 100644 index 0000000..8586397 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/javaLikeNames.txt @@ -0,0 +1 @@ +java \ No newline at end of file diff --git a/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache new file mode 100644 index 0000000..593f470 Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat new file mode 100644 index 0000000..0edae4b Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml b/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml new file mode 100644 index 0000000..a4ee3cb --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/OpenTypeHistory.xml @@ -0,0 +1,2 @@ + + diff --git a/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml b/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml new file mode 100644 index 0000000..9e390f5 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml @@ -0,0 +1,2 @@ + + diff --git a/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml b/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml new file mode 100644 index 0000000..918e365 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml @@ -0,0 +1,10 @@ + +
+
+ + + + + +
+
diff --git a/Java_Project/.metadata/.plugins/org.eclipse.m2e.core/workspaceState.ser b/Java_Project/.metadata/.plugins/org.eclipse.m2e.core/workspaceState.ser new file mode 100644 index 0000000..abbf8e5 Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.m2e.core/workspaceState.ser differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.m2e.logback/0.log b/Java_Project/.metadata/.plugins/org.eclipse.m2e.logback/0.log new file mode 100644 index 0000000..6a9346c --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.m2e.logback/0.log @@ -0,0 +1 @@ +2024-03-29 15:45:12,638 [Worker-6: Loading available Gradle versions] INFO o.e.b.c.i.u.g.PublishedGradleVersions - Gradle version information cache is up-to-date. Trying to read. diff --git a/Java_Project/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.6.0.20240217-1525.xml b/Java_Project/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.6.0.20240217-1525.xml new file mode 100644 index 0000000..9effde7 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.6.0.20240217-1525.xml @@ -0,0 +1,41 @@ + + + + %date [%thread] %-5level %logger{35} - %msg%n + + + ${org.eclipse.m2e.log.console.threshold:-OFF} + + + + + ${org.eclipse.m2e.log.dir}/0.log + + ${org.eclipse.m2e.log.dir}/%i.log + 1 + 10 + + + 10MB + + + %date [%thread] %-5level %logger{35} - %msg%n + + + + + + WARN + + + + + + + + + + + + + diff --git a/Java_Project/.metadata/.plugins/org.eclipse.mylyn.github.ui/avatars.ser b/Java_Project/.metadata/.plugins/org.eclipse.mylyn.github.ui/avatars.ser new file mode 100644 index 0000000..1e9a069 Binary files /dev/null and b/Java_Project/.metadata/.plugins/org.eclipse.mylyn.github.ui/avatars.ser differ diff --git a/Java_Project/.metadata/.plugins/org.eclipse.oomph.setup/workspace.setup b/Java_Project/.metadata/.plugins/org.eclipse.oomph.setup/workspace.setup new file mode 100644 index 0000000..1f73e14 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.oomph.setup/workspace.setup @@ -0,0 +1,6 @@ + + diff --git a/Java_Project/.metadata/.plugins/org.eclipse.tips.ide/dialog_settings.xml b/Java_Project/.metadata/.plugins/org.eclipse.tips.ide/dialog_settings.xml new file mode 100644 index 0000000..5ca0b77 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.tips.ide/dialog_settings.xml @@ -0,0 +1,3 @@ + +
+
diff --git a/Java_Project/.metadata/.plugins/org.eclipse.ui.intro/introstate b/Java_Project/.metadata/.plugins/org.eclipse.ui.intro/introstate new file mode 100644 index 0000000..02f134f --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.ui.intro/introstate @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Java_Project/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml b/Java_Project/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml new file mode 100644 index 0000000..033dbf2 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml @@ -0,0 +1,12 @@ + +
+
+
+ + + + + +
+
+
diff --git a/Java_Project/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml b/Java_Project/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml new file mode 100644 index 0000000..8419756 --- /dev/null +++ b/Java_Project/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java_Project/.metadata/version.ini b/Java_Project/.metadata/version.ini new file mode 100644 index 0000000..f320a28 --- /dev/null +++ b/Java_Project/.metadata/version.ini @@ -0,0 +1,3 @@ +#Fri Mar 29 15:45:06 CST 2024 +org.eclipse.core.runtime=2 +org.eclipse.platform=4.31.100.v20240229-0520 diff --git a/Java_Project/.project b/Java_Project/.project new file mode 100644 index 0000000..0e4b82c --- /dev/null +++ b/Java_Project/.project @@ -0,0 +1,17 @@ + + + Java_Project + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java_Project/.settings/org.eclipse.core.resources.prefs b/Java_Project/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/Java_Project/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/Java_Project/.settings/org.eclipse.jdt.core.prefs b/Java_Project/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..92dd3c2 --- /dev/null +++ b/Java_Project/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/Java_Project/bin/Test/Main.class b/Java_Project/bin/Test/Main.class new file mode 100644 index 0000000..2f38aac Binary files /dev/null and b/Java_Project/bin/Test/Main.class differ diff --git a/Java_Project/src/Test/Main.java b/Java_Project/src/Test/Main.java new file mode 100644 index 0000000..2b7975d --- /dev/null +++ b/Java_Project/src/Test/Main.java @@ -0,0 +1,8 @@ +package Test; +import utm.*; +public class Main { + public static void main(String[] args) { + System.out.println("Hello"); + } + +} diff --git a/Java_Project/turingmachines.jar b/Java_Project/turingmachines.jar new file mode 100644 index 0000000..2d95425 Binary files /dev/null and b/Java_Project/turingmachines.jar differ diff --git a/README.md b/README.md index 49d270a..c279d2c 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,11 @@ Using the pre-written code to make a dynamic graphical turing machine. #### Wekk 2 - 3 Building a Proper OO Model of a Universal Turing Machine + +## TODO: +- rewrite the javadoc +- finish the class diagram +- do more testing + - using the instructed method to test the project + - test the GUI / Termial working logic (probably making more corner cases) + - output the whole java project as a 'xxx.jar' file diff --git a/Source Code Folder/.DS_Store b/Source Code Folder/.DS_Store new file mode 100644 index 0000000..114c1b8 Binary files /dev/null and b/Source Code Folder/.DS_Store differ diff --git a/Source Code Folder/BBTM.java b/Source Code Folder/BBTM.java new file mode 100644 index 0000000..eab338d --- /dev/null +++ b/Source Code Folder/BBTM.java @@ -0,0 +1,49 @@ + + +import utm.*; + +/** + * Busy Beaver Turing Machine configuration manager. + * This class is responsible for managing the configuration of a Busy Beaver Turing Machine. + * It extends the BaseTM class and overrides some of its methods to implement the specific + * functionality required for a Busy Beaver TM. + * + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + * */ +public class BBTM extends BaseTM { + + /** + The constructor for a Busy Beaver TM. + @param rulesNumber The number of rules in the Turing Machine. + @param initialState The initial state of the Turing Machine. + @param acceptState The accept state of the Turing Machine. + @param rejectState The reject state of the Turing Machine. + @param baseUTM The base Universal Turing Machine. + */ + + public BBTM(int rulesNumber, String initialState, String acceptState, String rejectState, BaseUTM baseUTM) { + super(rulesNumber, initialState, acceptState, rejectState, baseUTM); + initialHeadPos = 10; + } + + + /** + Overrides the getMoveDir method in BaseTM to return the specific Move object for a Busy Beaver TM. + @param move The way that the head should move. + @return The Move object for the given move. + */ + + @Override + protected Move getMoveDir(String move) { + return move.equals("RIGHT") ? MoveBBTM.RIGHT : MoveBBTM.LEFT; + } + + /** + Overrides the initiateTM method in BaseTM to initialize the tape with a specific input for a Busy Beaver TM. + @param input The input to initialize the tape with. + */ + @Override + public void initiateTM(String input) { + super.initiateTM("00000000000000000000"); + } +} diff --git a/Source Code Folder/BaseTM.java b/Source Code Folder/BaseTM.java new file mode 100644 index 0000000..20a916b --- /dev/null +++ b/Source Code Folder/BaseTM.java @@ -0,0 +1,133 @@ + + +import java.util.HashMap; +import utm.*; + +/** + * Base Turing Machine configuration manager. + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + */ +public class BaseTM extends TuringMachine { + + /** + * The initial location of the header pointer. + */ + protected int initialHeadPos; + + + /** + * instantiate the UTM object. + */ + + public BaseUTM utm; + + /** + * Build the hashmap of the input string. + */ + private HashMap, ThreeTuple, Integer>> map; + + /** + * Constructor of the BaseTM + * + * @param rulesNumber The number of rules that the machine will have. + * @param initialState A string representing the TM's initial state. + * @param acceptState A string representing the TM's accept state. + * @param rejectState A string representing the TM's reject state. + * @param baseUTM The specification of base Universal Turing Machine. + */ + public BaseTM(int rulesNumber, String initialState, String acceptState, String rejectState, BaseUTM baseUTM){ + super(rulesNumber, initialState, acceptState, rejectState); + map = new HashMap<>(); + utm = baseUTM; + utm.loadTuringMachine(this); + } + + /** + * The input string of users to the TM. + * @param input + */ + + public void initiateTM(String input){ + utm.loadInput(input); + } + + /** + * The execution of execution the turing machine. + */ + + public void execute(){ + for(int i = 0; i < initialHeadPos - 1; i++) + utm.moveHead(MoveClassical.RIGHT, false); + // For better fits the animation of the Turing machine movement + if (utm.isAnimated){ + try { + Thread.sleep(Config.DELAY); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + // Get the initial state of the head + String currentState = getInitialState(); + HashMap, ThreeTuple, Integer>> map = getRule(); + + // Judge whether the header is taking accept state or the reject state + while (!currentState.equals(getAcceptState()) && !currentState.equals(getRejectState())){ + ThreeTuple, Integer> temp = map.get(new TwoTuple<>(currentState, getTape().get(getHead().getCurrentCell()))); + utm.writeOnCurrentCell(temp.getTuple().getSymbol()); + operateHead(temp.getThird(), utm.isAnimated); + currentState = temp.getTuple().getState(); + if (utm.isAnimated) utm.updateHeadState(currentState); + } + + // Get the result of the machine state, whether it is accepted or rejected + boolean result = currentState.equals(getAcceptState()); + HaltState haltState = result ? HaltState.ACCEPTED : HaltState.REJECTED; + utm.displayHaltState(haltState); + } + + /** + * Add the rules from .desc file and store it in the variable. + * @param rules + */ + public void addRules(String[] rules) { + for (String rule : rules) { + String[] s = rule.split(","); // s的长度为5,包括q0 1 q1 1 right + addRule(s[0], s[1].charAt(0), s[2], s[3].charAt(0), getMoveDir(s[4])); + TwoTuple a = new TwoTuple<>(s[0], s[1].charAt(0)); + Integer dir = s[4].equals("RIGHT") ? 1 : 0; // 1 - right 0 - left + ThreeTuple, Integer> b = new ThreeTuple<>(s[2], s[3].charAt(0), dir); + map.put(a, b); + } + } + + /** + * Get the rule of the TM from the hashmap. + * @return HashMap + */ + public HashMap, ThreeTuple, Integer>> getRule() + { + return map; + } + + /** + * Get the move direction from the input. + * @param move + * @return move state + */ + protected Move getMoveDir(String move){ + return move.equals("RIGHT") ? MoveClassical.RIGHT : MoveClassical.LEFT; + } + + /** + * Get the next move direction of the head + * @param move + * @param animation + */ + public void operateHead(Integer move, boolean animation){ + if(move.equals(1)) + utm.moveHead(MoveClassical.RIGHT, animation); + else + utm.moveHead(MoveClassical.LEFT, animation); + } +} diff --git a/Source Code Folder/BaseUTM.java b/Source Code Folder/BaseUTM.java new file mode 100644 index 0000000..ee86022 --- /dev/null +++ b/Source Code Folder/BaseUTM.java @@ -0,0 +1,98 @@ + + +import utm.UniversalTuringMachine; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.Scanner; + +/** + * Base Universal Turing Machine configuration manager. + * This class is responsible for creating a Turing Machine from a file and executing it. + * It uses a UniversalTuringMachine as its parent class. + * It also contains a boolean variable isAnimated, which indicates whether the Turing Machine execution should be animated. + * + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + */ +public class BaseUTM extends UniversalTuringMachine { + /** + * The boolean value of whether it is animated. + */ + public boolean isAnimated = false; + + /** + * Instantiate the BaseTM + */ + private BaseTM tm; + + /** + * Create a Turing Machine from a file + * @param filePath the path of the file containing the Turing Machine configuration + */ + public void createTuringMachineFrom(String filePath){ + String initialState = "", acceptState = "", rejectState = "", variant = "", rulesRecord = ""; + try (Scanner sc = new Scanner(new FileReader(filePath))) { + while (sc.hasNextLine()) { + String line = sc.nextLine(); + if(line.equals("") || line.charAt(0) == '#') + continue; + String[] contents = line.split("="); + switch (contents[0]) { + case "initialState": + initialState = contents[1]; + break; + case "acceptState": + acceptState = contents[1]; + break; + case "rejectState": + rejectState = contents[1]; + break; + case "variant": + variant = contents[1]; + break; + case "rules": + rulesRecord = contents[1]; + break; + } + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + // split the rules and create the Turing Machine based on the variant + String[] rules = rulesRecord.split("<>"); + switch (variant) { + case "CLASSICAL": + tm = new ClassicalTM(rules.length, initialState, acceptState, rejectState, this); + break; + case "BUSY_BEAVER": + tm = new BBTM(rules.length, initialState, acceptState, rejectState, this); + break; + case "LEFT_RESET": + tm = new LRTM(rules.length, initialState, acceptState, rejectState, this); + break; + default: + System.out.println("Wrong file"); + return; + } + tm.addRules(rules); + } + + /** + * Execute the Turing Machine with the given input + * @param input the input string for the Turing Machine + */ + public void executeTM(String input){ + BaseTM baseTM = (BaseTM) getTuringMachine(); + baseTM.initiateTM(input); + baseTM.execute(); + } + + /** + * Set the isAnimated variable to the given value + * @param animated true if the Turing Machine execution should be animated, false otherwise + */ + public void setAnimated(boolean animated){ + isAnimated = animated; + } +} + diff --git a/Source Code Folder/ClassicalTM.java b/Source Code Folder/ClassicalTM.java new file mode 100644 index 0000000..e717bf2 --- /dev/null +++ b/Source Code Folder/ClassicalTM.java @@ -0,0 +1,22 @@ + + + +/** + * A class representing a Classical Turing Machine configuration manager. + * It extends the BaseTM class and provides specific implementation for a classical Turing Machine. + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + */ +public class ClassicalTM extends BaseTM { + /** + Constructor for creating a ClassicalTM object. + @param rulesNumber the number of rules in the transition function of the Turing Machine + @param initialState the initial state of the Turing Machine + @param acceptState the accept state of the Turing Machine + @param rejectState the reject state of the Turing Machine + @param baseUTM the underlying BaseUTM object of the Turing Machine + */ + public ClassicalTM(int rulesNumber, String initialState, String acceptState, String rejectState, BaseUTM baseUTM) { + super(rulesNumber, initialState, acceptState, rejectState, baseUTM); + initialHeadPos = 0; + } +} diff --git a/Source Code Folder/LRTM.java b/Source Code Folder/LRTM.java new file mode 100644 index 0000000..0769e13 --- /dev/null +++ b/Source Code Folder/LRTM.java @@ -0,0 +1,60 @@ + + +import utm.*; + +/** + * A class that represents a Left-Reset Turing Machine configuration manager. + * This class extends the BaseTM class and overrides the getMoveDir() method to return + * the appropriate move direction based on the input string "RIGHT" or "RESET". + * This class also overrides the nextMove() method to move the head to the right or reset + * it based on the input move integer. + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + */ +public class LRTM extends BaseTM { + /** + * * Constructor that takes in the number of rules, initial state, accept state, + * reject state, and a BaseUTM object + * @param rulesNumber The number of rules in the Turing Machine. + * @param initialState The initial state of the Turing Machine. + * @param acceptState The accept state of the Turing Machine. + * @param rejectState The reject state of the Turing Machine. + * @param baseUTM The BaseUTM object that this LRTM object belongs + */ + public LRTM(int rulesNumber, String initialState, String acceptState, String rejectState, BaseUTM baseUTM) { + super(rulesNumber, initialState, acceptState, rejectState, baseUTM); + initialHeadPos = 0; + } + + /** + * Method that returns the appropriate move direction based on the input string "RIGHT" or "RESET". + * @param move The input string representing the direction of the move. + * @return The appropriate MoveLRTM enum value based on the input string. + */ + @Override + protected Move getMoveDir(String move) { + return move.equals("RIGHT") ? MoveLRTM.RIGHT : MoveLRTM.RESET; + } + + + /** + * Method that moves the head to the right or resets it based on the input move integer. + * @param move The input integer representing the move direction. + * @param animation A boolean value indicating whether animation is enabled. + */ + @Override + public void operateHead(Integer move, boolean animation){ + if(move.equals(1)) + utm.moveHead(MoveClassical.RIGHT, animation); + else { + if(animation){ + try { + Thread.sleep(Config.DELAY); + } + catch (InterruptedException ex){ + System.out.println(ex); + } + } + utm.getTuringMachine().getHead().reset(); + } + } +} diff --git a/Source Code Folder/Main.java b/Source Code Folder/Main.java new file mode 100644 index 0000000..91a7550 --- /dev/null +++ b/Source Code Folder/Main.java @@ -0,0 +1,43 @@ + + +import utmeditor.UTMEditor; +/** + * The main class for running the Left-Reset Turing Machine. + * This is a description of a command line interface for loading a Turing machine description and input. + * It also allows for the specification of whether display an animation window. + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + */ +public class Main { + public static void main(String[] args) { + // initialize the controller + ModifiedUTMController controller = new ModifiedUTMController(); + + // Identify the input terminal of the UTM, if it exists exception + if (args.length == 0) { + controller.setAnimation(true); + controller.displayWindow(); + UTMEditor utmEditor = new UTMEditor(); + utmEditor.setUTMController(controller); + }else { + // Judge the format of the input information + if (args.length != 3) { + System.out.println("Please input in the format: java -jar practical1-ID.jar \"desc_absPath\" " + + "\"input\" [--animation/--noanimation]"); + System.exit(0); + } + // If the user needs the animation of the tape moving + if (args[2].equals("--animation")) { + controller.setAnimation(true); + controller.displayWindow(); + } + // If the user only needs the result of the turing machine + else if(!args[2].equals("--noanimation")){ + System.out.println("Please input in the format: java -jar practical1-ID.jar \"desc_absPath\" " + + "\"input\" [--animation/--noanimation]"); + System.exit(0); + } + controller.loadTuringMachineFrom(args[0]); + controller.runUTM(args[1]); + } + } +} diff --git a/Source Code Folder/ModifiedUTMController.java b/Source Code Folder/ModifiedUTMController.java new file mode 100644 index 0000000..eec0146 --- /dev/null +++ b/Source Code Folder/ModifiedUTMController.java @@ -0,0 +1,58 @@ + + +import utmeditor.UTMController; +import javax.swing.*; + +/** + * The controller for the Left-Reset Turing Machine configuration manager. + * It implements the UTMController interface and manages the base UTM object and loads Turing machine and executes it on the input string. + * It also sets animation and displays the UTM window. + * + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + * + */ +public class ModifiedUTMController implements UTMController { + /** The base UTM object used for the LRTM configuration. */ + BaseUTM baseUTM; + + /** + Constructor for ModifiedUTMController class. Initializes the base UTM object. + */ + public ModifiedUTMController(){ + baseUTM = new BaseUTM(); + } + + /** + Sets the animation of the UTM. + @param animation A boolean value indicating whether animation is enabled. + */ + public void setAnimation(boolean animation){ + baseUTM.setAnimated(animation); + } + + /** + Displays the UTM window. + */ + public void displayWindow(){ + baseUTM.display(); + baseUTM.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + /** + Loads the Turing machine from a file path. + @param filePath A string value indicating the file path to load the Turing machine from. + */ + @Override + public void loadTuringMachineFrom(String filePath) { + baseUTM.createTuringMachineFrom(filePath); + } + + /** + Runs the loaded Turing machine on the input string. + @param input A string value indicating the input for the Turing machine. + */ + @Override + public void runUTM(String input) { + baseUTM.executeTM(input); + } +} diff --git a/Source Code Folder/MoveBBTM.java b/Source Code Folder/MoveBBTM.java new file mode 100644 index 0000000..7266492 --- /dev/null +++ b/Source Code Folder/MoveBBTM.java @@ -0,0 +1,16 @@ + + +import utm.Move; + +/** + * Head movements for a Busy Beaver Turing Machine. + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + */ +public enum MoveBBTM implements Move{ + + /** The right movement of a BBTM. */ + RIGHT, + + /** The LEFT movement of a BBTM. */ + LEFT; +} diff --git a/Source Code Folder/MoveLRTM.java b/Source Code Folder/MoveLRTM.java new file mode 100644 index 0000000..7563355 --- /dev/null +++ b/Source Code Folder/MoveLRTM.java @@ -0,0 +1,15 @@ + +import utm.Move; + +/** + * Head movements for a Left-Reset Turing Machine. + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + */ +public enum MoveLRTM implements Move{ + + /** The right movement of a LRTM. */ + RIGHT, + + /** The RESET movement of a LRTM. */ + RESET; +} \ No newline at end of file diff --git a/Source Code Folder/ThreeTuple.java b/Source Code Folder/ThreeTuple.java new file mode 100644 index 0000000..9207dab --- /dev/null +++ b/Source Code Folder/ThreeTuple.java @@ -0,0 +1,44 @@ + + +/** + * A three-element tuple for hashmap that stores a state, a symbol, and a direction. + * The first two elements are stored in a TwoTuple object. + * @param The type of the first element in the TwoTuple object. + * @param The type of the third element in the tuple. + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + */ +public class ThreeTuple { + + /** The state and symbol. */ + private TwoTuple tuple; + /** The direction. */ + private Integer dir; + + /** + * Constructs a new ThreeTuple object with the specified state, symbol, and direction. + * @param a The state. + * @param b The symbol. + * @param dir_ The direction. + */ + public ThreeTuple(String a, Character b, Integer dir_){ + tuple = new TwoTuple(a, b); + dir = dir_; + } + + /** + * Returns the TwoTuple object containing the state and symbol. + * @return The TwoTuple object. + */ + public TwoTuple getTuple() { + return tuple; + } + + /** + * Returns the direction. + * @return The direction. + */ + public Integer getThird() { + return dir; + } + +} \ No newline at end of file diff --git a/Source Code Folder/TwoTuple.java b/Source Code Folder/TwoTuple.java new file mode 100644 index 0000000..cb4e676 --- /dev/null +++ b/Source Code Folder/TwoTuple.java @@ -0,0 +1,75 @@ + + +import java.util.Objects; + +/** + * Two-element tuple for hashmap + * @author Shujian Gao, Bohan Shen, Yuan Wang, Zhoumeng Yang, Jin Wang, Zixuan Wen. + * @param The state + * @param The tuple + */ + +class TwoTuple { + + /** The state. */ + private String state; + /** The symbol. */ + private Character symbol; + + /** + * The constructor of TwoTuple + * @param a The input state. + * @param b The input symbol. + */ + public TwoTuple(String a, Character b) { + state = a; + symbol = b; + + } + + /** + * Get the state value of the tuple. + * @return The state. + */ + public String getState() { + return state; + } + + /** + * Get the symbol value of the tuple. + * @return The symbol. + */ + public Character getSymbol() { + return symbol; + } + + /** + * Judge if the values of this Two-element tuple equal to the input tuple. + * @param obj The input tuple. + * @return Boolean. + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj == null || obj.getClass() != this.getClass()) { + return false; + } + + TwoTuple o = (TwoTuple) obj; + return this.getState().equals(o.getState()) && this.getSymbol().equals(o.getSymbol()); + + } + + /** + * Rewrite equals as well as hashCode, because hashCode for the same object is always the same. + * @return The hash value of the input values. + */ + public int hashCode() { + //Call the Objects class, which is a subclass of the Object class + return Objects.hash(state, symbol); + } + + +} \ No newline at end of file diff --git a/Source Code Folder/practical4-7.jar b/Source Code Folder/practical4-7.jar new file mode 100644 index 0000000..7e8b38c Binary files /dev/null and b/Source Code Folder/practical4-7.jar differ diff --git a/Source Code Folder/practical4-7/.DS_Store b/Source Code Folder/practical4-7/.DS_Store new file mode 100644 index 0000000..7939e45 Binary files /dev/null and b/Source Code Folder/practical4-7/.DS_Store differ diff --git a/Source Code Folder/practical4-7/META-INF/MANIFEST.MF b/Source Code Folder/practical4-7/META-INF/MANIFEST.MF new file mode 100644 index 0000000..15ec611 --- /dev/null +++ b/Source Code Folder/practical4-7/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: myPackage.Main + diff --git a/Source Code Folder/practical4-7/myPackage/BBTM.class b/Source Code Folder/practical4-7/myPackage/BBTM.class new file mode 100644 index 0000000..22b2c04 Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/BBTM.class differ diff --git a/Source Code Folder/practical4-7/myPackage/BaseTM.class b/Source Code Folder/practical4-7/myPackage/BaseTM.class new file mode 100644 index 0000000..384070b Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/BaseTM.class differ diff --git a/Source Code Folder/practical4-7/myPackage/BaseUTM.class b/Source Code Folder/practical4-7/myPackage/BaseUTM.class new file mode 100644 index 0000000..5443bcf Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/BaseUTM.class differ diff --git a/Source Code Folder/practical4-7/myPackage/ClassicalTM.class b/Source Code Folder/practical4-7/myPackage/ClassicalTM.class new file mode 100644 index 0000000..87fe801 Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/ClassicalTM.class differ diff --git a/Source Code Folder/practical4-7/myPackage/LRTM.class b/Source Code Folder/practical4-7/myPackage/LRTM.class new file mode 100644 index 0000000..38db2f8 Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/LRTM.class differ diff --git a/Source Code Folder/practical4-7/myPackage/Main.class b/Source Code Folder/practical4-7/myPackage/Main.class new file mode 100644 index 0000000..5f8634c Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/Main.class differ diff --git a/Source Code Folder/practical4-7/myPackage/ModifiedUTMController.class b/Source Code Folder/practical4-7/myPackage/ModifiedUTMController.class new file mode 100644 index 0000000..56ac19e Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/ModifiedUTMController.class differ diff --git a/Source Code Folder/practical4-7/myPackage/MoveBBTM.class b/Source Code Folder/practical4-7/myPackage/MoveBBTM.class new file mode 100644 index 0000000..cd175e0 Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/MoveBBTM.class differ diff --git a/Source Code Folder/practical4-7/myPackage/MoveLRTM.class b/Source Code Folder/practical4-7/myPackage/MoveLRTM.class new file mode 100644 index 0000000..f98b359 Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/MoveLRTM.class differ diff --git a/Source Code Folder/practical4-7/myPackage/ThreeTuple.class b/Source Code Folder/practical4-7/myPackage/ThreeTuple.class new file mode 100644 index 0000000..a97733f Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/ThreeTuple.class differ diff --git a/Source Code Folder/practical4-7/myPackage/TwoTuple.class b/Source Code Folder/practical4-7/myPackage/TwoTuple.class new file mode 100644 index 0000000..e0168a4 Binary files /dev/null and b/Source Code Folder/practical4-7/myPackage/TwoTuple.class differ diff --git a/Source Code Folder/practical4-7/utm/Config.class b/Source Code Folder/practical4-7/utm/Config.class new file mode 100644 index 0000000..3f4ec35 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/Config.class differ diff --git a/Source Code Folder/practical4-7/utm/HaltState.class b/Source Code Folder/practical4-7/utm/HaltState.class new file mode 100644 index 0000000..97b9d92 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/HaltState.class differ diff --git a/Source Code Folder/practical4-7/utm/Head.class b/Source Code Folder/practical4-7/utm/Head.class new file mode 100644 index 0000000..c5bf016 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/Head.class differ diff --git a/Source Code Folder/practical4-7/utm/HeadPanel.class b/Source Code Folder/practical4-7/utm/HeadPanel.class new file mode 100644 index 0000000..8ded665 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/HeadPanel.class differ diff --git a/Source Code Folder/practical4-7/utm/Move.class b/Source Code Folder/practical4-7/utm/Move.class new file mode 100644 index 0000000..ca1a91f Binary files /dev/null and b/Source Code Folder/practical4-7/utm/Move.class differ diff --git a/Source Code Folder/practical4-7/utm/MoveClassical.class b/Source Code Folder/practical4-7/utm/MoveClassical.class new file mode 100644 index 0000000..019feb1 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/MoveClassical.class differ diff --git a/Source Code Folder/practical4-7/utm/Tape.class b/Source Code Folder/practical4-7/utm/Tape.class new file mode 100644 index 0000000..0f6a7c6 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/Tape.class differ diff --git a/Source Code Folder/practical4-7/utm/TapePanel.class b/Source Code Folder/practical4-7/utm/TapePanel.class new file mode 100644 index 0000000..9a145a0 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/TapePanel.class differ diff --git a/Source Code Folder/practical4-7/utm/TuringMachine.class b/Source Code Folder/practical4-7/utm/TuringMachine.class new file mode 100644 index 0000000..6ab28a2 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/TuringMachine.class differ diff --git a/Source Code Folder/practical4-7/utm/UniversalTuringMachine.class b/Source Code Folder/practical4-7/utm/UniversalTuringMachine.class new file mode 100644 index 0000000..6abddfd Binary files /dev/null and b/Source Code Folder/practical4-7/utm/UniversalTuringMachine.class differ diff --git a/Source Code Folder/practical4-7/utm/tm-head.png b/Source Code Folder/practical4-7/utm/tm-head.png new file mode 100644 index 0000000..6fd71a0 Binary files /dev/null and b/Source Code Folder/practical4-7/utm/tm-head.png differ diff --git a/Source Code Folder/practical4-7/utmeditor/UTMController.class b/Source Code Folder/practical4-7/utmeditor/UTMController.class new file mode 100644 index 0000000..787fcec Binary files /dev/null and b/Source Code Folder/practical4-7/utmeditor/UTMController.class differ diff --git a/Source Code Folder/practical4-7/utmeditor/UTMEditor$1.class b/Source Code Folder/practical4-7/utmeditor/UTMEditor$1.class new file mode 100644 index 0000000..3951cc7 Binary files /dev/null and b/Source Code Folder/practical4-7/utmeditor/UTMEditor$1.class differ diff --git a/Source Code Folder/practical4-7/utmeditor/UTMEditor.class b/Source Code Folder/practical4-7/utmeditor/UTMEditor.class new file mode 100644 index 0000000..c056329 Binary files /dev/null and b/Source Code Folder/practical4-7/utmeditor/UTMEditor.class differ diff --git a/Turing/.idea/.gitignore b/Turing/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Turing/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Turing/.idea/misc.xml b/Turing/.idea/misc.xml new file mode 100644 index 0000000..104cfef --- /dev/null +++ b/Turing/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Turing/.idea/modules.xml b/Turing/.idea/modules.xml new file mode 100644 index 0000000..fc4bff6 --- /dev/null +++ b/Turing/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Turing/.idea/vcs.xml b/Turing/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Turing/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Turing/Turing.iml b/Turing/Turing.iml new file mode 100644 index 0000000..aa8e51e --- /dev/null +++ b/Turing/Turing.iml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Turing/out/production/Turing/BBTM.class b/Turing/out/production/Turing/BBTM.class new file mode 100644 index 0000000..4d6a851 Binary files /dev/null and b/Turing/out/production/Turing/BBTM.class differ diff --git a/Turing/out/production/Turing/BaseTM.class b/Turing/out/production/Turing/BaseTM.class new file mode 100644 index 0000000..6996df3 Binary files /dev/null and b/Turing/out/production/Turing/BaseTM.class differ diff --git a/Turing/out/production/Turing/BaseUTM.class b/Turing/out/production/Turing/BaseUTM.class new file mode 100644 index 0000000..e2fcb9c Binary files /dev/null and b/Turing/out/production/Turing/BaseUTM.class differ diff --git a/Turing/out/production/Turing/ClassicalTM.class b/Turing/out/production/Turing/ClassicalTM.class new file mode 100644 index 0000000..f9e5e9f Binary files /dev/null and b/Turing/out/production/Turing/ClassicalTM.class differ diff --git a/Turing/out/production/Turing/FromInfo.class b/Turing/out/production/Turing/FromInfo.class new file mode 100644 index 0000000..7a5fc97 Binary files /dev/null and b/Turing/out/production/Turing/FromInfo.class differ diff --git a/Turing/out/production/Turing/LRTM.class b/Turing/out/production/Turing/LRTM.class new file mode 100644 index 0000000..14d2f1b Binary files /dev/null and b/Turing/out/production/Turing/LRTM.class differ diff --git a/Turing/out/production/Turing/Main.class b/Turing/out/production/Turing/Main.class new file mode 100644 index 0000000..a9c546b Binary files /dev/null and b/Turing/out/production/Turing/Main.class differ diff --git a/Turing/out/production/Turing/MoveBBTM.class b/Turing/out/production/Turing/MoveBBTM.class new file mode 100644 index 0000000..202f1e0 Binary files /dev/null and b/Turing/out/production/Turing/MoveBBTM.class differ diff --git a/Turing/out/production/Turing/MoveLRTM.class b/Turing/out/production/Turing/MoveLRTM.class new file mode 100644 index 0000000..626cbc1 Binary files /dev/null and b/Turing/out/production/Turing/MoveLRTM.class differ diff --git a/Turing/out/production/Turing/MyUTMController.class b/Turing/out/production/Turing/MyUTMController.class new file mode 100644 index 0000000..2754236 Binary files /dev/null and b/Turing/out/production/Turing/MyUTMController.class differ diff --git a/Turing/out/production/Turing/ToInfo.class b/Turing/out/production/Turing/ToInfo.class new file mode 100644 index 0000000..addda27 Binary files /dev/null and b/Turing/out/production/Turing/ToInfo.class differ diff --git a/Turing/out/production/Turing/data.desc b/Turing/out/production/Turing/data.desc new file mode 100644 index 0000000..107af92 --- /dev/null +++ b/Turing/out/production/Turing/data.desc @@ -0,0 +1,11 @@ +#Input Alphabet: {0,1} +#Tape Alphabet: {0,1,*,X} + +#Configuration +initialState=q0 +acceptState=qa +rejectState=qr +variant=CLASSICAL + +#Delta Function: Calculate whether there are consecutive three 0s in the input string +rules=q0,0,q1,0,RIGHT<>q0,1,q0,1,RIGHT<>q0,*,qr,*,RIGHT<>q1,0,q2,0,RIGHT<>q1,1,q0,1,RIGHT<>q1,*,qr,*,RIGHT<>q2,0,q3,0,RIGHT<>q2,1,q0,1,RIGHT<>q2,*,qr,*,RIGHT<>q3,0,qa,0,RIGHT<>q3,1,qa,1,RIGHT<>q3,*,qa,*,RIGHT diff --git a/Turing/src/BBTM.java b/Turing/src/BBTM.java new file mode 100644 index 0000000..2bc405e --- /dev/null +++ b/Turing/src/BBTM.java @@ -0,0 +1,61 @@ +import utm.*; +import java.util.Collections; + +/** + * This class represents a Busy Beaver Turing Machine (BBTM). + * It extends the BaseTM class and provides specific implementations for BBTM operations. + * + * The Busy Beaver Turing Machine is a theoretical construct used in computability theory. + * It is designed to illustrate the concept of halting problem and Turing-completeness. + * + * @author 17619 + * @date 2024/04/08 + */ +public class BBTM extends BaseTM { + /** + * Constructs a BBTM object with the specified parameters. + * + * @param rulesNumber The number of rules for the BBTM. + * @param initialState The initial state of the BBTM. + * @param acceptState The accepted state of the BBTM. + * @param rejectState The reject state of the BBTM. + * @param baseUTM The Universal Turing Machine associated with this BBTM. + */ + public BBTM(int rulesNumber, String initialState, String acceptState, String rejectState, BaseUTM baseUTM) { + super(rulesNumber, initialState, acceptState, rejectState, baseUTM); + setOffset(10); + } + + /** + * Overrides the getMove method to provide BBTM-specific movement. + * + * @param move The move direction as a string. + * @return The corresponding Move enum value. + */ + @Override + protected Move getMove(String move) { + return move.equals("RIGHT") ? MoveBBTM.RIGHT : MoveBBTM.LEFT; + } + + /** + * Overrides the moveHeadPos method to provide BBTM-specific head movement. + * + * @param move The move direction. + * @param animation Specifies whether to animate the movement. + */ + @Override + public void moveHeadPos(Move move, boolean animation) { + utm.moveHead((move.equals(MoveBBTM.RIGHT) ? MoveClassical.RIGHT : MoveClassical.LEFT), animation); + } + + /** + * Overrides the loadTape method to load the tape with a specific input for BBTM. + * + * @param input The input string to be loaded onto the tape. + */ + @Override + public void loadTape(String input) { + // Loads the tape with 20 zeros + super.loadTape(String.join("", Collections.nCopies(20, "0"))); + } +} diff --git a/Turing/src/BaseTM.java b/Turing/src/BaseTM.java new file mode 100644 index 0000000..8d639d6 --- /dev/null +++ b/Turing/src/BaseTM.java @@ -0,0 +1,102 @@ +import utm.*; +import java.util.List; + +/** + * This class represents a base Turing Machine. + * It extends the TuringMachine class and provides methods for executing Turing Machine operations. + * + * @author 17619 + * @date 2024/04/08 + */ +public class BaseTM extends TuringMachine { + private int offset; + public BaseUTM utm; + + /** + * Constructs a BaseTM object with the given parameters. + * + * @param rulesSize The size of the rules. + * @param initialState The initial state of the Turing Machine. + * @param acceptState The accept state of the Turing Machine. + * @param rejectState The reject state of the Turing Machine. + * @param _utm The Universal Turing Machine associated with this BaseTM. + */ + public BaseTM(int rulesSize, String initialState, String acceptState, String rejectState, BaseUTM _utm) { + super(rulesSize, initialState, acceptState, rejectState); + utm = _utm; + utm.loadTuringMachine(this); + } + public void setOffset(int _offset) { + offset = _offset; + } + + /** + * Loads the input tape with the provided input. + * + * @param input The input string to be loaded onto the tape. + */ + public void loadTape(String input) { + utm.loadInput(input); + } + + /** + * Gets the Move enum value corresponding to the provided move string. + * + * @param move The move string. + * @return The corresponding Move enum value. + */ + protected Move getMove(String move) { + return move.equals("RIGHT") ? MoveClassical.RIGHT : MoveClassical.LEFT; + } + + /** + * Moves the head position of the tape. + * + * @param move The direction of the movement. + * @param animation Specifies whether to animate the movement. + */ + public void moveHeadPos(Move move, boolean animation) { + utm.moveHead(move, animation); + } + + /** + * Adds rules to the Turing Machine. + * + * @param rules The rules to be added. + */ + public void addRules(List rules) { + for (String[] rule : rules) this.addRule(rule[0], rule[1].charAt(0), rule[2], rule[3].charAt(0), getMove(rule[4])); + } + + /** + * Executes the Turing Machine with the provided input. + * + * @param input The input string to be processed. + */ + public void execute(String input) { + loadTape(input); + // Move the head of TM to the corresponding position + while (offset-- > 0) moveHeadPos(getMove("RIGHT"), false); + + // To fit the initial position animation of BBTM + if (utm.getAnimated()){ + try { + Thread.sleep(Config.DELAY); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + String curState = getInitialState(); + char curSymbol = getTape().get(getHead().getCurrentCell()); + while (!(curState.equals(getAcceptState()) || curState.equals(getRejectState()))) { + ToInfo toInfo = utm.findRules(new FromInfo(curState, curSymbol)); + assert toInfo != null; + utm.writeOnCurrentCell(toInfo.getNewSymbol()); + moveHeadPos(getMove(toInfo.getMove()), utm.getAnimated()); + curSymbol = getTape().get(getHead().getCurrentCell()); + utm.updateHeadState(curState = toInfo.getNewState()); + } + utm.displayHaltState(curState.equals(getAcceptState()) ? HaltState.ACCEPTED : HaltState.REJECTED); + } +} diff --git a/Turing/src/BaseUTM.java b/Turing/src/BaseUTM.java new file mode 100644 index 0000000..4a6a828 --- /dev/null +++ b/Turing/src/BaseUTM.java @@ -0,0 +1,92 @@ +import utm.*; +import java.util.*; +import java.io.*; + +/** + * This class represents a base Universal Turing Machine. + * It extends the UniversalTuringMachine class and provides methods for importing and executing Turing Machines. + * + * @author 17619 + * @date 2024/04/08 + */ +public class BaseUTM extends UniversalTuringMachine { + private BaseTM tm; + private boolean isAnimated = false; + private static final List rules = new ArrayList<>(); + private static final HashMap map = new HashMap<>(); + + /** + * Imports a Turing Machine from the specified file path. + * + * @param filePath The file path from which to import the Turing Machine. + * @throws Exception If an error occurs while importing the Turing Machine. + */ + public void importTuringMachineFrom(String filePath) throws Exception { + // Read desc file + String line = "", initialState = "", acceptState = "", rejectState = "", variant = ""; + BufferedReader br = new BufferedReader(new FileReader(filePath)); + while ((line = br.readLine()) != null) { + String[] parts = line.split("="); + // skip the non-rule line + if (parts.length < 2) continue; + String parameter = parts[0].trim(); + String value = parts[1].trim(); + + switch (parameter) { + case "initialState" -> initialState = value; + case "acceptState" -> acceptState = value; + case "rejectState" -> rejectState = value; + case "variant" -> variant = value; + case "rules" -> { + for (String rulePart : value.split("<>")) { + String[] rule = rulePart.split(","); + rules.add(rule); + map.put(new FromInfo(rule[0], rule[1].charAt(0)), new ToInfo(rule[2], rule[3].charAt(0), rule[4])); + } + } + } + } + // Choose TM variant + switch (variant) { + case "CLASSICAL" -> tm = new ClassicalTM(rules.size(), initialState, acceptState, rejectState, this); + case "BUSY_BEAVER" -> tm = new BBTM(rules.size(), initialState, acceptState, rejectState, this); + case "LEFT_RESET" -> tm = new LRTM(rules.size(), initialState, acceptState, rejectState, this); + default -> { + System.err.println("Unsupported Turing Machine Variant!"); + System.exit(1); + } + } + tm.addRules(rules); + } + + public ToInfo findRules(FromInfo fromInfo) { + return map.get(new FromInfo(fromInfo.getState(), fromInfo.getSymbol())); + } + + /** + * Sets the animation status. + * + * @param _isAnimated True if animation is enabled, false otherwise. + */ + public void setAnimated(boolean _isAnimated) { + isAnimated = _isAnimated; + } + + /** + * Returns the animation status. + * + * @return True if animation is enabled, false otherwise. + */ + public boolean getAnimated() { + return isAnimated; + } + + /** + * Executes the Turing Machine with the provided input. + * + * @param input The input string to be processed. + */ + public void execute(String input) { + tm.execute(input); + } +} diff --git a/Turing/src/ClassicalTM.java b/Turing/src/ClassicalTM.java new file mode 100644 index 0000000..204468f --- /dev/null +++ b/Turing/src/ClassicalTM.java @@ -0,0 +1,21 @@ +/** + * classical tm + * + * @author 17619 + * @date 2024/04/08 + */ +public class ClassicalTM extends BaseTM { + /** + * classical tm + * + * @param rulesNumber rules number + * @param initialState initial state + * @param acceptState accept state + * @param rejectState reject state + * @param utm utm + */ + public ClassicalTM(int rulesNumber, String initialState, String acceptState, String rejectState, BaseUTM utm) { + super(rulesNumber, initialState, acceptState, rejectState, utm); + } +} + diff --git a/Turing/src/FromInfo.java b/Turing/src/FromInfo.java new file mode 100644 index 0000000..6fecdd3 --- /dev/null +++ b/Turing/src/FromInfo.java @@ -0,0 +1,87 @@ +import java.util.Objects; + +/** + * This class represents information about the current state and symbol of a Turing Machine tape cell. + * Instances of this class are used as keys in HashMaps to represent transitions in a Turing Machine. + * + * @author 17619 + * @date 2024/04/08 + */ +public class FromInfo { + private String state; + private char symbol; + + /** + * Constructs a FromInfo object with the specified state and symbol. + * + * @param state The current state of the Turing Machine. + * @param symbol The symbol on the tape cell. + */ + public FromInfo(String state, char symbol) { + this.state = state; + this.symbol = symbol; + } + + /** + * Indicates whether some other object is "equal to" this one. + * This method compares the state and symbol of the FromInfo objects. + * + * @param o The reference object with which to compare. + * @return True if this object is the same as the obj argument; false otherwise. + */ + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FromInfo fromInfo = (FromInfo) o; + return Objects.equals(state, fromInfo.state) && + Objects.equals(symbol, fromInfo.symbol); + } + + /** + * Returns a hash code value for the object. + * This method returns a hash code based on the state and symbol of the FromInfo object. + * + * @return A hash code value for this object. + */ + @Override + public int hashCode() { + return Objects.hash(state, symbol); + } + + /** + * Returns the current state of the Turing Machine. + * + * @return The current state. + */ + public String getState() { + return state; + } + + /** + * Sets the current state of the Turing Machine. + * + * @param state The state to be set. + */ + public void setState(String state) { + this.state = state; + } + + /** + * Returns the symbol on the tape cell. + * + * @return The symbol on the tape cell. + */ + public char getSymbol() { + return symbol; + } + + /** + * Sets the symbol on the tape cell. + * + * @param symbol The symbol to be set. + */ + public void setSymbol(char symbol) { + this.symbol = symbol; + } +} diff --git a/Turing/src/LRTM.java b/Turing/src/LRTM.java new file mode 100644 index 0000000..a762caf --- /dev/null +++ b/Turing/src/LRTM.java @@ -0,0 +1,53 @@ +import utm.*; + +/** + * This class represents a Left Reset Turing Machine (LRTM). + * It extends the BaseTM class and provides specific implementations for LRTM operations. + * + * The Left Reset Turing Machine is a variant of a Universal Turing Machine. + * It allows the tape head to move left or reset to the leftmost cell. + * + * @author 17619 + * @date 2024/04/08 + */ +public class LRTM extends BaseTM { + /** + * Constructs an LRTM object with the specified parameters. + * + * @param rulesNumber The number of rules for the LRTM. + * @param initialState The initial state of the LRTM. + * @param acceptState The accepted state of the LRTM. + * @param rejectState The reject state of the LRTM. + * @param utm The Universal Turing Machine associated with this LRTM. + */ + public LRTM(int rulesNumber, String initialState, String acceptState, String rejectState, BaseUTM utm) { + super(rulesNumber, initialState, acceptState, rejectState, utm); + setOffset(0); + } + + /** + * Overrides the getMove method to provide LRTM-specific movement. + * + * @param move The move direction as a string. + * @return The corresponding Move enum value. + */ + @Override + protected Move getMove(String move) { + return move.equals("RIGHT") ? MoveLRTM.RIGHT : MoveLRTM.RESET; + } + + /** + * Overrides the moveHeadPos method to provide LRTM-specific head movement. + * + * @param move The move direction. + * @param animation Specifies whether to animate the movement. + */ + @Override + public void moveHeadPos(Move move, boolean animation) { + if (move.equals(MoveLRTM.RIGHT)) { + utm.moveHead(MoveClassical.RIGHT, animation); + } else { + utm.getTuringMachine().getHead().reset(); + } + } +} diff --git a/Turing/src/Main.java b/Turing/src/Main.java new file mode 100644 index 0000000..15c58b8 --- /dev/null +++ b/Turing/src/Main.java @@ -0,0 +1,46 @@ +import utmeditor.UTMEditor; + +/** + * This class contains the main method to run the application. + * It either launches the application in GUI mode or runs it from the command line with arguments. + * The application allows users to interact with a Universal Turing Machine (UTM) either through a graphical user interface (GUI) or through the command line. + * + * Users can specify the description file path, input panel, and animation settings when running the application from the command line. + * Alternatively, they can use the GUI interface provided by the application. + * + * @author 17619 + * @date 2024/04/08 + */ +public class Main { + /** + * The main method to run the application. + * @param args The command-line arguments passed to the application. + */ + public static void main(String[] args) { + MyUTMController controller = new MyUTMController(); + if (args.length != 0) { + // Using terminal + if (args.length != 3) { + System.err.println("Wrong format!"); + System.err.println("Please input the arguments in the following format:\n" + + "java -jar partical_1-18.jar" + " " + "desc file's path" + " " + + "input panel" + " " + "[--animation or --noanimation]"); + System.exit(1); + } + if (!(args[2].equals("--animation") || args[2].equals("--noanimation"))) { + System.err.println("Invalid argument!"); + System.err.println("[--animation or --noanimation]"); + System.exit(1); + } + controller.setAnimation(args[2]); + controller.runUTM(args[1]); + } else { + // Using GUI + controller.displayPanel(); + // Animations are turned on by default + controller.setAnimation("--animation"); + UTMEditor utmEditor = new UTMEditor(); + utmEditor.setUTMController(controller); + } + } +} diff --git a/Turing/src/MoveBBTM.java b/Turing/src/MoveBBTM.java new file mode 100644 index 0000000..e5e852e --- /dev/null +++ b/Turing/src/MoveBBTM.java @@ -0,0 +1,13 @@ +import utm.Move; + +/** + * move bbtm + * + * @author 17619 + * @date 2024/04/09 + */ +public enum MoveBBTM implements Move { + RIGHT, + + LEFT; +} diff --git a/Turing/src/MoveLRTM.java b/Turing/src/MoveLRTM.java new file mode 100644 index 0000000..9d6f469 --- /dev/null +++ b/Turing/src/MoveLRTM.java @@ -0,0 +1,13 @@ +import utm.Move; + +/** + * move lrtm + * + * @author 17619 + * @date 2024/04/09 + */ +public enum MoveLRTM implements Move { + RIGHT, + + RESET; +} \ No newline at end of file diff --git a/Turing/src/MyUTMController.java b/Turing/src/MyUTMController.java new file mode 100644 index 0000000..5a3afac --- /dev/null +++ b/Turing/src/MyUTMController.java @@ -0,0 +1,60 @@ +import utmeditor.UTMController; + +/** + * This class represents a custom implementation of the UTMController interface. + * It provides methods to interact with a Universal Turing Machine (UTM) through a controller. + * + * Users can display the panel, set the animation, load a Turing Machine from a file, and run the UTM with input. + * + * @author 17619 + * @date 2024/04/08 + */ +public class MyUTMController implements UTMController { + private BaseUTM utm; + + /** + * Constructs a MyUTMController object. + * Initializes the associated Universal Turing Machine (UTM). + */ + public MyUTMController() { + utm = new BaseUTM(); + } + + /** + * Displays the panel associated with the Universal Turing Machine (UTM). + */ + public void displayPanel() { + utm.display(); + } + + /** + * Sets the animation status of the Universal Turing Machine (UTM). + * + * @param _isAnimated Specifies whether animation is enabled. + */ + public void setAnimation(String _isAnimated) { utm.setAnimated(_isAnimated.equals("--animation")); } + + /** + * Loads a Turing Machine description from the specified file path. + * + * @param filePath The file path from which to load the Turing Machine description. + */ + @Override + public void loadTuringMachineFrom(String filePath) { + try { + utm.importTuringMachineFrom(filePath); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * Runs the Universal Turing Machine (UTM) with the provided input. + * + * @param input The input string to be processed by the UTM. + */ + @Override + public void runUTM(String input) { + utm.execute(input); + } +} diff --git a/Turing/src/ToInfo.java b/Turing/src/ToInfo.java new file mode 100644 index 0000000..281d9f6 --- /dev/null +++ b/Turing/src/ToInfo.java @@ -0,0 +1,79 @@ + +/** + * This class represents information about the transition to a new state in a Turing Machine. + * It encapsulates the new state, the new symbol to write on the tape, and the movement of the tape head. + * + * Instances of this class are used to define transitions between states in a Turing Machine. + * + * @author 17619 + * @date 2024/04/08 + */ +public class ToInfo { + private String newState, move; + private char newSymbol; + + /** + * Constructs a ToInfo object with the specified parameters. + * + * @param newState The new state after the transition. + * @param newSymbol The new symbol to be written on the tape. + * @param move The movement of the tape head (LEFT or RIGHT). + */ + public ToInfo(String newState, char newSymbol, String move) { + this.newState = newState; + this.newSymbol = newSymbol; + this.move = move; + } + + /** + * Returns the new state after the transition. + * + * @return The new state. + */ + public String getNewState() { + return newState; + } + + /** + * Sets the new state after the transition. + * + * @param newState The new state to be set. + */ + public void setNewState(String newState) {this.newState = newState;} + + /** + * Returns the new symbol to be written on the tape. + * + * @return The new symbol. + */ + public char getNewSymbol() { + return newSymbol; + } + + /** + * Sets the new symbol to be written on the tape. + * + * @param newSymbol The new symbol to be set. + */ + public void setNewSymbol(char newSymbol) { + this.newSymbol = newSymbol; + } + + /** + * Returns the movement of the tape head (LEFT or RIGHT). + * + * @return The movement of the tape head. + */ + public String getMove() { + return move; + } + + /** + * Sets the movement of the tape head (LEFT or RIGHT). + * + * @param move The movement to be set. + */ + public void setMove(String move) { + this.move = move; + } +} diff --git a/Turing/src/data.desc b/Turing/src/data.desc new file mode 100644 index 0000000..107af92 --- /dev/null +++ b/Turing/src/data.desc @@ -0,0 +1,11 @@ +#Input Alphabet: {0,1} +#Tape Alphabet: {0,1,*,X} + +#Configuration +initialState=q0 +acceptState=qa +rejectState=qr +variant=CLASSICAL + +#Delta Function: Calculate whether there are consecutive three 0s in the input string +rules=q0,0,q1,0,RIGHT<>q0,1,q0,1,RIGHT<>q0,*,qr,*,RIGHT<>q1,0,q2,0,RIGHT<>q1,1,q0,1,RIGHT<>q1,*,qr,*,RIGHT<>q2,0,q3,0,RIGHT<>q2,1,q0,1,RIGHT<>q2,*,qr,*,RIGHT<>q3,0,qa,0,RIGHT<>q3,1,qa,1,RIGHT<>q3,*,qa,*,RIGHT diff --git a/Week4/Turing/.idea/misc.xml b/Week4/Turing/.idea/misc.xml new file mode 100644 index 0000000..cc6eae0 --- /dev/null +++ b/Week4/Turing/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Week4/Turing/.idea/workspace.xml b/Week4/Turing/.idea/workspace.xml new file mode 100644 index 0000000..811299e --- /dev/null +++ b/Week4/Turing/.idea/workspace.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "WebServerToolWindowFactoryState": "false", + "last_opened_file_path": "/Users/liam/Desktop/TM/Week4/Turing", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.15", + "project.structure.side.proportion": "0.2", + "vue.rearranger.settings.migration": "true" + } +} + + + + + + + + + + 1712470847353 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/classical-own.desc b/classical-own.desc new file mode 100644 index 0000000..6a23d48 --- /dev/null +++ b/classical-own.desc @@ -0,0 +1,11 @@ +#Input Alphabet: {0,1} +#Tape Alphabet: {0,1,*,X} + +#Configuration +initialState=q0 +acceptState=qa +rejectState=qr +variant=CLASSICAL + +#Delta Function: Calculate whether there are consecutive three 0s in the input string +rules=q0,0,q1,0,RIGHT<>q0,1,q0,1,RIGHT<>q0,*,qr,*,RIGHT<>q1,0,q2,0,RIGHT<>q1,1,q0,1,RIGHT<>q1,*,qr,*,RIGHT<>q2,0,q3,0,RIGHT<>q2,1,q0,1,RIGHT<>q2,*,qr,*,RIGHT<>q3,0,qa,0,RIGHT<>q3,1,qa,1,RIGHT<>q3,*,qa,*,RIGHT \ No newline at end of file