Aggiunta di parziale
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#Sat May 02 22:23:18 CEST 2026
|
||||
host=eslusarzs-MacBook-Pro.local
|
||||
process-id=5824
|
||||
#Sat May 09 20:34:12 CEST 2026
|
||||
host=DESKTOP-ALBQHEK
|
||||
process-id=5732
|
||||
user=eslusarz
|
||||
|
||||
+350
@@ -138,3 +138,353 @@ java.lang.NullPointerException: Cannot store to object array because "this.types
|
||||
Suppressed: java.lang.RuntimeException: RuntimeException loading =asdl/\/Users\/eslusarz\/.p2\/pool\/plugins\/org.eclipse.justj.openjdk.hotspot.jre.full.macosx.aarch64_21.0.10.v20260205-0638\/jre\/lib\/jrt-fs.jar`java.base=/javadoc_location=/https:\/\/docs.oracle.com\/en\/java\/javase\/21\/docs\/api\/=/=/module=/true=/|java/util/Comparator.class
|
||||
at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.cachePartsFrom(BinaryTypeBinding.java:446)
|
||||
... 34 more
|
||||
!SESSION 2026-05-09 20:32:52.385 -----------------------------------------------
|
||||
eclipse.buildId=4.39.0.20260305-0817
|
||||
java.version=21.0.10
|
||||
java.vendor=Eclipse Adoptium
|
||||
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_GB
|
||||
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 2026-05-09 20:33:46.349
|
||||
!MESSAGE Activated before the state location was initialized. Retry after the state location is initialized.
|
||||
|
||||
!ENTRY org.eclipse.core.resources 2 10035 2026-05-09 20:34:13.052
|
||||
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
|
||||
|
||||
!ENTRY org.eclipse.core.resources 4 567 2026-05-09 20:34:13.482
|
||||
!MESSAGE Workspace restored, but some problems occurred.
|
||||
!SUBENTRY 1 org.eclipse.core.resources 4 567 2026-05-09 20:34:13.482
|
||||
!MESSAGE Could not read metadata for '.org.eclipse.egit.core.cmp'.
|
||||
!STACK 1
|
||||
org.eclipse.core.internal.resources.ResourceException(/.org.eclipse.egit.core.cmp)[567]: java.lang.Exception: The project description file (.project) for '.org.eclipse.egit.core.cmp' is missing. This file contains important information about the project. The project will not function properly until this file is restored.
|
||||
at org.eclipse.core.internal.resources.ResourceException.provideStackTrace(ResourceException.java:42)
|
||||
at org.eclipse.core.internal.resources.ResourceException.<init>(ResourceException.java:38)
|
||||
at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:1015)
|
||||
at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:1004)
|
||||
at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:983)
|
||||
at org.eclipse.core.internal.resources.SaveManager.restore(SaveManager.java:825)
|
||||
at org.eclipse.core.internal.resources.SaveManager.startup(SaveManager.java:1689)
|
||||
at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:2677)
|
||||
at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:2369)
|
||||
at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:591)
|
||||
at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:1)
|
||||
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:947)
|
||||
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
|
||||
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:257)
|
||||
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:184)
|
||||
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:324)
|
||||
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:267)
|
||||
at org.eclipse.core.resources.ResourcesPlugin.start(ResourcesPlugin.java:565)
|
||||
at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:838)
|
||||
at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:1)
|
||||
at java.base/java.security.AccessController.doPrivileged(AccessController.java:571)
|
||||
at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:830)
|
||||
at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:780)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1082)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:394)
|
||||
at org.eclipse.osgi.container.Module.doStart(Module.java:643)
|
||||
at org.eclipse.osgi.container.Module.start(Module.java:500)
|
||||
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:528)
|
||||
at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:122)
|
||||
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:620)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:353)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:418)
|
||||
at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:41)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:523)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:439)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:195)
|
||||
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
|
||||
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:186)
|
||||
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:298)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:615)
|
||||
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:563)
|
||||
at org.eclipse.equinox.launcher.Main.run(Main.java:1415)
|
||||
!SUBENTRY 2 org.eclipse.core.resources 4 567 2026-05-09 20:34:13.500
|
||||
!MESSAGE The project description file (.project) for '.org.eclipse.egit.core.cmp' is missing. This file contains important information about the project. The project will not function properly until this file is restored.
|
||||
!STACK 0
|
||||
java.lang.Exception: The project description file (.project) for '.org.eclipse.egit.core.cmp' is missing. This file contains important information about the project. The project will not function properly until this file is restored.
|
||||
at org.eclipse.core.internal.resources.ResourceException.provideStackTrace(ResourceException.java:42)
|
||||
at org.eclipse.core.internal.resources.ResourceException.<init>(ResourceException.java:38)
|
||||
at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:1015)
|
||||
at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:1004)
|
||||
at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:983)
|
||||
at org.eclipse.core.internal.resources.SaveManager.restore(SaveManager.java:825)
|
||||
at org.eclipse.core.internal.resources.SaveManager.startup(SaveManager.java:1689)
|
||||
at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:2677)
|
||||
at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:2369)
|
||||
at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:591)
|
||||
at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:1)
|
||||
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:947)
|
||||
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
|
||||
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:257)
|
||||
at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:184)
|
||||
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:324)
|
||||
at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:267)
|
||||
at org.eclipse.core.resources.ResourcesPlugin.start(ResourcesPlugin.java:565)
|
||||
at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:838)
|
||||
at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:1)
|
||||
at java.base/java.security.AccessController.doPrivileged(AccessController.java:571)
|
||||
at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:830)
|
||||
at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:780)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1082)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:394)
|
||||
at org.eclipse.osgi.container.Module.doStart(Module.java:643)
|
||||
at org.eclipse.osgi.container.Module.start(Module.java:500)
|
||||
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:528)
|
||||
at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:122)
|
||||
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:620)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:353)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:418)
|
||||
at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:41)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:523)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:439)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:195)
|
||||
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
|
||||
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:186)
|
||||
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:298)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:615)
|
||||
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:563)
|
||||
at org.eclipse.equinox.launcher.Main.run(Main.java:1415)
|
||||
|
||||
!ENTRY ch.qos.logback.classic 1 0 2026-05-09 20:34:15.126
|
||||
!MESSAGE Logback config file: C:\Users\eslusarz\Documents\eclipse-workspace\.metadata\.plugins\org.eclipse.m2e.logback\logback.2.7.101.20251017-1242.xml
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 4 0 2026-05-09 20:34:16.824
|
||||
!MESSAGE Unable to load class 'org.eclipse.e4.ui.workbench.renderers.swt.cocoa.ArrangeWindowHandler' from bundle '147'
|
||||
!STACK 0
|
||||
java.lang.ClassNotFoundException: org.eclipse.e4.ui.workbench.renderers.swt.cocoa.ArrangeWindowHandler cannot be found by org.eclipse.e4.ui.workbench.renderers.swt_0.17.0.v20260131-0926
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:570)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:564)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:439)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:195)
|
||||
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:663)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:88)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:42)
|
||||
at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.processActiveHandler(HandlerProcessingAddon.java:131)
|
||||
at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.postConstruct(HandlerProcessingAddon.java:51)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:1037)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:142)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:401)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:334)
|
||||
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:228)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:93)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:37)
|
||||
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:276)
|
||||
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:603)
|
||||
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
|
||||
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:583)
|
||||
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
|
||||
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:185)
|
||||
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:298)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:615)
|
||||
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:563)
|
||||
at org.eclipse.equinox.launcher.Main.run(Main.java:1415)
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 4 0 2026-05-09 20:34:16.839
|
||||
!MESSAGE Unable to load class 'org.eclipse.e4.ui.workbench.renderers.swt.cocoa.MinimizeWindowHandler' from bundle '147'
|
||||
!STACK 0
|
||||
java.lang.ClassNotFoundException: org.eclipse.e4.ui.workbench.renderers.swt.cocoa.MinimizeWindowHandler cannot be found by org.eclipse.e4.ui.workbench.renderers.swt_0.17.0.v20260131-0926
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:570)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:564)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:439)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:195)
|
||||
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:663)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:88)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:42)
|
||||
at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.processActiveHandler(HandlerProcessingAddon.java:131)
|
||||
at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.postConstruct(HandlerProcessingAddon.java:51)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:1037)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:142)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:401)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:334)
|
||||
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:228)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:93)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:37)
|
||||
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:276)
|
||||
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:603)
|
||||
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
|
||||
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:583)
|
||||
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
|
||||
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:185)
|
||||
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:298)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:615)
|
||||
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:563)
|
||||
at org.eclipse.equinox.launcher.Main.run(Main.java:1415)
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 4 0 2026-05-09 20:34:16.841
|
||||
!MESSAGE Unable to load class 'org.eclipse.e4.ui.workbench.renderers.swt.cocoa.ZoomWindowHandler' from bundle '147'
|
||||
!STACK 0
|
||||
java.lang.ClassNotFoundException: org.eclipse.e4.ui.workbench.renderers.swt.cocoa.ZoomWindowHandler cannot be found by org.eclipse.e4.ui.workbench.renderers.swt_0.17.0.v20260131-0926
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:570)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:564)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:439)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:195)
|
||||
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:663)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:88)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:42)
|
||||
at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.processActiveHandler(HandlerProcessingAddon.java:131)
|
||||
at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.postConstruct(HandlerProcessingAddon.java:51)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:1037)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:142)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:401)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:334)
|
||||
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:228)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:93)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:37)
|
||||
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:276)
|
||||
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:603)
|
||||
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
|
||||
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:583)
|
||||
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
|
||||
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:185)
|
||||
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:298)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:615)
|
||||
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:563)
|
||||
at org.eclipse.equinox.launcher.Main.run(Main.java:1415)
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 4 0 2026-05-09 20:34:16.843
|
||||
!MESSAGE Unable to load class 'org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CloseDialogHandler' from bundle '147'
|
||||
!STACK 0
|
||||
java.lang.ClassNotFoundException: org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CloseDialogHandler cannot be found by org.eclipse.e4.ui.workbench.renderers.swt_0.17.0.v20260131-0926
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:570)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:564)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:439)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:195)
|
||||
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:663)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:88)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:42)
|
||||
at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.processActiveHandler(HandlerProcessingAddon.java:131)
|
||||
at org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon.postConstruct(HandlerProcessingAddon.java:51)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:1037)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:142)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:401)
|
||||
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:334)
|
||||
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:228)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:93)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:37)
|
||||
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:276)
|
||||
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:603)
|
||||
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
|
||||
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:583)
|
||||
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
|
||||
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:185)
|
||||
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:298)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:615)
|
||||
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:563)
|
||||
at org.eclipse.equinox.launcher.Main.run(Main.java:1415)
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 4 0 2026-05-09 20:34:16.878
|
||||
!MESSAGE Unable to load class 'org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CocoaUIHandler' from bundle '147'
|
||||
!STACK 0
|
||||
java.lang.ClassNotFoundException: org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CocoaUIHandler cannot be found by org.eclipse.e4.ui.workbench.renderers.swt_0.17.0.v20260131-0926
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:570)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:564)
|
||||
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:439)
|
||||
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:195)
|
||||
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
|
||||
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:663)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:88)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:59)
|
||||
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:37)
|
||||
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:276)
|
||||
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:603)
|
||||
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
|
||||
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:583)
|
||||
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
|
||||
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:185)
|
||||
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:219)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:149)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:115)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:467)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:298)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:615)
|
||||
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:563)
|
||||
at org.eclipse.equinox.launcher.Main.run(Main.java:1415)
|
||||
|
||||
!ENTRY org.eclipse.jdt.launching 1 0 2026-05-09 20:34:28.087
|
||||
!MESSAGE Installed JRE 'Java SE 21.0.11 [21.0.11]' removed due to missing VM type extension.
|
||||
|
||||
!ENTRY org.eclipse.jdt.launching 1 0 2026-05-09 20:34:28.087
|
||||
!MESSAGE Installed JRE 'JRE [21.0.10]' removed due to missing VM type extension.
|
||||
|
||||
!ENTRY org.eclipse.egit.ui 2 0 2026-05-09 20:34:37.838
|
||||
!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\eslusarz'. 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.
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 2 0 2026-05-09 20:34:38.751
|
||||
!MESSAGE Removing HandlerImpl with the "org.eclipse.e4.ui.workbench.renderers.swt.cocoa.ArrangeWindowHandler" id.It points to the non available "bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.cocoa.ArrangeWindowHandler" class. Bundle might have been uninstalled
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 2 0 2026-05-09 20:34:38.764
|
||||
!MESSAGE Removing HandlerImpl with the "org.eclipse.e4.ui.workbench.renderers.swt.cocoa.MinimizeWindowHandler" id.It points to the non available "bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.cocoa.MinimizeWindowHandler" class. Bundle might have been uninstalled
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 2 0 2026-05-09 20:34:38.767
|
||||
!MESSAGE Removing HandlerImpl with the "org.eclipse.e4.ui.workbench.renderers.swt.cocoa.ZoomWindowHandler" id.It points to the non available "bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.cocoa.ZoomWindowHandler" class. Bundle might have been uninstalled
|
||||
|
||||
!ENTRY org.eclipse.e4.ui.workbench 2 0 2026-05-09 20:34:38.769
|
||||
!MESSAGE Removing HandlerImpl with the "org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CloseDialogHandler" id.It points to the non available "bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.cocoa.CloseDialogHandler" class. Bundle might have been uninstalled
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(ricoverati);
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
|
||||
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
}
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg /
|
||||
}
|
||||
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer>
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return (Double) (avg / pazienti.size());
|
||||
}
|
||||
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
return pazienti1 - pazienti2;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
|
||||
}
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
cliniche.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
return pazienti1 - pazienti2;
|
||||
}
|
||||
});
|
||||
|
||||
return cliniche;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if ()
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iter
|
||||
}
|
||||
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente
|
||||
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
Iterator<Paziente> fixedIt = ricoveratiOrdinati.keySet().iterator();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp =
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else
|
||||
}
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0)
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iter
|
||||
}
|
||||
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
}
|
||||
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put();
|
||||
}
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente>
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
|
||||
}
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iter
|
||||
}
|
||||
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente>
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
return c1 - c2;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
if () {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> ) {
|
||||
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return (Double) (avg / pazienti.size());
|
||||
}
|
||||
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put();
|
||||
}
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
Iterator<String>
|
||||
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
return
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
Iterator<Paziente> fixedIt = ricoveratiOrdinati.keySet().iterator();
|
||||
while (fixedIt.hasNext()) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ordinatiPerCodice(){
|
||||
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
if (cmp == 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it =
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if ()
|
||||
}
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new Map<Integer, Integer>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null)
|
||||
}
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String>
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
}
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear =
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente> {
|
||||
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List ordinaListaClinicaPerNumeroPazienti() {
|
||||
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
if ()
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
Iterator<Paziente> fixedIt = ricoveratiOrdinati.keySet().iterator();
|
||||
while (fixedIt.hasNext()) {
|
||||
ricoverati.add(fixedIt.next());
|
||||
}
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user