added murach files
This commit is contained in:
parent
5c53a73944
commit
eec228a630
0
murach/.metadata/.lock
Normal file
0
murach/.metadata/.lock
Normal file
4
murach/.metadata/.lock_info
Normal file
4
murach/.metadata/.lock_info
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#Thu Dec 26 09:17:18 EST 2024
|
||||||
|
host=L914
|
||||||
|
process-id=33180
|
||||||
|
user=DagostiT
|
||||||
99
murach/.metadata/.log
Normal file
99
murach/.metadata/.log
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
!SESSION 2024-12-26 09:15:39.973 -----------------------------------------------
|
||||||
|
eclipse.buildId=4.34.0.20241128-0756
|
||||||
|
java.version=23.0.1
|
||||||
|
java.vendor=Oracle Corporation
|
||||||
|
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
|
||||||
|
Framework arguments: -product org.eclipse.epp.package.java.product
|
||||||
|
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product
|
||||||
|
|
||||||
|
!ENTRY ch.qos.logback.classic 1 0 2024-12-26 09:15:41.800
|
||||||
|
!MESSAGE Activated before the state location was initialized. Retry after the state location is initialized.
|
||||||
|
|
||||||
|
!ENTRY ch.qos.logback.classic 1 0 2024-12-26 09:15:43.363
|
||||||
|
!MESSAGE Logback config file: C:\Users\Dagostit\OneDrive - The Mental Health Association of Westchester Inc\Documents\Code\java\.metadata\.plugins\org.eclipse.m2e.logback\logback.2.7.0.20241001-1350.xml
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.ui 4 4 2024-12-26 09:15:44.057
|
||||||
|
!MESSAGE Invalid workspace location to be set for Edge browser.
|
||||||
|
!STACK 0
|
||||||
|
java.net.URISyntaxException: Illegal character in path at index 32: file:/C:/Users/Dagostit/OneDrive - The Mental Health Association of Westchester Inc/Documents/Code/java/.metadata/.plugins/org.eclipse.swt
|
||||||
|
at java.base/java.net.URI$Parser.fail(URI.java:2995)
|
||||||
|
at java.base/java.net.URI$Parser.checkChars(URI.java:3166)
|
||||||
|
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3248)
|
||||||
|
at java.base/java.net.URI$Parser.parse(URI.java:3196)
|
||||||
|
at java.base/java.net.URI.<init>(URI.java:645)
|
||||||
|
at java.base/java.net.URL.toURI(URL.java:1220)
|
||||||
|
at org.eclipse.ui.internal.Workbench.setEdgeDataDirectory(Workbench.java:530)
|
||||||
|
at org.eclipse.ui.internal.Workbench.<init>(Workbench.java:461)
|
||||||
|
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:598)
|
||||||
|
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
|
||||||
|
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:570)
|
||||||
|
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
|
||||||
|
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:178)
|
||||||
|
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
|
||||||
|
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
|
||||||
|
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
|
||||||
|
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
|
||||||
|
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
|
||||||
|
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:668)
|
||||||
|
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:605)
|
||||||
|
at org.eclipse.equinox.launcher.Main.run(Main.java:1481)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.egit.ui 2 0 2024-12-26 09:15:50.594
|
||||||
|
!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\Dagostit'. 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.oomph.setup.ui 1 0 2024-12-26 09:15:58.250
|
||||||
|
!MESSAGE Setup tasks were performed during startup updating 5 preferences. See 'C:\Users\Dagostit\eclipse\java-2024-12\eclipse\configuration\org.eclipse.oomph.setup\setup.log' for details
|
||||||
|
!SESSION 2024-12-26 09:17:16.245 -----------------------------------------------
|
||||||
|
eclipse.buildId=4.34.0.20241128-0756
|
||||||
|
java.version=23.0.1
|
||||||
|
java.vendor=Oracle Corporation
|
||||||
|
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
|
||||||
|
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 -data C:\Users\Dagostit\OneDrive - The Mental Health Association of Westchester Inc\Documents\Code\Java
|
||||||
|
|
||||||
|
!ENTRY ch.qos.logback.classic 1 0 2024-12-26 09:17:18.093
|
||||||
|
!MESSAGE Activated before the state location was initialized. Retry after the state location is initialized.
|
||||||
|
|
||||||
|
!ENTRY ch.qos.logback.classic 1 0 2024-12-26 09:17:19.392
|
||||||
|
!MESSAGE Logback config file: C:\Users\Dagostit\OneDrive - The Mental Health Association of Westchester Inc\Documents\Code\java\.metadata\.plugins\org.eclipse.m2e.logback\logback.2.7.0.20241001-1350.xml
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.ui 4 4 2024-12-26 09:17:20.494
|
||||||
|
!MESSAGE Invalid workspace location to be set for Edge browser.
|
||||||
|
!STACK 0
|
||||||
|
java.net.URISyntaxException: Illegal character in path at index 32: file:/C:/Users/Dagostit/OneDrive - The Mental Health Association of Westchester Inc/Documents/Code/java/.metadata/.plugins/org.eclipse.swt
|
||||||
|
at java.base/java.net.URI$Parser.fail(URI.java:2995)
|
||||||
|
at java.base/java.net.URI$Parser.checkChars(URI.java:3166)
|
||||||
|
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3248)
|
||||||
|
at java.base/java.net.URI$Parser.parse(URI.java:3196)
|
||||||
|
at java.base/java.net.URI.<init>(URI.java:645)
|
||||||
|
at java.base/java.net.URL.toURI(URL.java:1220)
|
||||||
|
at org.eclipse.ui.internal.Workbench.setEdgeDataDirectory(Workbench.java:530)
|
||||||
|
at org.eclipse.ui.internal.Workbench.<init>(Workbench.java:461)
|
||||||
|
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:598)
|
||||||
|
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
|
||||||
|
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:570)
|
||||||
|
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
|
||||||
|
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:178)
|
||||||
|
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
|
||||||
|
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
|
||||||
|
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
|
||||||
|
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
|
||||||
|
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
|
||||||
|
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:668)
|
||||||
|
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:605)
|
||||||
|
at org.eclipse.equinox.launcher.Main.run(Main.java:1481)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.egit.ui 2 0 2024-12-26 09:17:24.730
|
||||||
|
!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\Dagostit'. 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.
|
||||||
BIN
murach/.metadata/.mylyn/.taskListIndex/segments_1
Normal file
BIN
murach/.metadata/.mylyn/.taskListIndex/segments_1
Normal file
Binary file not shown.
0
murach/.metadata/.mylyn/.taskListIndex/write.lock
Normal file
0
murach/.metadata/.mylyn/.taskListIndex/write.lock
Normal file
BIN
murach/.metadata/.mylyn/.tasks.xml.zip
Normal file
BIN
murach/.metadata/.mylyn/.tasks.xml.zip
Normal file
Binary file not shown.
BIN
murach/.metadata/.mylyn/repositories.xml.zip
Normal file
BIN
murach/.metadata/.mylyn/repositories.xml.zip
Normal file
Binary file not shown.
BIN
murach/.metadata/.mylyn/tasks.xml.zip
Normal file
BIN
murach/.metadata/.mylyn/tasks.xml.zip
Normal file
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
|
||||||
@ -0,0 +1 @@
|
|||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,6 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.ui.formatterprofiles.version=23
|
||||||
|
spelling_locale_initialized=true
|
||||||
|
typefilter_migrated_2=true
|
||||||
|
useAnnotationsPrefPage=true
|
||||||
|
useQuickDiffPrefPage=true
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.m2e.discovery.pref.projects=
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
migrated.task.repositories.secure.store=true
|
||||||
|
org.eclipse.mylyn.tasks.ui.filters.nonmatching=true
|
||||||
|
org.eclipse.mylyn.tasks.ui.filters.nonmatching.encouraged=true
|
||||||
|
org.eclipse.mylyn.tasks.ui.welcome.message=true
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
platformState=907520816282796
|
||||||
|
quickStart=false
|
||||||
|
tipsAndTricks=true
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
//org.eclipse.ui.commands/state/org.eclipse.ui.navigator.resources.nested.changeProjectPresentation/org.eclipse.ui.commands.radioState=false
|
||||||
|
PLUGINS_NOT_ACTIVATED_ON_STARTUP=;org.eclipse.m2e.discovery;
|
||||||
|
RUN_IN_BACKGROUND=false
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_END=41,41,41
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START=43,44,45
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_TEXT_COLOR=204,204,204
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_TAB_BG_END=41,41,41
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_TAB_BG_START=43,44,45
|
||||||
|
org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR=221,221,221
|
||||||
|
org.eclipse.ui.workbench.INACTIVE_TAB_BG_END=49,53,56
|
||||||
|
org.eclipse.ui.workbench.INACTIVE_TAB_BG_START=59,64,66
|
||||||
|
org.eclipse.ui.workbench.INACTIVE_TAB_TEXT_COLOR=187,187,187
|
||||||
2433
murach/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
Normal file
2433
murach/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
java
|
||||||
Binary file not shown.
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<typeInfoHistroy/>
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<qualifiedTypeNameHistroy/>
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<section name="Workbench">
|
||||||
|
<section name="org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart">
|
||||||
|
<item key="group_libraries" value="true"/>
|
||||||
|
<item key="layout" value="2"/>
|
||||||
|
<item key="rootMode" value="1"/>
|
||||||
|
<item key="linkWithEditor" value="false"/>
|
||||||
|
<item key="memento" value="<?xml version="1.0" encoding="UTF-8"?>
<packageExplorer group_libraries="1" layout="2" linkWithEditor="0" rootMode="1" workingSetName="Aggregate for window 1735222547717">
<customFilters userDefinedPatternsEnabled="false">
<xmlDefinedFilters>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.StaticsFilter" isEnabled="false"/>
<child filterId="org.eclipse.buildship.ui.packageexplorer.filter.gradle.buildfolder" isEnabled="true"/>
<child filterId="org.eclipse.mylyn.java.ui.MembersFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.NonJavaProjectsFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer_patternFilterId_.*" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.NonSharedProjectsFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.SyntheticMembersFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.ContainedLibraryFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.internal.ui.PackageExplorer.HideInnerClassFilesFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.internal.ui.PackageExplorer.EmptyInnerPackageFilter" isEnabled="true"/>
<child filterId="org.eclipse.m2e.MavenModuleFilter" isEnabled="false"/>
<child filterId="org.eclipse.buildship.ui.packageexplorer.filter.gradle.subProject" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.ClosedProjectsFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.DeprecatedMembersFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.EmptyLibraryContainerFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.PackageDeclarationFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.ImportDeclarationFilter" isEnabled="true"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.NonJavaElementFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.LibraryFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.CuAndClassFileFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.internal.ui.PackageExplorer.EmptyPackageFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.NonPublicFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.LocalTypesFilter" isEnabled="false"/>
<child filterId="org.eclipse.jdt.ui.PackageExplorer.FieldsFilter" isEnabled="false"/>
</xmlDefinedFilters>
</customFilters>
</packageExplorer>"/>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
2
murach/.metadata/.plugins/org.eclipse.m2e.logback/0.log
Normal file
2
murach/.metadata/.plugins/org.eclipse.m2e.logback/0.log
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
2024-12-26 09:15:50,435 [Worker-7: Loading available Gradle versions] INFO o.e.b.c.i.u.g.PublishedGradleVersions - Gradle version information cache is not available. Remote download required.
|
||||||
|
2024-12-26 09:17:24,563 [Worker-5: Loading available Gradle versions] INFO o.e.b.c.i.u.g.PublishedGradleVersions - Gradle version information cache is up-to-date. Trying to read.
|
||||||
Binary file not shown.
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<section name="Workbench">
|
||||||
|
<section name="SetupWizard">
|
||||||
|
<section name="VariablePage">
|
||||||
|
</section>
|
||||||
|
<section name="ConfirmationPage">
|
||||||
|
</section>
|
||||||
|
<section name="ProgressPage">
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
<section name="org.eclipse.oomph.setup.ui.wizards.SetupWizard$Updater">
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<section name="Workbench">
|
||||||
|
</section>
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<section name="Workbench">
|
||||||
|
<section name="ChooseWorkspaceDialogSettings">
|
||||||
|
<item key="DIALOG_X_ORIGIN" value="172"/>
|
||||||
|
<item key="DIALOG_Y_ORIGIN" value="197"/>
|
||||||
|
</section>
|
||||||
|
<section name="WORKBENCH_SETTINGS">
|
||||||
|
<list key="ENABLED_TRANSFERS">
|
||||||
|
</list>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<workingSetManager>
|
||||||
|
<workingSet editPageId="org.eclipse.jdt.internal.ui.DynamicSourcesWorkingSet" factoryID="org.eclipse.ui.internal.WorkingSetFactory" id="1735222546803_0" label="Java Main Sources" name="Java Main Sources"/>
|
||||||
|
<workingSet editPageId="org.eclipse.jdt.internal.ui.DynamicSourcesWorkingSet" factoryID="org.eclipse.ui.internal.WorkingSetFactory" id="1735222546814_1" label="Java Test Sources" name="Java Test Sources"/>
|
||||||
|
<workingSet aggregate="true" factoryID="org.eclipse.ui.internal.WorkingSetFactory" id="1735222547718_2" label="Window Working Set" name="Aggregate for window 1735222547717"/>
|
||||||
|
</workingSetManager>
|
||||||
3
murach/.metadata/version.ini
Normal file
3
murach/.metadata/version.ini
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#Thu Dec 26 09:17:18 EST 2024
|
||||||
|
org.eclipse.core.runtime=2
|
||||||
|
org.eclipse.platform=4.34.0.v20241120-1800
|
||||||
69
murach/db/products.sql
Normal file
69
murach/db/products.sql
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
-- Drop the tables if they already exist in order to start with a fresh
|
||||||
|
-- database. You will lose any changes you have made to this data.
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Products;
|
||||||
|
DROP TABLE IF EXISTS LineItems;
|
||||||
|
|
||||||
|
-- Create the tables
|
||||||
|
CREATE TABLE Products (
|
||||||
|
ProductCode TEXT PRIMARY KEY NOT NULL,
|
||||||
|
Description TEXT UNIQUE NOT NULL,
|
||||||
|
Price REAL NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE LineItems (
|
||||||
|
LineItemID INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
InvoiceID INTEGER NOT NULL,
|
||||||
|
ProductCode TEXT NOT NULL,
|
||||||
|
Quantity INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY(ProductCode) REFERENCES Products(ProductCode)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
-- Populate the Products table
|
||||||
|
INSERT INTO Products VALUES
|
||||||
|
('java', 'Murach''s Java Programming', 57.50);
|
||||||
|
|
||||||
|
INSERT INTO Products VALUES
|
||||||
|
('jsp', 'Murach''s Java Servlets and JSP', 57.50);
|
||||||
|
|
||||||
|
INSERT INTO Products VALUES
|
||||||
|
('mysql', 'Murach''s MySQL', 54.50);
|
||||||
|
|
||||||
|
INSERT INTO Products VALUES
|
||||||
|
('orac', 'Murach''s Oracle and PL/SQL', 54.50);
|
||||||
|
|
||||||
|
INSERT INTO Products VALUES
|
||||||
|
('andr', 'Murach''s Android Programming', 57.50);
|
||||||
|
|
||||||
|
INSERT INTO Products VALUES
|
||||||
|
('html', 'Murach''s HTML and CSS', 54.50);
|
||||||
|
|
||||||
|
INSERT INTO Products VALUES
|
||||||
|
('jscr', 'Murach''s JavaScript and jQuery', 54.50);
|
||||||
|
|
||||||
|
|
||||||
|
-- Populate the LineItems table
|
||||||
|
INSERT INTO LineItems VALUES
|
||||||
|
(1, 1, 'java', 5);
|
||||||
|
|
||||||
|
INSERT INTO LineItems VALUES
|
||||||
|
(2, 1, 'jsp', 5);
|
||||||
|
|
||||||
|
INSERT INTO LineItems VALUES
|
||||||
|
(3, 2, 'mysql', 1);
|
||||||
|
|
||||||
|
INSERT INTO LineItems VALUES
|
||||||
|
(4, 3, 'andr', 1);
|
||||||
|
|
||||||
|
INSERT INTO LineItems VALUES
|
||||||
|
(5, 3, 'orac', 2);
|
||||||
|
|
||||||
|
INSERT INTO LineItems VALUES
|
||||||
|
(6, 4, 'html', 1);
|
||||||
|
|
||||||
|
INSERT INTO LineItems VALUES
|
||||||
|
(7, 5, 'java', 1);
|
||||||
|
|
||||||
|
INSERT INTO LineItems VALUES
|
||||||
|
(8, 5, 'mysql', 5);
|
||||||
BIN
murach/db/products.sqlite
Normal file
BIN
murach/db/products.sqlite
Normal file
Binary file not shown.
BIN
murach/db/sqlite-jdbc.jar
Normal file
BIN
murach/db/sqlite-jdbc.jar
Normal file
Binary file not shown.
0
murach/eclipse/.metadata/.lock
Normal file
0
murach/eclipse/.metadata/.lock
Normal file
4
murach/eclipse/.metadata/.lock_info
Normal file
4
murach/eclipse/.metadata/.lock_info
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#Thu Dec 26 12:10:11 EST 2024
|
||||||
|
host=L914
|
||||||
|
process-id=30968
|
||||||
|
user=DagostiT
|
||||||
5330
murach/eclipse/.metadata/.log
Normal file
5330
murach/eclipse/.metadata/.log
Normal file
File diff suppressed because it is too large
Load Diff
BIN
murach/eclipse/.metadata/.mylyn/repositories.xml.zip
Normal file
BIN
murach/eclipse/.metadata/.mylyn/repositories.xml.zip
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package ch01_Test1;
|
||||||
|
|
||||||
|
public class TestApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Success!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package ch01_Test1;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TestApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String myName;
|
||||||
|
System.out.println("Enter your name:/n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
myName = sc.nextLine();
|
||||||
|
System.out.println(myName);
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class InvoiceApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("The Invoice Total Calculator\n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
String choice = "y";
|
||||||
|
|
||||||
|
while (choice.equalsIgnoreCase("y")) {
|
||||||
|
// get the input from the user
|
||||||
|
System.out.print("Enter customer type (r/c): ");
|
||||||
|
String customerType = sc.nextLine();
|
||||||
|
|
||||||
|
System.out.print("Enter subtotal: ");
|
||||||
|
double subtotal = Double.parseDouble(sc.nextLine());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
// get the discount percent
|
||||||
|
double discountPercent = switch(customerType) {
|
||||||
|
case "r", "R" -> {
|
||||||
|
if (subtotal >= 250) {
|
||||||
|
yield .2;
|
||||||
|
} else if (subtotal >= 100) {
|
||||||
|
yield .1;
|
||||||
|
} else {
|
||||||
|
yield 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "c", "C" -> {
|
||||||
|
if (subtotal >= 250) {
|
||||||
|
yield .3;
|
||||||
|
} else {
|
||||||
|
yield .2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> .1;
|
||||||
|
};
|
||||||
|
|
||||||
|
// calculate the discount amount and round to 2 decimals
|
||||||
|
double discountAmount = subtotal * discountPercent;
|
||||||
|
discountAmount = Math.ceil(discountAmount * 100) / 100;
|
||||||
|
|
||||||
|
// calculate the total
|
||||||
|
double total = subtotal - discountAmount;
|
||||||
|
|
||||||
|
// format and display the results
|
||||||
|
NumberFormat currency = NumberFormat.getCurrencyInstance();
|
||||||
|
NumberFormat percent = NumberFormat.getPercentInstance();
|
||||||
|
String format = "%-20s%12s%n";
|
||||||
|
|
||||||
|
System.out.println("INVOICE"); // print blank line
|
||||||
|
System.out.printf(format, "Subtotal:",
|
||||||
|
currency.format(subtotal));
|
||||||
|
System.out.printf(format, "Discount percent:",
|
||||||
|
percent.format(discountPercent));
|
||||||
|
System.out.printf(format, "Discount amount:",
|
||||||
|
currency.format(discountAmount));
|
||||||
|
System.out.printf(format, "Total:",
|
||||||
|
currency.format(total));
|
||||||
|
System.out.println(); // print blank line
|
||||||
|
|
||||||
|
// see if the user wants to continue
|
||||||
|
System.out.print("Continue? (y/n): ");
|
||||||
|
choice = sc.nextLine();
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
System.out.println("Bye!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package ch01_Test1;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TestApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String myName;
|
||||||
|
System.out.println("Enter your name:\n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
myName = sc.nextLine();
|
||||||
|
System.console().flush();
|
||||||
|
System.out.println("\n" + "Welcome to the Test App, " + myName + "!");
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,129 @@
|
|||||||
|
package com.murach.future_value;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class FutureValueApplication extends Application {
|
||||||
|
private TextField investmentField;
|
||||||
|
private TextField interestRateField;
|
||||||
|
private ComboBox<Integer> yearsCombo = new ComboBox<Integer>();
|
||||||
|
private ListView futureValues = new ListView();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
primaryStage.setTitle("Future Value Calculator");
|
||||||
|
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setAlignment(Pos.TOP_CENTER);
|
||||||
|
grid.setPadding(new Insets(25, 25, 25, 25));
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
|
||||||
|
Scene scene = new Scene(grid);
|
||||||
|
|
||||||
|
grid.add(new Label("Monthly Investment:"), 0, 0);
|
||||||
|
investmentField = new TextField();
|
||||||
|
grid.add(investmentField, 1, 0);
|
||||||
|
|
||||||
|
grid.add(new Label("Yearly Interest Rate:"), 0, 1);
|
||||||
|
interestRateField = new TextField();
|
||||||
|
grid.add(interestRateField, 1, 1);
|
||||||
|
|
||||||
|
|
||||||
|
grid.add(new Label("Years:"), 0, 2);
|
||||||
|
yearsCombo.setPromptText("Select Number of Years");
|
||||||
|
for(int i = 1; i <= 20; i++) {
|
||||||
|
yearsCombo.getItems().add(i);
|
||||||
|
}
|
||||||
|
grid.add(yearsCombo, 1, 2);
|
||||||
|
|
||||||
|
HBox listViewContainer = new HBox(10);
|
||||||
|
futureValues.setPrefHeight(5*24);
|
||||||
|
listViewContainer.getChildren().add(futureValues);
|
||||||
|
grid.add(new Label("Future Value:"), 0, 3);
|
||||||
|
grid.add(listViewContainer, 1, 3);
|
||||||
|
|
||||||
|
Button calculateButton = new Button("Calculate");
|
||||||
|
calculateButton.setOnAction(event -> calculateButtonClicked());
|
||||||
|
|
||||||
|
Button exitButton = new Button("Exit");
|
||||||
|
exitButton.setOnAction(event -> exitButtonClicked());
|
||||||
|
|
||||||
|
HBox buttonBox = new HBox(10);
|
||||||
|
buttonBox.getChildren().add(calculateButton);
|
||||||
|
buttonBox.getChildren().add(exitButton);
|
||||||
|
buttonBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||||
|
grid.add(buttonBox, 0, 4, 2, 1);
|
||||||
|
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateButtonClicked() {
|
||||||
|
Validation v = new Validation();
|
||||||
|
String errorMsg = "";
|
||||||
|
int years = yearsCombo.getSelectionModel().getSelectedItem();
|
||||||
|
errorMsg += v.isDouble(investmentField.getText(),
|
||||||
|
"Monthly Investment");
|
||||||
|
errorMsg += v.isDouble(interestRateField.getText(),
|
||||||
|
"Yearly Interest Rate");
|
||||||
|
errorMsg += v.isInteger(String.valueOf(years), "Years");
|
||||||
|
|
||||||
|
if (errorMsg.isEmpty()) {
|
||||||
|
double investment = Double.parseDouble(
|
||||||
|
investmentField.getText());
|
||||||
|
double rate = Double.parseDouble(
|
||||||
|
interestRateField.getText());
|
||||||
|
|
||||||
|
NumberFormat currency = NumberFormat.getCurrencyInstance();
|
||||||
|
for(int i = 1; i <= years; i++) {
|
||||||
|
double futureValue = calculateFutureValue(
|
||||||
|
investment, rate, i);
|
||||||
|
futureValues.getItems().add(
|
||||||
|
"Year " + i + ": " + currency.format(futureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setHeaderText("Invalid Data");
|
||||||
|
alert.setContentText(errorMsg);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calculateFutureValue(double investment, double rate, int years) {
|
||||||
|
double futureValue = 0.0;
|
||||||
|
|
||||||
|
// convert yearly values to monthly values
|
||||||
|
double monthlyInterestRate = rate / 12 / 100;
|
||||||
|
int months = years * 12;
|
||||||
|
|
||||||
|
for (int i = 1; i <= months; i++) {
|
||||||
|
futureValue = (futureValue + investment)
|
||||||
|
* (1 + monthlyInterestRate);
|
||||||
|
}
|
||||||
|
return futureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitButtonClicked() {
|
||||||
|
System.exit(0); // 0 indicates a normal exit
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package ch01_Test1;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TestApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String myName;
|
||||||
|
System.out.println("Enter your name:\n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
myName = sc.nextLine();
|
||||||
|
System.out.print("\033[H\033[2J");
|
||||||
|
System.out.flush();
|
||||||
|
System.out.println("\n" + "Welcome to the Test App, " + myName + "!");
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=23
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=23
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=23
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class GuessNumberApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final int LIMIT = 10;
|
||||||
|
|
||||||
|
System.out.println("Guess the number!");
|
||||||
|
System.out.println("I'm thinking of a number from 1 to " + LIMIT);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
// get a random number between 1 and the limit
|
||||||
|
double d = Math.random() * LIMIT; // d is >= 0.0 and < limit
|
||||||
|
int number = (int) d; // convert double to int
|
||||||
|
number++; // int is >= 1 and <= limit
|
||||||
|
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int count = 1;
|
||||||
|
while (true) {
|
||||||
|
System.out.print("Your guess: ");
|
||||||
|
String input = sc.nextLine();
|
||||||
|
int guess = Integer.parseInt(input);
|
||||||
|
|
||||||
|
if (guess < 1 || guess > LIMIT) {
|
||||||
|
System.out.println("Invalid guess. Try again.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guess < number) {
|
||||||
|
System.out.println("Too low.");
|
||||||
|
} else if (guess > number) {
|
||||||
|
System.out.println("Too high.");
|
||||||
|
} else {
|
||||||
|
System.out.println("You guessed it in " +
|
||||||
|
count + " tries.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
System.out.println("Bye!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class InvoiceApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// welcome the user to the program
|
||||||
|
System.out.println("Welcome to the Invoice Total Calculator");
|
||||||
|
System.out.println(); // print a blank line
|
||||||
|
|
||||||
|
// create a Scanner object named sc
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
// perform invoice calculations until choice isn't equal to "y" or "Y"
|
||||||
|
String choice = "y";
|
||||||
|
while (choice.equalsIgnoreCase("y")) {
|
||||||
|
// get the invoice subtotal from the user
|
||||||
|
System.out.print("Enter subtotal: ");
|
||||||
|
String input = sc.nextLine();
|
||||||
|
double subtotal = Double.parseDouble(input);
|
||||||
|
|
||||||
|
// calculate the discount amount and total
|
||||||
|
double discountPercent;
|
||||||
|
if (subtotal >= 200) {
|
||||||
|
discountPercent = .2;
|
||||||
|
} else if (subtotal >= 100) {
|
||||||
|
discountPercent = .1;
|
||||||
|
} else {
|
||||||
|
discountPercent = 0.0;
|
||||||
|
}
|
||||||
|
double discountAmount = subtotal * discountPercent;
|
||||||
|
double total = subtotal - discountAmount;
|
||||||
|
|
||||||
|
// display the discount amount and total
|
||||||
|
String message = "Discount percent: " + discountPercent + "\n"
|
||||||
|
+ "Discount amount: " + discountAmount + "\n"
|
||||||
|
+ "Invoice total: " + total + "\n";
|
||||||
|
System.out.println(message);
|
||||||
|
|
||||||
|
// see if the user wants to continue
|
||||||
|
System.out.print("Continue? (y/n): ");
|
||||||
|
choice = sc.nextLine();
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,131 @@
|
|||||||
|
package murach.ch13_ex2_pizzacalculator;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaFX App
|
||||||
|
*/
|
||||||
|
public class App extends Application {
|
||||||
|
|
||||||
|
// class globals
|
||||||
|
private ToggleGroup sizeToggle = new ToggleGroup();
|
||||||
|
private CheckBox sausageBox = new CheckBox("Sausage");
|
||||||
|
private CheckBox peppBox = new CheckBox("Pepperoni");
|
||||||
|
private CheckBox salamiBox = new CheckBox("Salami");
|
||||||
|
private CheckBox oliveBox = new CheckBox("Olives");
|
||||||
|
private CheckBox mushBox = new CheckBox("Mushrooms");
|
||||||
|
private CheckBox anchBox = new CheckBox("Anchovies");
|
||||||
|
private TextField priceField = new TextField();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) {
|
||||||
|
stage.setTitle("Pizza Price Calculcator");
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
VBox appContainer = new VBox(10);
|
||||||
|
// size
|
||||||
|
Label sizeLabel = new Label("Size");
|
||||||
|
HBox sizeBox = new HBox(10);
|
||||||
|
|
||||||
|
RadioButton smallButton = new RadioButton("Small");
|
||||||
|
smallButton.setToggleGroup(sizeToggle);
|
||||||
|
smallButton.setSelected(true);
|
||||||
|
RadioButton mediumButton = new RadioButton("Medium");
|
||||||
|
mediumButton.setToggleGroup(sizeToggle);
|
||||||
|
RadioButton largeButton = new RadioButton("Large");
|
||||||
|
largeButton.setToggleGroup(sizeToggle);
|
||||||
|
|
||||||
|
sizeBox.getChildren().add(smallButton);
|
||||||
|
sizeBox.getChildren().add(mediumButton);
|
||||||
|
sizeBox.getChildren().add(largeButton);
|
||||||
|
appContainer.getChildren().add(sizeLabel);
|
||||||
|
appContainer.getChildren().add(sizeBox);
|
||||||
|
|
||||||
|
// toppings
|
||||||
|
Label toppingsLabel = new Label("Toppings");
|
||||||
|
HBox sizeContainer = new HBox(10);
|
||||||
|
VBox sizeCol1 = new VBox(10);
|
||||||
|
VBox sizeCol2 = new VBox(10);
|
||||||
|
|
||||||
|
sizeCol1.getChildren().add(sausageBox);
|
||||||
|
sizeCol1.getChildren().add(peppBox);
|
||||||
|
sizeCol1.getChildren().add(salamiBox);
|
||||||
|
sizeCol2.getChildren().add(oliveBox);
|
||||||
|
sizeCol2.getChildren().add(mushBox);
|
||||||
|
sizeCol2.getChildren().add(anchBox);
|
||||||
|
sizeContainer.getChildren().add(sizeCol1);
|
||||||
|
sizeContainer.getChildren().add(sizeCol2);
|
||||||
|
appContainer.getChildren().add(toppingsLabel);
|
||||||
|
appContainer.getChildren().add(sizeContainer);
|
||||||
|
|
||||||
|
// price output
|
||||||
|
Label priceLabel = new Label("Price: ");
|
||||||
|
HBox priceContainer = new HBox(10);
|
||||||
|
priceField.setEditable(false);
|
||||||
|
priceContainer.getChildren().add(priceLabel);
|
||||||
|
priceContainer.getChildren().add(priceField);
|
||||||
|
appContainer.getChildren().add(priceContainer);
|
||||||
|
|
||||||
|
// calculate button
|
||||||
|
Button signUpButton = new Button("Calculate");
|
||||||
|
signUpButton.setOnAction(event -> calculatePrice(stage));
|
||||||
|
appContainer.getChildren().add(signUpButton);
|
||||||
|
|
||||||
|
grid.add(appContainer, 0, 5);
|
||||||
|
grid.setPadding(new Insets(10, 10, 0, 10));
|
||||||
|
Scene scene = new Scene(grid, 225, 250);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculatePrice(Stage stage) {
|
||||||
|
double price = 0.0;
|
||||||
|
RadioButton size =
|
||||||
|
(RadioButton) sizeToggle.getSelectedToggle();
|
||||||
|
if(size.getText() == "Small") {
|
||||||
|
price += 6.99;
|
||||||
|
} else if(size.getText() == "Medium") {
|
||||||
|
price += 8.99;
|
||||||
|
} else {
|
||||||
|
price += 10.99;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sausageBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(peppBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(salamiBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(oliveBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
if(mushBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
if(anchBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
price = (double)Math.round(price * 100.0) / 100.0;
|
||||||
|
priceField.setText("$" + price);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,129 @@
|
|||||||
|
package com.murach.future_value;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class FutureValueApplication extends Application {
|
||||||
|
private TextField investmentField;
|
||||||
|
private TextField interestRateField;
|
||||||
|
private ComboBox<Integer> yearsCombo = new ComboBox<Integer>();
|
||||||
|
private ListView futureValues = new ListView();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
primaryStage.setTitle("Future Value Calculator");
|
||||||
|
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setAlignment(Pos.TOP_CENTER);
|
||||||
|
grid.setPadding(new Insets(25, 25, 25, 25));
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
|
||||||
|
Scene scene = new Scene(grid);
|
||||||
|
|
||||||
|
grid.add(new Label("Monthly Investment:"), 0, 0);
|
||||||
|
investmentField = new TextField();
|
||||||
|
grid.add(investmentField, 1, 0);
|
||||||
|
|
||||||
|
grid.add(new Label("Yearly Interest Rate:"), 0, 1);
|
||||||
|
interestRateField = new TextField();
|
||||||
|
grid.add(interestRateField, 1, 1);
|
||||||
|
|
||||||
|
|
||||||
|
grid.add(new Label("Years:"), 0, 2);
|
||||||
|
yearsCombo.setPromptText("Select Number of Years");
|
||||||
|
for(int i = 1; i <= 20; i++) {
|
||||||
|
yearsCombo.getItems().add(i);
|
||||||
|
}
|
||||||
|
grid.add(yearsCombo, 1, 2);
|
||||||
|
|
||||||
|
HBox listViewContainer = new HBox(10);
|
||||||
|
futureValues.setPrefHeight(5*24);
|
||||||
|
listViewContainer.getChildren().add(futureValues);
|
||||||
|
grid.add(new Label("Future Value:"), 0, 3);
|
||||||
|
grid.add(listViewContainer, 1, 3);
|
||||||
|
|
||||||
|
Button calculateButton = new Button("Calculate");
|
||||||
|
calculateButton.setOnAction(event -> calculateButtonClicked());
|
||||||
|
|
||||||
|
Button exitButton = new Button("Exit");
|
||||||
|
exitButton.setOnAction(event -> exitButtonClicked());
|
||||||
|
|
||||||
|
HBox buttonBox = new HBox(10);
|
||||||
|
buttonBox.getChildren().add(calculateButton);
|
||||||
|
buttonBox.getChildren().add(exitButton);
|
||||||
|
buttonBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||||
|
grid.add(buttonBox, 0, 4, 2, 1);
|
||||||
|
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateButtonClicked() {
|
||||||
|
Validation v = new Validation();
|
||||||
|
String errorMsg = "";
|
||||||
|
int years = yearsCombo.getSelectionModel().getSelectedItem();
|
||||||
|
errorMsg += v.isDouble(investmentField.getText(),
|
||||||
|
"Monthly Investment");
|
||||||
|
errorMsg += v.isDouble(interestRateField.getText(),
|
||||||
|
"Yearly Interest Rate");
|
||||||
|
errorMsg += v.isInteger(String.valueOf(years), "Years");
|
||||||
|
|
||||||
|
if (errorMsg.isEmpty()) {
|
||||||
|
double investment = Double.parseDouble(
|
||||||
|
investmentField.getText());
|
||||||
|
double rate = Double.parseDouble(
|
||||||
|
interestRateField.getText());
|
||||||
|
|
||||||
|
NumberFormat currency = NumberFormat.getCurrencyInstance();
|
||||||
|
for(int i = 1; i <= years; i++) {
|
||||||
|
double futureValue = calculateFutureValue(
|
||||||
|
investment, rate, i);
|
||||||
|
futureValues.getItems().add(
|
||||||
|
"Year " + i + ": " + currency.format(futureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setHeaderText("Invalid Data");
|
||||||
|
alert.setContentText(errorMsg);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calculateFutureValue(double investment, double rate, int years) {
|
||||||
|
double futureValue = 0.0;
|
||||||
|
|
||||||
|
// convert yearly values to monthly values
|
||||||
|
double monthlyInterestRate = rate / 12 / 100;
|
||||||
|
int months = years * 12;
|
||||||
|
|
||||||
|
for (int i = 1; i <= months; i++) {
|
||||||
|
futureValue = (futureValue + investment)
|
||||||
|
* (1 + monthlyInterestRate);
|
||||||
|
}
|
||||||
|
return futureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitButtonClicked() {
|
||||||
|
System.exit(0); // 0 indicates a normal exit
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class ProductApp {
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
// display a welcome message
|
||||||
|
System.out.println("Welcome to the Product Viewer");
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
// display 1 or more products
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
String choice = "y";
|
||||||
|
while (choice.equalsIgnoreCase("y")) {
|
||||||
|
// get the input from the user
|
||||||
|
System.out.print("Enter product code: ");
|
||||||
|
String productCode = sc.nextLine(); // read the product code
|
||||||
|
|
||||||
|
// get the Product object
|
||||||
|
Product product = ProductDB.getProduct(productCode);
|
||||||
|
|
||||||
|
// display the output
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("SELECTED PRODUCT");
|
||||||
|
System.out.println("Description: " + product.getDescription());
|
||||||
|
System.out.println("Price: " + product.getPriceFormatted());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
// see if the user wants to continue
|
||||||
|
System.out.print("Continue? (y/n): ");
|
||||||
|
choice = sc.nextLine();
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,130 @@
|
|||||||
|
package murach.ch13_ex2_pizzacalculator;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaFX App
|
||||||
|
*/
|
||||||
|
public class App extends Application {
|
||||||
|
|
||||||
|
// class globals
|
||||||
|
private ToggleGroup sizeToggle = new ToggleGroup();
|
||||||
|
private CheckBox sausageBox = new CheckBox("Sausage");
|
||||||
|
private CheckBox peppBox = new CheckBox("Pepperoni");
|
||||||
|
private CheckBox salamiBox = new CheckBox("Salami");
|
||||||
|
private CheckBox oliveBox = new CheckBox("Olives");
|
||||||
|
private CheckBox mushBox = new CheckBox("Mushrooms");
|
||||||
|
private CheckBox anchBox = new CheckBox("Anchovies");
|
||||||
|
private TextField priceField = new TextField();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) {
|
||||||
|
stage.setTitle("Pizza Price Calculcator");
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
VBox appContainer = new VBox(10);
|
||||||
|
// size
|
||||||
|
Label sizeLabel = new Label("Size");
|
||||||
|
HBox sizeBox = new HBox(10);
|
||||||
|
|
||||||
|
RadioButton smallButton = new RadioButton("Small");
|
||||||
|
smallButton.setToggleGroup(sizeToggle);
|
||||||
|
smallButton.setSelected(true);
|
||||||
|
RadioButton mediumButton = new RadioButton("Medium");
|
||||||
|
mediumButton.setToggleGroup(sizeToggle);
|
||||||
|
RadioButton largeButton = new RadioButton("Large");
|
||||||
|
largeButton.setToggleGroup(sizeToggle);
|
||||||
|
|
||||||
|
sizeBox.getChildren().add(smallButton);
|
||||||
|
sizeBox.getChildren().add(mediumButton);
|
||||||
|
sizeBox.getChildren().add(largeButton);
|
||||||
|
appContainer.getChildren().add(sizeLabel);
|
||||||
|
appContainer.getChildren().add(sizeBox);
|
||||||
|
|
||||||
|
// toppings
|
||||||
|
Label toppingsLabel = new Label("Toppings");
|
||||||
|
HBox sizeContainer = new HBox(10);
|
||||||
|
VBox sizeCol1 = new VBox(10);
|
||||||
|
VBox sizeCol2 = new VBox(10);
|
||||||
|
|
||||||
|
sizeCol1.getChildren().add(sausageBox);
|
||||||
|
sizeCol1.getChildren().add(peppBox);
|
||||||
|
sizeCol1.getChildren().add(salamiBox);
|
||||||
|
sizeCol2.getChildren().add(oliveBox);
|
||||||
|
sizeCol2.getChildren().add(mushBox);
|
||||||
|
sizeCol2.getChildren().add(anchBox);
|
||||||
|
sizeContainer.getChildren().add(sizeCol1);
|
||||||
|
sizeContainer.getChildren().add(sizeCol2);
|
||||||
|
appContainer.getChildren().add(toppingsLabel);
|
||||||
|
appContainer.getChildren().add(sizeContainer);
|
||||||
|
|
||||||
|
// price output
|
||||||
|
Label priceLabel = new Label("Price: ");
|
||||||
|
HBox priceContainer = new HBox(10);
|
||||||
|
priceField.setEditable(false);
|
||||||
|
priceContainer.getChildren().add(priceLabel);
|
||||||
|
priceContainer.getChildren().add(priceField);
|
||||||
|
appContainer.getChildren().add(priceContainer);
|
||||||
|
|
||||||
|
// calculate button
|
||||||
|
Button signUpButton = new Button("Calculate");
|
||||||
|
signUpButton.setOnAction(event -> calculatePrice(stage));
|
||||||
|
appContainer.getChildren().add(signUpButton);
|
||||||
|
|
||||||
|
grid.add(appContainer, 0, 5);
|
||||||
|
grid.setPadding(new Insets(10, 10, 0, 10));
|
||||||
|
Scene scene = new Scene(grid, 225, 250);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculatePrice(Stage stage) {
|
||||||
|
double price = 0.0;
|
||||||
|
RadioButton size =
|
||||||
|
(RadioButton) sizeToggle.getSelectedToggle();
|
||||||
|
if(size.getText() == "Small") {
|
||||||
|
price += 6.99;
|
||||||
|
} else if(size.getText() == "Medium") {
|
||||||
|
price += 8.99;
|
||||||
|
} else {
|
||||||
|
price += 10.99;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sausageBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(peppBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(salamiBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(oliveBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
if(mushBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
if(anchBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
price = (double)Math.round(price * 100.0) / 100.0;
|
||||||
|
priceField.setText("$" + price);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
public class FutureValueApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Welcome to the Future Value Calculator\n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
String choice = "y";
|
||||||
|
while (!choice.equalsIgnoreCase("n")) {
|
||||||
|
// get the input from the user
|
||||||
|
System.out.print("Enter monthly investment: ");
|
||||||
|
double monthlyInvestment = Double.parseDouble(sc.nextLine());
|
||||||
|
|
||||||
|
System.out.print("Enter yearly interest rate: ");
|
||||||
|
double interestRate = Double.parseDouble(sc.nextLine());
|
||||||
|
|
||||||
|
System.out.print("Enter number of years: ");
|
||||||
|
int years = Integer.parseInt(sc.nextLine());
|
||||||
|
|
||||||
|
// call the method that calculates the future value
|
||||||
|
double futureValue = calculateFutureValue(monthlyInvestment,
|
||||||
|
interestRate, years);
|
||||||
|
|
||||||
|
// format and display the result
|
||||||
|
NumberFormat currency = NumberFormat.getCurrencyInstance();
|
||||||
|
System.out.println("Future value: "
|
||||||
|
+ currency.format(futureValue));
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
// see if the user wants to continue
|
||||||
|
System.out.print("Continue? (y/n): ");
|
||||||
|
choice = sc.nextLine();
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double calculateFutureValue(double monthlyInvestment,
|
||||||
|
double interestRate, int years) {
|
||||||
|
|
||||||
|
// convert yearly values to monthly values
|
||||||
|
double monthlyInterestRate = interestRate / 12 / 100;
|
||||||
|
int months = years * 12;
|
||||||
|
|
||||||
|
// calculate future value
|
||||||
|
double futureValue = 0.0;
|
||||||
|
for (int i = 1; i <= months; i++) {
|
||||||
|
futureValue = (futureValue + monthlyInvestment)
|
||||||
|
* (1 + monthlyInterestRate);
|
||||||
|
}
|
||||||
|
return futureValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package murach.ch13_ex2_pizzacalculator;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaFX App
|
||||||
|
*/
|
||||||
|
public class App extends Application {
|
||||||
|
|
||||||
|
// class globals
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) {
|
||||||
|
stage.setTitle("Pizza Price Calculcator");
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
VBox appContainer = new VBox(10);
|
||||||
|
|
||||||
|
// size
|
||||||
|
|
||||||
|
// toppings
|
||||||
|
|
||||||
|
// price output
|
||||||
|
|
||||||
|
// calculate button
|
||||||
|
|
||||||
|
grid.add(appContainer, 0, 5);
|
||||||
|
grid.setPadding(new Insets(10, 10, 0, 10));
|
||||||
|
Scene scene = new Scene(grid, 225, 250);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculatePrice(Stage stage) {
|
||||||
|
double price = 0.0;
|
||||||
|
// calulation code here
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
package com.murach.mpg;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class MpgApp extends Application {
|
||||||
|
private TextField milesField;
|
||||||
|
private TextField gallonsField;
|
||||||
|
private TextField mpgField;
|
||||||
|
private Label milesError;
|
||||||
|
private Label gallonsError;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) {
|
||||||
|
stage.setTitle("MPG Calculator");
|
||||||
|
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setAlignment(Pos.TOP_LEFT);
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
grid.setPadding(new Insets(25, 25, 25, 25));
|
||||||
|
|
||||||
|
Scene scene = new Scene(grid, 275, 175);
|
||||||
|
|
||||||
|
grid.add(new Label("Miles:"), 0, 0);
|
||||||
|
milesField = new TextField();
|
||||||
|
grid.add(milesField, 1, 0);
|
||||||
|
|
||||||
|
grid.add(new Label("Gallons:"), 0, 1);
|
||||||
|
gallonsField = new TextField();
|
||||||
|
grid.add(gallonsField, 1, 1);
|
||||||
|
|
||||||
|
grid.add(new Label("MPG:"), 0, 2);
|
||||||
|
mpgField = new TextField();
|
||||||
|
mpgField.setEditable(false);
|
||||||
|
grid.add(mpgField, 1, 2);
|
||||||
|
|
||||||
|
Button btn = new Button();
|
||||||
|
btn.setText("Calculate");
|
||||||
|
btn.setOnAction(event -> buttonClicked());
|
||||||
|
grid.add(btn, 1, 3);
|
||||||
|
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonClicked() {
|
||||||
|
Validation v = new Validation();
|
||||||
|
|
||||||
|
String errorMsg = "";
|
||||||
|
errorMsg += v.isDouble(milesField.getText(), "Miles");
|
||||||
|
errorMsg += v.isDouble(gallonsField.getText(), "Gallons");
|
||||||
|
|
||||||
|
if (errorMsg.isEmpty()) {
|
||||||
|
double miles = Double.parseDouble(milesField.getText());
|
||||||
|
double gallons = Double.parseDouble(gallonsField.getText());
|
||||||
|
double mpg = miles / gallons;
|
||||||
|
|
||||||
|
NumberFormat num = NumberFormat.getNumberInstance();
|
||||||
|
mpgField.setText( num.format(mpg) );
|
||||||
|
} else {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setHeaderText("Invalid Data");
|
||||||
|
alert.setContentText(errorMsg);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
package com.murach.future_value;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class FutureValueApplication extends Application {
|
||||||
|
private TextField investmentField;
|
||||||
|
private TextField interestRateField;
|
||||||
|
private ComboBox<Integer> yearsCombo = new ComboBox<Integer>();
|
||||||
|
private ListView futureValues = new ListView();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
primaryStage.setTitle("Future Value Calculator");
|
||||||
|
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setAlignment(Pos.TOP_CENTER);
|
||||||
|
grid.setPadding(new Insets(25, 25, 25, 25));
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
|
||||||
|
Scene scene = new Scene(grid);
|
||||||
|
|
||||||
|
grid.add(new Label("Monthly Investment:"), 0, 0);
|
||||||
|
investmentField = new TextField();
|
||||||
|
grid.add(investmentField, 1, 0);
|
||||||
|
|
||||||
|
grid.add(new Label("Yearly Interest Rate:"), 0, 1);
|
||||||
|
interestRateField = new TextField();
|
||||||
|
grid.add(interestRateField, 1, 1);
|
||||||
|
|
||||||
|
|
||||||
|
grid.add(new Label("Years:"), 0, 2);
|
||||||
|
yearsCombo.setPromptText("Select Number of Years");
|
||||||
|
for(int i = 1; i <= 20; i++) {
|
||||||
|
yearsCombo.getItems().add(i);
|
||||||
|
}
|
||||||
|
grid.add(yearsCombo, 1, 2);
|
||||||
|
|
||||||
|
HBox listViewContainer = new HBox(10);
|
||||||
|
futureValues.setPrefHeight(5*24);
|
||||||
|
listViewContainer.getChildren().add(futureValues);
|
||||||
|
grid.add(new Label("Future Value:"), 0, 3);
|
||||||
|
grid.add(listViewContainer, 1, 3);
|
||||||
|
|
||||||
|
Button calculateButton = new Button("Calculate");
|
||||||
|
calculateButton.setOnAction(event -> calculateButtonClicked());
|
||||||
|
|
||||||
|
Button exitButton = new Button("Exit");
|
||||||
|
exitButton.setOnAction(event -> exitButtonClicked());
|
||||||
|
|
||||||
|
HBox buttonBox = new HBox(10);
|
||||||
|
buttonBox.getChildren().add(calculateButton);
|
||||||
|
buttonBox.getChildren().add(exitButton);
|
||||||
|
buttonBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||||
|
grid.add(buttonBox, 0, 4, 2, 1);
|
||||||
|
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateButtonClicked() {
|
||||||
|
Validation v = new Validation();
|
||||||
|
String errorMsg = "";
|
||||||
|
int years = yearsCombo.getSelectionModel().getSelectedItem();
|
||||||
|
errorMsg += v.isDouble(investmentField.getText(),
|
||||||
|
"Monthly Investment");
|
||||||
|
errorMsg += v.isDouble(interestRateField.getText(),
|
||||||
|
"Yearly Interest Rate");
|
||||||
|
errorMsg += v.isInteger(String.valueOf(years), "Years");
|
||||||
|
|
||||||
|
if (errorMsg.isEmpty()) {
|
||||||
|
double investment = Double.parseDouble(
|
||||||
|
investmentField.getText());
|
||||||
|
double rate = Double.parseDouble(
|
||||||
|
interestRateField.getText());
|
||||||
|
|
||||||
|
NumberFormat currency = NumberFormat.getCurrencyInstance();
|
||||||
|
for(int i = 1; i <= years; i++) {
|
||||||
|
double futureValue = calculateFutureValue(
|
||||||
|
investment, rate, i);
|
||||||
|
futureValues.getItems().add(
|
||||||
|
"Year " + i + ": " + currency.format(futureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setHeaderText("Invalid Data");
|
||||||
|
alert.setContentText(errorMsg);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calculateFutureValue(double investment, double rate, int years) {
|
||||||
|
double futureValue = 0.0;
|
||||||
|
|
||||||
|
// convert yearly values to monthly values
|
||||||
|
double monthlyInterestRate = rate / 12 / 100;
|
||||||
|
int months = years * 12;
|
||||||
|
|
||||||
|
for (int i = 1; i <= months; i++) {
|
||||||
|
futureValue = (futureValue + investment)
|
||||||
|
* (1 + monthlyInterestRate);
|
||||||
|
}
|
||||||
|
return futureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitButtonClicked() {
|
||||||
|
System.exit(0); // 0 indicates a normal exit
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,102 @@
|
|||||||
|
package murach;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class App extends Application {
|
||||||
|
private TextField investmentField;
|
||||||
|
private TextField interestRateField;
|
||||||
|
private TextField yearsField;
|
||||||
|
private TextField futureValueField;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
primaryStage.setTitle("Future Value Calculator");
|
||||||
|
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setAlignment(Pos.TOP_CENTER);
|
||||||
|
grid.setPadding(new Insets(25, 25, 25, 25));
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
|
||||||
|
Scene scene = new Scene(grid);
|
||||||
|
|
||||||
|
grid.add(new Label("Monthly Investment:"), 0, 0);
|
||||||
|
investmentField = new TextField();
|
||||||
|
grid.add(investmentField, 1, 0);
|
||||||
|
|
||||||
|
grid.add(new Label("Yearly Interest Rate:"), 0, 1);
|
||||||
|
interestRateField = new TextField();
|
||||||
|
grid.add(interestRateField, 1, 1);
|
||||||
|
grid.add(new Label("Years:"), 0, 2);
|
||||||
|
yearsField = new TextField();
|
||||||
|
grid.add(yearsField, 1, 2);
|
||||||
|
|
||||||
|
grid.add(new Label("Future Value:"), 0, 3);
|
||||||
|
futureValueField = new TextField();
|
||||||
|
futureValueField.setEditable(false);
|
||||||
|
grid.add(futureValueField, 1, 3);
|
||||||
|
|
||||||
|
Button calculateButton = new Button("Calculate");
|
||||||
|
calculateButton.setOnAction(event -> calculateButtonClicked());
|
||||||
|
|
||||||
|
Button exitButton = new Button("Exit");
|
||||||
|
exitButton.setOnAction(event -> exitButtonClicked());
|
||||||
|
|
||||||
|
HBox buttonBox = new HBox(10);
|
||||||
|
buttonBox.getChildren().add(calculateButton);
|
||||||
|
buttonBox.getChildren().add(exitButton);
|
||||||
|
buttonBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||||
|
grid.add(buttonBox, 0, 4, 2, 1);
|
||||||
|
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateButtonClicked() {
|
||||||
|
// get data from text fields
|
||||||
|
double investment = Double.parseDouble(investmentField.getText());
|
||||||
|
double rate = Double.parseDouble(interestRateField.getText());
|
||||||
|
int years = Integer.parseInt(yearsField.getText());
|
||||||
|
|
||||||
|
// calculate future value
|
||||||
|
double futureValue = calculateFutureValue(investment, rate, years);
|
||||||
|
|
||||||
|
// set data in read-only text field
|
||||||
|
NumberFormat currency = NumberFormat.getCurrencyInstance();
|
||||||
|
futureValueField.setText(currency.format(futureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calculateFutureValue(double investment, double rate, int years) {
|
||||||
|
double futureValue = 0.0;
|
||||||
|
|
||||||
|
// convert yearly values to monthly values
|
||||||
|
double monthlyInterestRate = rate/12/100;
|
||||||
|
int months = years * 12;
|
||||||
|
|
||||||
|
for (int i = 1; i <= months; i++) {
|
||||||
|
futureValue = (futureValue + investment) *
|
||||||
|
(1 + monthlyInterestRate);
|
||||||
|
}
|
||||||
|
return futureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitButtonClicked() {
|
||||||
|
System.exit(0); // 0 indicates a normal exit
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
package com.murach.future_value;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class FutureValueApplication extends Application {
|
||||||
|
private TextField investmentField;
|
||||||
|
private TextField interestRateField;
|
||||||
|
private ComboBox<Integer> yearsCombo = new ComboBox<Integer>();
|
||||||
|
private ListView futureValues = new ListView();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
primaryStage.setTitle("Future Value Calculator");
|
||||||
|
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setAlignment(Pos.TOP_CENTER);
|
||||||
|
grid.setPadding(new Insets(25, 25, 25, 25));
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
|
||||||
|
Scene scene = new Scene(grid);
|
||||||
|
|
||||||
|
grid.add(new Label("Monthly Investment:"), 0, 0);
|
||||||
|
investmentField = new TextField();
|
||||||
|
grid.add(investmentField, 1, 0);
|
||||||
|
|
||||||
|
grid.add(new Label("Yearly Interest Rate:"), 0, 1);
|
||||||
|
interestRateField = new TextField();
|
||||||
|
grid.add(interestRateField, 1, 1);
|
||||||
|
|
||||||
|
|
||||||
|
grid.add(new Label("Years:"), 0, 2);
|
||||||
|
yearsCombo.setPromptText("Select Number of Years");
|
||||||
|
for(int i = 1; i <= 20; i++) {
|
||||||
|
yearsCombo.getItems().add(i);
|
||||||
|
}
|
||||||
|
grid.add(yearsCombo, 1, 2);
|
||||||
|
|
||||||
|
HBox listViewContainer = new HBox(10);
|
||||||
|
futureValues.setPrefHeight(5*24);
|
||||||
|
listViewContainer.getChildren().add(futureValues);
|
||||||
|
grid.add(new Label("Future Value:"), 0, 3);
|
||||||
|
grid.add(listViewContainer, 1, 3);
|
||||||
|
|
||||||
|
Button calculateButton = new Button("Calculate");
|
||||||
|
calculateButton.setOnAction(event -> calculateButtonClicked());
|
||||||
|
|
||||||
|
Button exitButton = new Button("Exit");
|
||||||
|
exitButton.setOnAction(event -> exitButtonClicked());
|
||||||
|
|
||||||
|
HBox buttonBox = new HBox(10);
|
||||||
|
buttonBox.getChildren().add(calculateButton);
|
||||||
|
buttonBox.getChildren().add(exitButton);
|
||||||
|
buttonBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||||
|
grid.add(buttonBox, 0, 4, 2, 1);
|
||||||
|
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateButtonClicked() {
|
||||||
|
Validation v = new Validation();
|
||||||
|
String errorMsg = "";
|
||||||
|
int years = yearsCombo.getSelectionModel().getSelectedItem();
|
||||||
|
errorMsg += v.isDouble(investmentField.getText(),
|
||||||
|
"Monthly Investment");
|
||||||
|
errorMsg += v.isDouble(interestRateField.getText(),
|
||||||
|
"Yearly Interest Rate");
|
||||||
|
errorMsg += v.isInteger(String.valueOf(years), "Years");
|
||||||
|
|
||||||
|
if (errorMsg.isEmpty()) {
|
||||||
|
double investment = Double.parseDouble(
|
||||||
|
investmentField.getText());
|
||||||
|
double rate = Double.parseDouble(
|
||||||
|
interestRateField.getText());
|
||||||
|
|
||||||
|
NumberFormat currency = NumberFormat.getCurrencyInstance();
|
||||||
|
for(int i = 1; i <= years; i++) {
|
||||||
|
double futureValue = calculateFutureValue(
|
||||||
|
investment, rate, i);
|
||||||
|
futureValues.getItems().add(
|
||||||
|
"Year " + i + ": " + currency.format(futureValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setHeaderText("Invalid Data");
|
||||||
|
alert.setContentText(errorMsg);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calculateFutureValue(double investment, double rate, int years) {
|
||||||
|
double futureValue = 0.0;
|
||||||
|
|
||||||
|
// convert yearly values to monthly values
|
||||||
|
double monthlyInterestRate = rate / 12 / 100;
|
||||||
|
int months = years * 12;
|
||||||
|
|
||||||
|
for (int i = 1; i <= months; i++) {
|
||||||
|
futureValue = (futureValue + investment)
|
||||||
|
* (1 + monthlyInterestRate);
|
||||||
|
}
|
||||||
|
return futureValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitButtonClicked() {
|
||||||
|
System.exit(0); // 0 indicates a normal exit
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package ch01_Test1;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TestApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String myName;
|
||||||
|
System.out.println("Enter your name:\n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
myName = sc.nextLine();
|
||||||
|
System.out.println(myName);
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package ch01_Test1;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TestApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String myName;
|
||||||
|
System.out.println("Enter your name:\n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
myName = sc.nextLine();
|
||||||
|
|
||||||
|
System.out.println("\n" + myName);
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
public class FutureValueApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("The Future Value Calculator\n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
String choice = "y";
|
||||||
|
while (choice.equalsIgnoreCase("y")) {
|
||||||
|
// get the input from the user
|
||||||
|
System.out.print("Enter monthly investment: ");
|
||||||
|
double monthlyInvestment = Double.parseDouble(sc.nextLine());
|
||||||
|
System.out.print("Enter yearly interest rate: ");
|
||||||
|
double interestRate = Double.parseDouble(sc.nextLine());
|
||||||
|
System.out.print("Enter number of years: ");
|
||||||
|
int years = Integer.parseInt(sc.nextLine());
|
||||||
|
|
||||||
|
// convert yearly values to monthly values
|
||||||
|
double monthlyInterestRate = interestRate / 12 / 100;
|
||||||
|
int months = years * 12;
|
||||||
|
|
||||||
|
// calculate the future value
|
||||||
|
double futureValue = 0.0;
|
||||||
|
for (int i = 1; i <= months; i++) {
|
||||||
|
futureValue = (futureValue + monthlyInvestment) *
|
||||||
|
(1 + monthlyInterestRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
// format the result and display it to the user
|
||||||
|
NumberFormat currency = NumberFormat.getCurrencyInstance();
|
||||||
|
System.out.println("Future value: "
|
||||||
|
+ currency.format(futureValue));
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
// see if the user wants to continue
|
||||||
|
System.out.print("Continue? (y/n): ");
|
||||||
|
choice = sc.nextLine();
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
System.out.println("Bye!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TestScoreApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// display operational messages
|
||||||
|
System.out.println("Enter test scores that range from 0 to 100.");
|
||||||
|
System.out.println("To exit, enter 999.");
|
||||||
|
System.out.println(); // print a blank line
|
||||||
|
|
||||||
|
// initialize variables and create a Scanner object
|
||||||
|
int scoreTotal = 0;
|
||||||
|
int scoreCount = 0;
|
||||||
|
int testScore = 0;
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
// get a series of test scores from the user
|
||||||
|
while (testScore <= 100) {
|
||||||
|
// get the input from the user
|
||||||
|
System.out.print("Enter score: ");
|
||||||
|
String input = sc.nextLine();
|
||||||
|
testScore = Integer.parseInt(input);
|
||||||
|
|
||||||
|
// accumulate score count and score total
|
||||||
|
if (testScore <= 100) {
|
||||||
|
scoreCount = scoreCount + 1;
|
||||||
|
scoreTotal = scoreTotal + testScore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// display the score count, score total, and average score
|
||||||
|
double averageScore = (double) scoreTotal / scoreCount;
|
||||||
|
String message = "\n"
|
||||||
|
+ "Score count: " + scoreCount + "\n"
|
||||||
|
+ "Score total: " + scoreTotal + "\n"
|
||||||
|
+ "Average score: " + averageScore + "\n";
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,162 @@
|
|||||||
|
package murach.signup;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.TextArea;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ScrollPane;
|
||||||
|
import javafx.scene.control.SelectionMode;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.DatePicker;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
|
||||||
|
public class SignupApp extends Application {
|
||||||
|
|
||||||
|
private TextField nameField = new TextField();
|
||||||
|
private DatePicker dobPicker = new DatePicker();
|
||||||
|
private ToggleGroup genderToggle = new ToggleGroup();
|
||||||
|
private ListView<String> genreListView = new ListView<>();
|
||||||
|
private ComboBox<String> countryCombo = new ComboBox<>();
|
||||||
|
private TextArea descriptionArea = new TextArea();
|
||||||
|
private CheckBox notifyCheckBox = new CheckBox("Receive notifications");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) {
|
||||||
|
stage.setTitle("Social Media Signup");
|
||||||
|
VBox vbox = new VBox(10);
|
||||||
|
|
||||||
|
// name
|
||||||
|
HBox nameBox = new HBox(10);
|
||||||
|
Label nameLabel = new Label("Name: ");
|
||||||
|
nameField.setMinWidth(209);
|
||||||
|
nameBox.getChildren().add(nameLabel);
|
||||||
|
nameBox.getChildren().add(nameField);
|
||||||
|
vbox.getChildren().add(nameBox);
|
||||||
|
|
||||||
|
// date of birth (DOB)
|
||||||
|
HBox dobBox = new HBox(10);
|
||||||
|
Label dobLabel = new Label("Date of Birth: ");
|
||||||
|
dobBox.getChildren().add(dobLabel);
|
||||||
|
dobBox.getChildren().add(dobPicker);
|
||||||
|
vbox.getChildren().add(dobBox);
|
||||||
|
|
||||||
|
// gender
|
||||||
|
HBox genderBox = new HBox(10);
|
||||||
|
Label genderLabel = new Label("Gender: ");
|
||||||
|
|
||||||
|
RadioButton maleButton = new RadioButton("Male");
|
||||||
|
maleButton.setToggleGroup(genderToggle);
|
||||||
|
maleButton.setSelected(true);
|
||||||
|
RadioButton femaleButton = new RadioButton("Female");
|
||||||
|
femaleButton.setToggleGroup(genderToggle);
|
||||||
|
RadioButton otherButton = new RadioButton("Other");
|
||||||
|
otherButton.setToggleGroup(genderToggle);
|
||||||
|
|
||||||
|
genderBox.getChildren().add(genderLabel);
|
||||||
|
genderBox.getChildren().add(maleButton);
|
||||||
|
genderBox.getChildren().add(femaleButton);
|
||||||
|
genderBox.getChildren().add(otherButton);
|
||||||
|
vbox.getChildren().add(genderBox);
|
||||||
|
|
||||||
|
// country
|
||||||
|
Label countryLabel = new Label("Country: ");
|
||||||
|
countryCombo.setPromptText("Select Country");
|
||||||
|
String[] countries = {"United States", "Canada", "Mexico"};
|
||||||
|
for (String country : countries) {
|
||||||
|
countryCombo.getItems().add(country);
|
||||||
|
}
|
||||||
|
vbox.getChildren().add(countryLabel);
|
||||||
|
vbox.getChildren().add(countryCombo);
|
||||||
|
|
||||||
|
// movie genres
|
||||||
|
Label movieLabel = new Label("Favorite Movie Genres: ");
|
||||||
|
genreListView.getSelectionModel()
|
||||||
|
.setSelectionMode(SelectionMode.MULTIPLE);
|
||||||
|
String[] genres = {"Action", "Comedy", "Sci-Fi", "Horror", "Drama"};
|
||||||
|
for (String genre : genres) {
|
||||||
|
genreListView.getItems().add(genre);
|
||||||
|
}
|
||||||
|
genreListView.setPrefHeight(genres.length * 24);
|
||||||
|
vbox.getChildren().add(movieLabel);
|
||||||
|
vbox.getChildren().add(genreListView);
|
||||||
|
|
||||||
|
// description
|
||||||
|
Label descriptionLabel = new Label("Profile Description: ");
|
||||||
|
descriptionArea.setPrefColumnCount(35);
|
||||||
|
descriptionArea.setPrefRowCount(4);
|
||||||
|
descriptionArea.setWrapText(true);
|
||||||
|
ScrollPane descriptionScroll = new ScrollPane(descriptionArea);
|
||||||
|
vbox.getChildren().add(descriptionLabel);
|
||||||
|
vbox.getChildren().add(descriptionScroll);
|
||||||
|
|
||||||
|
// notification
|
||||||
|
vbox.getChildren().add(notifyCheckBox);
|
||||||
|
|
||||||
|
// button
|
||||||
|
Button signUpButton = new Button("Sign Up");
|
||||||
|
signUpButton.setOnAction(event -> signUpButtonClicked());
|
||||||
|
vbox.getChildren().add(signUpButton);
|
||||||
|
|
||||||
|
vbox.setPadding(new Insets(10, 10, 0, 10));
|
||||||
|
Scene scene = new Scene(vbox, 450, 510);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void signUpButtonClicked() {
|
||||||
|
// preprocess a few controls
|
||||||
|
RadioButton selectedGender =
|
||||||
|
(RadioButton) genderToggle.getSelectedToggle();
|
||||||
|
|
||||||
|
String country = countryCombo.getSelectionModel().getSelectedItem();
|
||||||
|
|
||||||
|
String genresStr = "";
|
||||||
|
List<String> genres =
|
||||||
|
genreListView.getSelectionModel().getSelectedItems();
|
||||||
|
for(String genre : genres) {
|
||||||
|
genresStr += genre + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
String notifications;
|
||||||
|
if(notifyCheckBox.isSelected()) {
|
||||||
|
notifications = "On";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
notifications = "Off";
|
||||||
|
}
|
||||||
|
|
||||||
|
// build output string
|
||||||
|
String outputString =
|
||||||
|
"Name: " + nameField.getText() + "\n" +
|
||||||
|
"DOB: " + dobPicker.getValue() + "\n" +
|
||||||
|
"Gender: " + selectedGender.getText() + "\n" +
|
||||||
|
"Country: " + country + "\n" +
|
||||||
|
"Favorite movie genres: " + genresStr + "\n" +
|
||||||
|
"Profile description: " + descriptionArea.getText() + "\n" +
|
||||||
|
"Notifications: " + notifications + "\n";
|
||||||
|
|
||||||
|
// display output string
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
alert.setTitle("Signup Info");
|
||||||
|
alert.setHeaderText("Signup Confirmation");
|
||||||
|
alert.setContentText(outputString);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,131 @@
|
|||||||
|
package murach.ch13_ex2_pizzacalculator;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaFX App
|
||||||
|
*/
|
||||||
|
public class App extends Application {
|
||||||
|
|
||||||
|
// class globals
|
||||||
|
private ToggleGroup sizeToggle = new ToggleGroup();
|
||||||
|
private CheckBox sausageBox = new CheckBox("Sausage");
|
||||||
|
private CheckBox peppBox = new CheckBox("Pepperoni");
|
||||||
|
private CheckBox salamiBox = new CheckBox("Salami");
|
||||||
|
private CheckBox oliveBox = new CheckBox("Olives");
|
||||||
|
private CheckBox mushBox = new CheckBox("Mushrooms");
|
||||||
|
private CheckBox anchBox = new CheckBox("Anchovies");
|
||||||
|
private TextField priceField = new TextField();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) {
|
||||||
|
stage.setTitle("Pizza Price Calculcator");
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
VBox appContainer = new VBox(10);
|
||||||
|
// size
|
||||||
|
Label sizeLabel = new Label("Size");
|
||||||
|
HBox sizeBox = new HBox(10);
|
||||||
|
|
||||||
|
RadioButton smallButton = new RadioButton("Small");
|
||||||
|
smallButton.setToggleGroup(sizeToggle);
|
||||||
|
smallButton.setSelected(true);
|
||||||
|
RadioButton mediumButton = new RadioButton("Medium");
|
||||||
|
mediumButton.setToggleGroup(sizeToggle);
|
||||||
|
RadioButton largeButton = new RadioButton("Large");
|
||||||
|
largeButton.setToggleGroup(sizeToggle);
|
||||||
|
|
||||||
|
sizeBox.getChildren().add(smallButton);
|
||||||
|
sizeBox.getChildren().add(mediumButton);
|
||||||
|
sizeBox.getChildren().add(largeButton);
|
||||||
|
appContainer.getChildren().add(sizeLabel);
|
||||||
|
appContainer.getChildren().add(sizeBox);
|
||||||
|
|
||||||
|
// toppings
|
||||||
|
Label toppingsLabel = new Label("Toppings");
|
||||||
|
HBox sizeContainer = new HBox(10);
|
||||||
|
VBox sizeCol1 = new VBox(10);
|
||||||
|
VBox sizeCol2 = new VBox(10);
|
||||||
|
|
||||||
|
sizeCol1.getChildren().add(sausageBox);
|
||||||
|
sizeCol1.getChildren().add(peppBox);
|
||||||
|
sizeCol1.getChildren().add(salamiBox);
|
||||||
|
sizeCol2.getChildren().add(oliveBox);
|
||||||
|
sizeCol2.getChildren().add(mushBox);
|
||||||
|
sizeCol2.getChildren().add(anchBox);
|
||||||
|
sizeContainer.getChildren().add(sizeCol1);
|
||||||
|
sizeContainer.getChildren().add(sizeCol2);
|
||||||
|
appContainer.getChildren().add(toppingsLabel);
|
||||||
|
appContainer.getChildren().add(sizeContainer);
|
||||||
|
|
||||||
|
// price output
|
||||||
|
Label priceLabel = new Label("Price: ");
|
||||||
|
HBox priceContainer = new HBox(10);
|
||||||
|
priceField.setEditable(false);
|
||||||
|
priceContainer.getChildren().add(priceLabel);
|
||||||
|
priceContainer.getChildren().add(priceField);
|
||||||
|
appContainer.getChildren().add(priceContainer);
|
||||||
|
|
||||||
|
// calculate button
|
||||||
|
Button signUpButton = new Button("Calculate");
|
||||||
|
signUpButton.setOnAction(event -> calculatePrice(stage));
|
||||||
|
appContainer.getChildren().add(signUpButton);
|
||||||
|
|
||||||
|
grid.add(appContainer, 0, 5);
|
||||||
|
grid.setPadding(new Insets(10, 10, 0, 10));
|
||||||
|
Scene scene = new Scene(grid, 225, 250);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculatePrice(Stage stage) {
|
||||||
|
double price = 0.0;
|
||||||
|
RadioButton size =
|
||||||
|
(RadioButton) sizeToggle.getSelectedToggle();
|
||||||
|
if(size.getText() == "Small") {
|
||||||
|
price += 6.99;
|
||||||
|
} else if(size.getText() == "Medium") {
|
||||||
|
price += 8.99;
|
||||||
|
} else {
|
||||||
|
price += 10.99;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sausageBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(peppBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(salamiBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(oliveBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
if(mushBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
if(anchBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
price = (double)Math.round(price * 100.0) / 100.0;
|
||||||
|
priceField.setText("$" + price);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,130 @@
|
|||||||
|
package murach.ch13_ex2_pizzacalculator;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaFX App
|
||||||
|
*/
|
||||||
|
public class App extends Application {
|
||||||
|
|
||||||
|
// class globals
|
||||||
|
private ToggleGroup sizeToggle = new ToggleGroup();
|
||||||
|
private CheckBox sausageBox = new CheckBox("Sausage");
|
||||||
|
private CheckBox peppBox = new CheckBox("Pepperoni");
|
||||||
|
private CheckBox salamiBox = new CheckBox("Salami");
|
||||||
|
private CheckBox oliveBox = new CheckBox("Olives");
|
||||||
|
private CheckBox mushBox = new CheckBox("Mushrooms");
|
||||||
|
private CheckBox anchBox = new CheckBox("Anchovies");
|
||||||
|
private TextField priceField = new TextField();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) {
|
||||||
|
stage.setTitle("Pizza Price Calculcator");
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
VBox appContainer = new VBox(10);
|
||||||
|
// size
|
||||||
|
Label sizeLabel = new Label("Size");
|
||||||
|
HBox sizeBox = new HBox(10);
|
||||||
|
|
||||||
|
RadioButton smallButton = new RadioButton("Small");
|
||||||
|
smallButton.setToggleGroup(sizeToggle);
|
||||||
|
smallButton.setSelected(true);
|
||||||
|
RadioButton mediumButton = new RadioButton("Medium");
|
||||||
|
mediumButton.setToggleGroup(sizeToggle);
|
||||||
|
RadioButton largeButton = new RadioButton("Large");
|
||||||
|
largeButton.setToggleGroup(sizeToggle);
|
||||||
|
|
||||||
|
sizeBox.getChildren().add(smallButton);
|
||||||
|
sizeBox.getChildren().add(mediumButton);
|
||||||
|
sizeBox.getChildren().add(largeButton);
|
||||||
|
appContainer.getChildren().add(sizeLabel);
|
||||||
|
appContainer.getChildren().add(sizeBox);
|
||||||
|
|
||||||
|
// toppings
|
||||||
|
Label toppingsLabel = new Label("Toppings");
|
||||||
|
HBox sizeContainer = new HBox(10);
|
||||||
|
VBox sizeCol1 = new VBox(10);
|
||||||
|
VBox sizeCol2 = new VBox(10);
|
||||||
|
|
||||||
|
sizeCol1.getChildren().add(sausageBox);
|
||||||
|
sizeCol1.getChildren().add(peppBox);
|
||||||
|
sizeCol1.getChildren().add(salamiBox);
|
||||||
|
sizeCol2.getChildren().add(oliveBox);
|
||||||
|
sizeCol2.getChildren().add(mushBox);
|
||||||
|
sizeCol2.getChildren().add(anchBox);
|
||||||
|
sizeContainer.getChildren().add(sizeCol1);
|
||||||
|
sizeContainer.getChildren().add(sizeCol2);
|
||||||
|
appContainer.getChildren().add(toppingsLabel);
|
||||||
|
appContainer.getChildren().add(sizeContainer);
|
||||||
|
|
||||||
|
// price output
|
||||||
|
Label priceLabel = new Label("Price: ");
|
||||||
|
HBox priceContainer = new HBox(10);
|
||||||
|
priceField.setEditable(false);
|
||||||
|
priceContainer.getChildren().add(priceLabel);
|
||||||
|
priceContainer.getChildren().add(priceField);
|
||||||
|
appContainer.getChildren().add(priceContainer);
|
||||||
|
|
||||||
|
// calculate button
|
||||||
|
Button signUpButton = new Button("Calculate");
|
||||||
|
signUpButton.setOnAction(event -> calculatePrice(stage));
|
||||||
|
appContainer.getChildren().add(signUpButton);
|
||||||
|
|
||||||
|
grid.add(appContainer, 0, 5);
|
||||||
|
grid.setPadding(new Insets(10, 10, 0, 10));
|
||||||
|
Scene scene = new Scene(grid, 225, 250);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculatePrice(Stage stage) {
|
||||||
|
double price = 0.0;
|
||||||
|
RadioButton size =
|
||||||
|
(RadioButton) sizeToggle.getSelectedToggle();
|
||||||
|
if(size.getText() == "Small") {
|
||||||
|
price += 6.99;
|
||||||
|
} else if(size.getText() == "Medium") {
|
||||||
|
price += 8.99;
|
||||||
|
} else {
|
||||||
|
price += 10.99;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sausageBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(peppBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(salamiBox.isSelected()) {
|
||||||
|
price += 1.49;
|
||||||
|
}
|
||||||
|
if(oliveBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
if(mushBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
if(anchBox.isSelected()) {
|
||||||
|
price += 0.99;
|
||||||
|
}
|
||||||
|
price = (double)Math.round(price * 100.0) / 100.0;
|
||||||
|
priceField.setText("$" + price);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
public class InvoiceApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final double DISCOUNT_PCT = .05;
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
String choice = "y";
|
||||||
|
while (choice.equalsIgnoreCase("y")) {
|
||||||
|
System.out.print("Enter subtotal: ");
|
||||||
|
String input = sc.nextLine();
|
||||||
|
double subtotal = Double.parseDouble(input);
|
||||||
|
System.out.println(); // print blank line
|
||||||
|
|
||||||
|
// calculate the results
|
||||||
|
double discountAmount = subtotal * DISCOUNT_PCT;
|
||||||
|
discountAmount = (double) Math.round(discountAmount * 100) / 100;
|
||||||
|
double total = subtotal - discountAmount;
|
||||||
|
|
||||||
|
// format and display the discount percent
|
||||||
|
NumberFormat percent = NumberFormat.getPercentInstance();
|
||||||
|
System.out.printf("%-20s%12s%n",
|
||||||
|
"Discount percent:", percent.format(DISCOUNT_PCT));
|
||||||
|
|
||||||
|
// a debugging statement that has been commented out
|
||||||
|
/*
|
||||||
|
System.out.println("UNFORMATTED RESULTS\n"
|
||||||
|
+ "Subtotal: " + subtotal + "\n"
|
||||||
|
+ "Discount amount: " + discountAmount + "\n"
|
||||||
|
+ "Invoice total: " + total + "\n"
|
||||||
|
+ "FORMATTED RESULTS");
|
||||||
|
*/
|
||||||
|
|
||||||
|
// format and display the floating-point numbers
|
||||||
|
String format = "%-20s%,12.2f%n";
|
||||||
|
System.out.printf(format, "Subtotal:", subtotal);
|
||||||
|
System.out.printf(format, "Discount amount:", discountAmount);
|
||||||
|
System.out.printf(format, "Invoice total:", total);
|
||||||
|
System.out.println(); // print blank line
|
||||||
|
|
||||||
|
System.out.print("Continue? (y/n): ");
|
||||||
|
choice = sc.nextLine();
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package ch01_Test1;
|
||||||
|
|
||||||
|
public class TestApp {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package ch01_Test1;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TestApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String myName;
|
||||||
|
System.out.println("Enter your name:\n");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
myName = sc.nextLine();
|
||||||
|
System.out.println("\n" + "Welcome to the Test App, " + myName);
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user