From aa37ae1eecc3c35a6893c230adac431c1c4fad5b Mon Sep 17 00:00:00 2001 From: gabriel venberg Date: Fri, 26 Mar 2021 22:45:38 -0500 Subject: [PATCH] inital commit --- .gitignore | 45 ++ LICENCE.md | 621 +++++++++++++++++++++ Lab09/src/Date.java | 113 ++++ Lab09/src/DateTest.java | 41 ++ Lab09/src/Loan.java | 120 ++++ Lab09/src/LoanTest.java | 82 +++ Lab09/src/Stock.java | 90 +++ Lab09/src/StockTest.java | 33 ++ README.md | 6 + home02/src/Average.java | 38 ++ home02/src/InchesToFeetInches.java | 43 ++ home03/src/Investment.java | 54 ++ home03/src/points.java | 62 ++ home06/src/Stack.java | 97 ++++ home06/src/StackTest.java | 68 +++ home07/src/BasePlusCommissionEmployee.java | 54 ++ home07/src/CommissionEmployee.java | 86 +++ home07/src/Employee.java | 52 ++ home07/src/EmployeesClient.java | 54 ++ home07/src/HourlyEmployee.java | 69 +++ home07/src/SalariedEmployee.java | 53 ++ homeAssignment05/src/Date.java | 113 ++++ homeAssignment05/src/Employee.java | 132 +++++ homeAssignment05/src/EmployeeTest.java | 41 ++ lab01/src/helloworld.java | 33 ++ lab02/src/Weight.java | 50 ++ lab03/nbproject/private/jshell.history | 0 lab03/src/circleCalc.java | 23 + lab03/src/tempConversion.java | 51 ++ lab03/src/timeCalc.java | 45 ++ lab04/src/milesConversion.java | 45 ++ lab04/src/quartsToGallons.java | 41 ++ lab05/src/BankAccount.java | 65 +++ lab05/src/BankAccountTest.java | 44 ++ lab05/src/StringTest.java | 51 ++ lab06/src/DigitAddition.java | 51 ++ lab06/src/Morgage.java | 71 +++ lab06/src/Payroll.java | 78 +++ lab07/src/LeapYear.java | 47 ++ lab07/src/Seasons.java | 54 ++ lab07/src/Triangle.java | 61 ++ lab08/grades.txt | 19 + lab08/src/Grades.java | 77 +++ lab08/src/HiLo.java | 79 +++ lab08/src/RockPaperSissors.java | 102 ++++ lab10/dist/javadoc/element-list | 1 + lab10/src/Course.java | 69 +++ lab10/src/NFLstats.java | 85 +++ lab10/src/Student.java | 132 +++++ lab10/src/StudentTest.java | 35 ++ lab10/stats.txt | 18 + lab11/src/Passenger.java | 67 +++ lab11/src/Train.java | 114 ++++ lab11/src/TrainTest.java | 58 ++ lab11/src/salesTax.java | 94 ++++ 55 files changed, 3927 insertions(+) create mode 100644 .gitignore create mode 100644 LICENCE.md create mode 100644 Lab09/src/Date.java create mode 100644 Lab09/src/DateTest.java create mode 100644 Lab09/src/Loan.java create mode 100644 Lab09/src/LoanTest.java create mode 100644 Lab09/src/Stock.java create mode 100644 Lab09/src/StockTest.java create mode 100644 README.md create mode 100644 home02/src/Average.java create mode 100644 home02/src/InchesToFeetInches.java create mode 100644 home03/src/Investment.java create mode 100644 home03/src/points.java create mode 100644 home06/src/Stack.java create mode 100644 home06/src/StackTest.java create mode 100644 home07/src/BasePlusCommissionEmployee.java create mode 100644 home07/src/CommissionEmployee.java create mode 100644 home07/src/Employee.java create mode 100644 home07/src/EmployeesClient.java create mode 100644 home07/src/HourlyEmployee.java create mode 100644 home07/src/SalariedEmployee.java create mode 100644 homeAssignment05/src/Date.java create mode 100644 homeAssignment05/src/Employee.java create mode 100644 homeAssignment05/src/EmployeeTest.java create mode 100644 lab01/src/helloworld.java create mode 100644 lab02/src/Weight.java create mode 100644 lab03/nbproject/private/jshell.history create mode 100644 lab03/src/circleCalc.java create mode 100644 lab03/src/tempConversion.java create mode 100644 lab03/src/timeCalc.java create mode 100644 lab04/src/milesConversion.java create mode 100644 lab04/src/quartsToGallons.java create mode 100644 lab05/src/BankAccount.java create mode 100644 lab05/src/BankAccountTest.java create mode 100644 lab05/src/StringTest.java create mode 100644 lab06/src/DigitAddition.java create mode 100644 lab06/src/Morgage.java create mode 100644 lab06/src/Payroll.java create mode 100644 lab07/src/LeapYear.java create mode 100644 lab07/src/Seasons.java create mode 100644 lab07/src/Triangle.java create mode 100644 lab08/grades.txt create mode 100644 lab08/src/Grades.java create mode 100644 lab08/src/HiLo.java create mode 100644 lab08/src/RockPaperSissors.java create mode 100644 lab10/dist/javadoc/element-list create mode 100644 lab10/src/Course.java create mode 100644 lab10/src/NFLstats.java create mode 100644 lab10/src/Student.java create mode 100644 lab10/src/StudentTest.java create mode 100644 lab10/stats.txt create mode 100644 lab11/src/Passenger.java create mode 100644 lab11/src/Train.java create mode 100644 lab11/src/TrainTest.java create mode 100644 lab11/src/salesTax.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d51ce2b --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# Created by https://www.toptal.com/developers/gitignore/api/java +# Edit at https://www.toptal.com/developers/gitignore?templates=java + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# End of https://www.toptal.com/developers/gitignore/api/java + +#uploading only code, not compile settings. +*.xml +*.properties +*.html +*.js +*.css +*.png +*.mf +*.TXT +*.netbeans* + + +#word docs for assignment submission (I have no clue why our professor insited on copying and pasting source code into *word docs*. +*.docx +*.doc diff --git a/LICENCE.md b/LICENCE.md new file mode 100644 index 0000000..701a3f1 --- /dev/null +++ b/LICENCE.md @@ -0,0 +1,621 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you dstribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS diff --git a/Lab09/src/Date.java b/Lab09/src/Date.java new file mode 100644 index 0000000..04c829f --- /dev/null +++ b/Lab09/src/Date.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.GregorianCalendar; +import java.util.Calendar; +public class Date { + private int day, month, year; + + public Date (int startDay, int startMonth, int startYear){ + setYear(startYear); + setMonth(startMonth); + setDay(startDay); + } + /** + * returns day + * @return + */ + public int getDay(){ + return day; + } + /** + * returns month + * @return + */ + public int getMonth(){ + return month; + } + /** + * returns year + * @return + */ + public int getYear(){ + return year; + } + + /** + * sets the day, throws error if day is impossible under the gregorian calander. + * @param newDay + */ + private void setDay(int newDay){ + GregorianCalendar checker = new GregorianCalendar(year, month, day); + //found in javadoc for gregoriancalander. will also take into account leap years. + int daysInMonth = checker.getActualMaximum(Calendar.DAY_OF_MONTH); + + if (newDay<=daysInMonth){ + day=newDay; + } + else { + throw new IllegalArgumentException("newDay out of range for set month and year"); + } + } + /** + * sets month, throws error if month is above 12. + * @param newMonth + */ + private void setMonth(int newMonth){ + if (newMonth<=12){ + month=newMonth; + } + else { + throw new IllegalArgumentException("newMonth must be <= 12"); + } + } + /** + * sets year, returns error if year is before 1582 + * @param newYear + */ + private void setYear(int newYear){ + if (newYear>=1582){ + year=newYear; + } + else { + throw new IllegalArgumentException("newYear must be >= 1582, the year the gregorian calander was adopted."); + } + } + + /** + * outputs a string representation of the date in mm/dd/yyyy format. + * @return + */ + public String toString(){ + return (month+"/"+day+"/"+year); + } + + /** + * tests if date obgect is equal to another date object. + * @param testDate + * @return + */ + public boolean equals(Date testDate){ + return testDate.getDay()==day&testDate.getMonth()==month&testDate.getYear()==year; + } + + +} diff --git a/Lab09/src/DateTest.java b/Lab09/src/DateTest.java new file mode 100644 index 0000000..a6cb9dc --- /dev/null +++ b/Lab09/src/DateTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.Scanner; + +public class DateTest { + public static void main(String[] args){ + Scanner scan = new Scanner(System.in); + int day, month, year; + + System.out.print("input a year >"); + year = scan.nextInt(); + System.out.print("input a month >"); + month = scan.nextInt(); + System.out.println("input a day >"); + day = scan.nextInt(); + + Date test = new Date(day, month, year); + + System.out.println("The date You entered is "+test.toString()); + + } +} diff --git a/Lab09/src/Loan.java b/Lab09/src/Loan.java new file mode 100644 index 0000000..ade9ed1 --- /dev/null +++ b/Lab09/src/Loan.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class Loan { + private double interestRate; + private double amount; + private int years; + private Date date; + + public Loan(double startInterestRate, double startAmount, int startYears, Date startDate){ + setInterestRate(startInterestRate); + setAmount(startAmount); + setYears(startYears); + date=startDate; + } + /** + * returns interestRate + * @return + */ + public double getInterestRate(){ + return interestRate; + } + /** + * returns amount + * @return + */ + public double getAmount(){ + return amount; + } + /** + * returns years + * @return + */ + public double getYears(){ + return years; + } + /** + * returns a string representing date. + * @return + */ + public String getDate(){ + return date.toString(); + } + /** + * sets interest rate, making sure its not negative. + * @param newInterestRate + */ + private void setInterestRate(double newInterestRate){ + if (newInterestRate >=0){ + interestRate=newInterestRate; + } + else{ + throw new IllegalArgumentException("Interest must be >= 0"); + } + } + /** + * sets amount, making sure its not negative. + * @param newAmount + */ + private void setAmount(double newAmount){ + if (newAmount >=0){ + amount=newAmount; + } + else{ + throw new IllegalArgumentException("Amount must be >= 0"); + } + } + /** + * sets years, making sure its at least 1. + * @param newYears + */ + private void setYears(int newYears){ + if (newYears >0){ + years=newYears; + } + else{ + throw new IllegalArgumentException("years must be > 0"); + } + } + /** + * returns the monthly payment, assuming interest stays static throuought the rest of the loans term. + * @return + */ + public double getMonthlyPayment(){ + return (((interestRate/12)*amount)/(1-(1/Math.pow((1+(interestRate/12)),(years*12))))); + } + /** + * returns the total payment made throuhought the life of the loan. + * @return + */ + public double getTotalPayment(){ + return getMonthlyPayment()*12*years; + } + /** + * returns the total amount paid over the amount initally borrowed. + * @return + */ + public double getOverpayment(){ + return getTotalPayment()-amount; + } + +} diff --git a/Lab09/src/LoanTest.java b/Lab09/src/LoanTest.java new file mode 100644 index 0000000..00d2e15 --- /dev/null +++ b/Lab09/src/LoanTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.Scanner; +import java.text.NumberFormat; +import java.text.DecimalFormat; +public class LoanTest { + public static void main(String[] args){ + //setup + NumberFormat percentFormat = NumberFormat.getPercentInstance(); + NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(); + Scanner scan = new Scanner(System.in); + double interestRate, amount; + int years; + int year, month, day; + boolean wantsToContinue = true; + char tempInput; + + while (wantsToContinue){ + //getting input + System.out.print("intput the annual interest rate as a decimal >"); + interestRate = scan.nextDouble(); + System.out.print("input the number of years the loan will be held >"); + years = scan.nextInt(); + System.out.print("input the amount borrowed >"); + amount = scan.nextDouble(); + System.out.print("input the year >"); + year = scan.nextInt(); + System.out.print("input the month >"); + month = scan.nextInt(); + System.out.print("input the day >"); + day = scan.nextInt(); + + Date loanDate = new Date(day, month, year); + Loan testLoan = new Loan(interestRate, amount, years, loanDate); + + //some minor calculation in order to keep the line from getting too long. + double overpaymentPercent = testLoan.getOverpayment()/testLoan.getTotalPayment(); + + System.out.println("SUCSESS!"); + System.out.println("Loan created."); + System.out.println("You have sucsessfully signed up for a loan!"); + System.out.println("You have an interest rate of "+percentFormat.format(testLoan.getInterestRate())); + System.out.println("You borrowed"+moneyFormat.format(testLoan.getAmount())); + System.out.println("You will be paying us "+moneyFormat.format(testLoan.getMonthlyPayment())+" a month for "+years+" years."); + System.out.println("Even assuming you pay on time every month, by the end of the loan you will have paid us "+moneyFormat.format(testLoan.getTotalPayment())+","); + System.out.println(moneyFormat.format(testLoan.getOverpayment())+" of whitch will be pure profit for us!"); + System.out.println("That is, you will have paid "+percentFormat.format(overpaymentPercent)+" more than you initaly borrowed!"); + System.out.println("Isnt capitalism great!"); + System.out.println("Press y to register for another loan."); + tempInput = scan.next().charAt(0); + + switch(tempInput) { + case 'y': + wantsToContinue = true; + break; + default: + wantsToContinue = false; + break; + + } + } + } +} diff --git a/Lab09/src/Stock.java b/Lab09/src/Stock.java new file mode 100644 index 0000000..b7cc8a9 --- /dev/null +++ b/Lab09/src/Stock.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *Stock class + * @author toric + */ +public class Stock { + private String symbol; + private String name; + private double previousClosingPrice; + private double currentPrice; + + /** + * constructor that assigns symbol and name. + * no blank constructor, as symbol and name do not have assignment methods. + * @param startSymbol + * @param startName + */ + public Stock(String startSymbol, String startName){ + symbol=startSymbol; + name=startName; + } + + /** + * returns symbol + * @return + */ + public String getSymbol(){ + return symbol; + } + /** + * returns name + * @return + */ + public String getName(){ + return name; + } + /** + * returns previousClosingPrice + * @return + */ + public double getPreviousClosingPrice(){ + return previousClosingPrice; + } + /** + * returns currentPrice + * @return + */ + public double getCurrentPrice(){ + return currentPrice; + } + + /** + * sets previousClosingPrice + * @param newPreviousClosingPrice + */ + public void setPreviousClosingPrice(double newPreviousClosingPrice){ + previousClosingPrice=newPreviousClosingPrice; + } + /** + * sets currentPrice + * @param newCurrentPrice + */ + public void setCurrentPrice(double newCurrentPrice){ + currentPrice=newCurrentPrice; + } + + /** + * returns the percentage change between the previousClosingPrice and the currentPrice. + * @return + */ + public double changePercent(){ + return ((currentPrice-previousClosingPrice)/previousClosingPrice)*100; + } +} diff --git a/Lab09/src/StockTest.java b/Lab09/src/StockTest.java new file mode 100644 index 0000000..042197d --- /dev/null +++ b/Lab09/src/StockTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class StockTest { + public static void main(String[] args){ + Stock mmm = new Stock("MMM","3M"); + //set monetary values + mmm.setPreviousClosingPrice(165.51); + mmm.setCurrentPrice(150); + //print info. + System.out.println("Yesterdays closing price for "+mmm.getName()+" was "+mmm.getPreviousClosingPrice()+"."); + System.out.println("The current price for "+mmm.getName()+" is "+mmm.getCurrentPrice()+"."); + System.out.println(mmm.getName()+" has changed by "+mmm.changePercent()+"%."); + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..499a4bf --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# CS1 java projects + +This repository is simply a record of the projects I did for my Computer Science 1 class. +As I didnt come up with the bright idea to put this in a git repository until after im halfway through Computer Science 2, the initial commit will be the only commit. + +Feel free to look around, but keep in mind I was utterly unfamiliar with java at the time, and we were not allowed to 'read ahead' and use java classes we had not learned about yet. diff --git a/home02/src/Average.java b/home02/src/Average.java new file mode 100644 index 0000000..6538314 --- /dev/null +++ b/home02/src/Average.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class Average { + public static void main(String[] arg){ + + //declare input + int in1 = 1; + int in2 = 7; + int in3 = 9; + int in4 = 34; + int noOfInputs = 4; + + //calculate + double avg = (double)(in1+in2+in3+in4)/noOfInputs; + + //output + System.out.println("the average of the inputs is "+avg); + } +} diff --git a/home02/src/InchesToFeetInches.java b/home02/src/InchesToFeetInches.java new file mode 100644 index 0000000..f2c630e --- /dev/null +++ b/home02/src/InchesToFeetInches.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class InchesToFeetInches { + public static void main(String[] args){ + + //declare input + int inputInches = 100; + + //declare constants + final int inchesInFoot = 12; + + //declare variables + int outputFeet; + int outputInches; + + //compute + outputFeet = inputInches/inchesInFoot; + outputInches = inputInches%inchesInFoot; + + //output + System.out.println(inputInches+" inches is equal to "+outputFeet+" feet, "+outputInches+" inches."); + + } +} diff --git a/home03/src/Investment.java b/home03/src/Investment.java new file mode 100644 index 0000000..15c29c8 --- /dev/null +++ b/home03/src/Investment.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *inputs an inital investment and a percent intrest, and calculates balance after 5, 10, and 15 years. + * @author toric + */ +import java.util.Scanner; +import java.text.NumberFormat; +public class Investment { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + NumberFormat priceFormat = NumberFormat.getCurrencyInstance(); + + //get input + System.out.print("Enter your intrest rate as a decimal (6.5% - .065) >"); + double intrest = scan.nextDouble(); + System.out.print("enter your inital investment >"); + double investment = scan.nextDouble(); + //could easily get this from a user input as well... + int year; + + //calculate 5 years + year = 5; + double year5Value = investment*Math.pow(1+intrest, year); + + //calculate 10 years + year = 10; + double year10Value = investment*Math.pow(1+intrest, year); + + //calculate 20 years + year = 20; + double year20Value = investment*Math.pow(1+intrest, year); + + //print the values. + System.out.println("After 5 years, you will have "+priceFormat.format(year5Value)); + System.out.println("After 10 years, you will have "+priceFormat.format(year10Value)); + System.out.println("After 20 years, you will have "+priceFormat.format(year20Value)); + } +} diff --git a/home03/src/points.java b/home03/src/points.java new file mode 100644 index 0000000..f2aaf84 --- /dev/null +++ b/home03/src/points.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.Scanner; +import java.awt.Point; +public class points { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + /*gathering the input. Should really use some string processing in order to have the use input be comma seperated values, + but the spec doesnt reqire it, and havent done mutch string processing in java yet.. + */ + System.out.println("Enter the x cordinate for the first point >"); + int x1 = scan.nextInt(); + System.out.println("Enter the y cordinate for the first point >"); + int y1 = scan.nextInt(); + System.out.println("Enter the x cordinate for the second point >"); + int x2 = scan.nextInt(); + System.out.println("Enter the y cordinate for the second point >"); + int y2 = scan.nextInt(); + + //take our x and y numbers and turn them into point objects. + Point p1 = new Point(x1,y1); + Point p2 = new Point(x2,y2); + + /*outputing our inital values. a quote from the java 14 docs: + Returns a string representation of this point and its location in the (x,y) coordinate space. + This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. + The returned string may be empty but may not be null. + This is why it returns stuff like java.awt.point[x=3, y=12] + If we want a clean output, we should use getX and getY individually. + */ + System.out.println("The first point is at "+p1.toString()); + System.out.println("The second point is at "+p2.toString()); + + //apply our changes + p1.translate(5, 10); + p2.move(15, 20); + + //output our new values. + System.out.println("The first point is now at "+p1.toString()); + System.out.println("The second point is now at "+p2.toString()); + } +} diff --git a/home06/src/Stack.java b/home06/src/Stack.java new file mode 100644 index 0000000..0e361fd --- /dev/null +++ b/home06/src/Stack.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class Stack { + private int [] list; + private int count; + + public Stack () { + list = new int [5]; + count=0; + } + + public Stack (int [] startList){ + list = new int [startList.length]; + for (int i=0; i=list.length;} //still dont need if. + + private void addCapacity(){ + int [] temp = new int [list.length*2]; //new array + + for (int i=0; i. + */ + +/** + * + * @author toric + */ +import java.lang.Math; +public class StackTest { + public static void main(String[] args){ + int [] testArray = new int [10]; + + for (int i=0; i. + */ + +/** + * + * @author toric + */ +public class BasePlusCommissionEmployee extends CommissionEmployee{ + public double baseSalary; + + public BasePlusCommissionEmployee(String startFirstName, String startLastName, int startSSN, double startGrossSales, double startCommissionRate, double startBaseSalary){ + //we simply set minWage as baseSalary (or something lower, but it doesnt matter), as we wont run into that problem with this type of employee. + super(startFirstName, startLastName, startSSN, startGrossSales, startCommissionRate, startBaseSalary); + setBaseSalary(startBaseSalary); + } + + public double getBaseSalary(){return baseSalary;} + + public void setBaseSalary(double newBaseSalary){ + if (newBaseSalary > 0){ + baseSalary = newBaseSalary; + } + else{ + throw new IllegalArgumentException("Base salary must be > 0"); + } + } + + public String toString(){ + return super.toString()+", Min wage same as base salary"; + } + + public boolean equals(BasePlusCommissionEmployee testEmployee){ + //dont actually need to test baseSalary, as it is set equal to minWage. + return super.equals(testEmployee); + } + + public double getEarnings(){ + return this.getCommissionRate()*this.getGrossSales()+baseSalary; + } +} diff --git a/home07/src/CommissionEmployee.java b/home07/src/CommissionEmployee.java new file mode 100644 index 0000000..fc6c77e --- /dev/null +++ b/home07/src/CommissionEmployee.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +/*going a bit above on this one. +in the US and europe (any country with a minimum wage), even commissioned employees are gaurenteed a minimum wage +no matter how little they sell on a given week. I will be implementing sutch a system. +Note this is different from a base+commission because it uses a floor, rather than an addition. +in the US, Every employee that recives commission must also recive a base pay, actually. The only weird thing is that the min base pay for tipped employees is lower. +But they still get a base pay. (The more you know!) +*/ +public class CommissionEmployee extends Employee{ + + private double grossSales; + private double commissionRate; + private double minWage; + + public CommissionEmployee(String startFirstName, String startLastName, int startSSN, double startGrossSales, double startCommissionRate, double startMinWage){ + super(startFirstName, startLastName, startSSN); + setGrossSales(startGrossSales); + setCommissionRate(startCommissionRate); + setMinWage(startMinWage); + } + + public double getGrossSales(){return grossSales;} + public double getCommissionRate(){return commissionRate;} + public double getMinWage(){return minWage;} + + public void setGrossSales(double newGrossSales){ + if (newGrossSales >= 0){ + grossSales = newGrossSales; + } + else{ + throw new IllegalArgumentException("grossSales cannot be negative"); + } + } + + public void setCommissionRate(double newCommissionRate){ + if (newCommissionRate > 0){ + commissionRate = newCommissionRate; + } + else{ + throw new IllegalArgumentException("commissionRate must be >0"); + } + } + + public void setMinWage(double newMinWage){ + if (newMinWage > 0){ + minWage = newMinWage; + } + else{ + throw new IllegalArgumentException("minWage must be > 0, and, legaly speaking, above or equal to your local minimum wage"); + } + } + + public String toString(){ + return super.toString()+", Gross sales: $"+grossSales+", commissionRate: "+commissionRate+"%, minimum wage: $"+minWage; + } + + public boolean equals(CommissionEmployee testEmployee){ + return super.equals(testEmployee) && grossSales == testEmployee.getGrossSales() && commissionRate == testEmployee.getCommissionRate() + && minWage == testEmployee.getMinWage(); + } + + public double getEarnings(){ + return Math.max(minWage, (grossSales*commissionRate)); + } + +} diff --git a/home07/src/Employee.java b/home07/src/Employee.java new file mode 100644 index 0000000..91a1f0f --- /dev/null +++ b/home07/src/Employee.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public abstract class Employee { + private String firstName; + private String lastName; + private int SSN; + + public Employee(String startFirstName, String startLastName, int startSSN){ + firstName = startFirstName; + lastName=startLastName; + SSN = startSSN; + } + + public String getFirstName(){return firstName;} + public String getLastName(){return lastName;} + public int getSSN(){return SSN;} + + public void setFirstName(String newFirstName){firstName = newFirstName;} + public void setLastName(String newLastName){lastName = newLastName;} + /*SSN's dont change, names do. But you told me to implement this. Im not sure why, and am actually quite curious to know. + * Did you intend the set method to be public? Am I supposed to be calling the set methods in the constructor (dispite the data not needing validation)? + */ + private void setSSN(int newSSN){SSN = newSSN;} + + public abstract double getEarnings(); + + public String toString(){ + return lastName+", "+firstName+", SSN: "+SSN; + } + public boolean equals(Employee testEmployee){ + return firstName == testEmployee.getFirstName() && lastName == testEmployee.getLastName() && SSN == testEmployee.getSSN(); + } +} diff --git a/home07/src/EmployeesClient.java b/home07/src/EmployeesClient.java new file mode 100644 index 0000000..a409fdd --- /dev/null +++ b/home07/src/EmployeesClient.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.ArrayList; + +public class EmployeesClient { + public static ArrayList GenerateEmployees(){ + ArrayList employeeList = new ArrayList(); + int empType; + for (int i=0; i<10; i++){ + empType = (int)(Math.random()*4); + //the random numbers are a bit of a mess, I should really write a random number method. + switch(empType){ + case 0: + employeeList.add(new SalariedEmployee("Clone"+(i+1), "Venberg", (int)Math.random()*900000000+100000000, Math.random()*2701+300)); + break; + case 1: + employeeList.add(new HourlyEmployee("Clone"+i, "Venberg", (int)Math.random()*900000000+100000000, Math.random()*41+10, Math.random()*51+10)); + break; + case 2: + employeeList.add(new CommissionEmployee("Clone"+i, "Venberg", (int)Math.random()*900000000+100000000, Math.random()*10000, Math.random()*.1, Math.random()*701+300)); + break; + case 3: + employeeList.add(new BasePlusCommissionEmployee("Clone"+i, "Venberg", (int)Math.random()*900000000+100000000, Math.random()*10000, Math.random()*.1, Math.random()*2701+300)); + break; + } + } + return employeeList; + } + public static void main(String[] args){ + ArrayList employeeList = GenerateEmployees(); + for (int i=0; i. + */ + +/** + * + * @author toric + */ +public class HourlyEmployee extends Employee{ + private double wage; + private double hours; + + public HourlyEmployee(String startFirstName, String startLastName, int startSSN, double startWage, double startHours){ + super(startFirstName, startLastName, startSSN); + setWage(startWage); + setHours(startHours); + } + + public double getWage(){return wage;} + public double getHours(){return hours;} + + public void setWage(double newWage){ + if (newWage > 0){ + wage = newWage; + } + else{ + throw new IllegalArgumentException("Wage must be > 0"); + } + } + + public void setHours(double newHours){ + if (newHours > 0){ + hours = newHours; + } + else{ + throw new IllegalArgumentException("Hours must be > 0"); + } + } + + public String toString(){ + return super.toString()+", Hourly Wage: $"+wage+"/hr, Weekly Hours: "+hours; + } + + public boolean equals(HourlyEmployee testEmployee){ + return super.equals(testEmployee) && hours == testEmployee.getHours() && wage == testEmployee.getWage(); + } + + public double getEarnings(){ + if (hours > 40){ + return 40*wage+(hours-40)*wage; + } + else{ + return hours*wage; + } + } +} diff --git a/home07/src/SalariedEmployee.java b/home07/src/SalariedEmployee.java new file mode 100644 index 0000000..7aa1601 --- /dev/null +++ b/home07/src/SalariedEmployee.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class SalariedEmployee extends Employee{ + private double weeklySalary; + + public SalariedEmployee(String startFirstName, String startLastName, int startSSN, double startWeeklySalary){ + super(startFirstName, startLastName, startSSN); + setWeeklySalary(startWeeklySalary); + } + + public double getWeeklySalary(){return weeklySalary;} + + public void setWeeklySalary(double newWeeklySalary){ + if (newWeeklySalary > 0){ + weeklySalary = newWeeklySalary; + } + else{ + throw new IllegalArgumentException("Salary must be > 0"); + } + } + + public String toString(){ + return super.toString()+", Weekly Salary: $"+weeklySalary; + } + + public boolean equals(SalariedEmployee testEmployee){ + return super.equals(testEmployee) && weeklySalary == testEmployee.getWeeklySalary(); + } + + //Im assuming you want getEarnings to return weekly earnings. + public double getEarnings(){ + return weeklySalary; + } +} diff --git a/homeAssignment05/src/Date.java b/homeAssignment05/src/Date.java new file mode 100644 index 0000000..04c829f --- /dev/null +++ b/homeAssignment05/src/Date.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.GregorianCalendar; +import java.util.Calendar; +public class Date { + private int day, month, year; + + public Date (int startDay, int startMonth, int startYear){ + setYear(startYear); + setMonth(startMonth); + setDay(startDay); + } + /** + * returns day + * @return + */ + public int getDay(){ + return day; + } + /** + * returns month + * @return + */ + public int getMonth(){ + return month; + } + /** + * returns year + * @return + */ + public int getYear(){ + return year; + } + + /** + * sets the day, throws error if day is impossible under the gregorian calander. + * @param newDay + */ + private void setDay(int newDay){ + GregorianCalendar checker = new GregorianCalendar(year, month, day); + //found in javadoc for gregoriancalander. will also take into account leap years. + int daysInMonth = checker.getActualMaximum(Calendar.DAY_OF_MONTH); + + if (newDay<=daysInMonth){ + day=newDay; + } + else { + throw new IllegalArgumentException("newDay out of range for set month and year"); + } + } + /** + * sets month, throws error if month is above 12. + * @param newMonth + */ + private void setMonth(int newMonth){ + if (newMonth<=12){ + month=newMonth; + } + else { + throw new IllegalArgumentException("newMonth must be <= 12"); + } + } + /** + * sets year, returns error if year is before 1582 + * @param newYear + */ + private void setYear(int newYear){ + if (newYear>=1582){ + year=newYear; + } + else { + throw new IllegalArgumentException("newYear must be >= 1582, the year the gregorian calander was adopted."); + } + } + + /** + * outputs a string representation of the date in mm/dd/yyyy format. + * @return + */ + public String toString(){ + return (month+"/"+day+"/"+year); + } + + /** + * tests if date obgect is equal to another date object. + * @param testDate + * @return + */ + public boolean equals(Date testDate){ + return testDate.getDay()==day&testDate.getMonth()==month&testDate.getYear()==year; + } + + +} diff --git a/homeAssignment05/src/Employee.java b/homeAssignment05/src/Employee.java new file mode 100644 index 0000000..5a44c46 --- /dev/null +++ b/homeAssignment05/src/Employee.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class Employee { + private int emplID; + private static int nextID = 1000; + private static int noOfEmployees = 0; + private String firstName; + private String lastName; + private Date birthDate; + private Date hireDate; + + /** + * Constructor that assigns full name, birthdate, hiredate, as well as automatically assigning an ID. + * @param startFirstName + * @param startLastName + * @param startBirthDate + * @param startHireDate + */ + public Employee(String startFirstName, String startLastName, Date startBirthDate, Date startHireDate){ + setFirstName(startFirstName); // what does overridable method call in constructor mean? + setLastName(startLastName); + setBirthDate(startBirthDate); + setHireDate(startHireDate); + emplID=nextID; + nextID++; + noOfEmployees++; + } + + //normally would go multiline, but get methods are so formulaic and short its just as readable on one line. + /** + * returns emplID + * @return + */ + public int getemplID(){return emplID;} + /** + * returns firstName + * @return + */ + public String getFirstName(){return firstName;} + /** + * returns lastName + * @return + */ + public String getLastName(){return lastName;} + /** + * returns birthDate + * @return + */ + public Date getBirthDate(){return birthDate;} + /** + * returns hireDate + * @return + */ + public Date getHireDate(){return hireDate;} + + //names change, so they are public. + /** + * sets firstName + * @param newFirstName + */ + public void setFirstName(String newFirstName){ + firstName=newFirstName; + } + /** + * sets lastName + * @param newLastName + */ + public void setLastName(String newLastName){ + lastName=newLastName; + } + + //birth dates and hire dates dont change, so these are private. + /** + * sets birthDate + * @param newBirthDate + */ + private void setBirthDate(Date newBirthDate) { + birthDate=newBirthDate; + } + /** + * sets hireDate + * @param newHireDate + */ + private void setHireDate(Date newHireDate){ + hireDate=newHireDate; + } + /** + * tests if all values are equal to another instance of Employee + * @param testEmployee + * @return + */ + public boolean equals(Employee testEmployee){ + return testEmployee.getFirstName().equals(firstName)&testEmployee.getLastName().equals(lastName)& //multiline for readability. if statements would be slower, I think. + testEmployee.getBirthDate().equals(birthDate)&testEmployee.getHireDate().equals(hireDate)& + testEmployee.getemplID()==emplID; + } + /** + * returns a human readable string representing Employee. + * @return + */ + public String toString(){ + return (firstName+" "+lastName+", born "+birthDate.toString()+", hired "+hireDate.toString()+ + " employee ID: "+emplID); + } + /** + * returns the number of times an instance of Employee has been created. + * @return + */ + static public int getEmployeeCount(){ + return noOfEmployees; + } + +} diff --git a/homeAssignment05/src/EmployeeTest.java b/homeAssignment05/src/EmployeeTest.java new file mode 100644 index 0000000..e3f5579 --- /dev/null +++ b/homeAssignment05/src/EmployeeTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class EmployeeTest { + public static void main(String[] args){ + System.out.println("you have "+Employee.getEmployeeCount()+" employees."); + + + //turns out you can declare a new object inside declaring an object! + Employee bob = new Employee("Bob", "Ross", new Date(1,1,1995), new Date(20,9,2007)); + Employee doug = new Employee("Douglass", "Mcdonell", new Date(5,7,1968), new Date(23,4,1992)); + Employee linus = new Employee("Linus", "Torvalds", new Date(28,12,1969), new Date(30,6,1985)); + + //do I really have to explain these things? + System.out.println(bob.toString()); + System.out.println(doug.toString()); + System.out.println(linus.toString()); + + System.out.println("you have "+Employee.getEmployeeCount()+" employees."); + + System.out.println("is bob the same as doug? T/F: "+bob.equals(doug)); + } +} diff --git a/lab01/src/helloworld.java b/lab01/src/helloworld.java new file mode 100644 index 0000000..eb42160 --- /dev/null +++ b/lab01/src/helloworld.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author gabriel.venberg + */ +public class helloworld { + public static void main(String[] args) + { + System.out.println("Hello World!"); + System.out.println("Bonjour!"); + System.out.println("Brought to you by Gabe."); + + //tmp +char c = 67; +System.out.println(c); + } +} diff --git a/lab02/src/Weight.java b/lab02/src/Weight.java new file mode 100644 index 0000000..da55f88 --- /dev/null +++ b/lab02/src/Weight.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author gabriel.venberg + */ +public class Weight +{ + + /** + * Your comments go here + * @param args + */ + + public static void main(String[] args) + { + //create 3 variables to store the different weights 10, 20, 30 + int kg1 = 10; + int kg2 = 20; + int kg3 = 30; + //create a variable to store the conversion factor to convert 1Kg to pounds + double kToLb = 2.20462; + //create 3 variables to store the results of the conversion + float lb1; + float lb2; + float lb3; + lb1 = (float) (kg1/kToLb); + lb2 = (float) (kg2/kToLb); + lb3 = (float) (kg3/kToLb); + //print the results of the conversion to the output window + System.out.println(lb1); + System.out.println(lb2); + System.out.println(lb3); + } +} diff --git a/lab03/nbproject/private/jshell.history b/lab03/nbproject/private/jshell.history new file mode 100644 index 0000000..e69de29 diff --git a/lab03/src/circleCalc.java b/lab03/src/circleCalc.java new file mode 100644 index 0000000..48d1163 --- /dev/null +++ b/lab03/src/circleCalc.java @@ -0,0 +1,23 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author gabriel.venberg + */ +public class circleCalc { + public static void main(String[] args){ + double radius=3.4; + double area; + double perimeter; + + perimeter=(radius*2*Math.PI); + area=(Math.pow(radius, 2)*Math.PI); + + System.out.println("The perimeter is "+perimeter); + System.out.println("The area is "+area); + } +} diff --git a/lab03/src/tempConversion.java b/lab03/src/tempConversion.java new file mode 100644 index 0000000..0986620 --- /dev/null +++ b/lab03/src/tempConversion.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author gabriel.venberg + */ +public class tempConversion { + public static void main(String[] args) { + + final double converCoeff = (double)5/(double)9; + final int convertoffSet = 32; + + //would be better to store as array and loop through array, but have not covered arrays yet. + double f1=32; + double f2=72; + double f3=0; + double f4=212; + + double c1; + double c2; + double c3; + double c4; + + //again, it would be better to loop through the array here... + c1=(converCoeff*(f1-convertoffSet)); + c2=(converCoeff*(f2-convertoffSet)); + c3=(converCoeff*(f3-convertoffSet)); + c4=(converCoeff*(f4-convertoffSet)); + + System.out.println(f1+" degrees F is "+c1+" degrees c"); + System.out.println(f2+" degrees F is "+c2+" degrees c"); + System.out.println(f3+" degrees F is "+c3+" degrees c"); + System.out.println(f4+" degrees F is "+c4+" degrees c"); + + } +} diff --git a/lab03/src/timeCalc.java b/lab03/src/timeCalc.java new file mode 100644 index 0000000..63ef90b --- /dev/null +++ b/lab03/src/timeCalc.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author gabriel.venberg + */ +public class timeCalc { + public static void main(String[] args){ + final int secInHour=3600; + final int secInMin=60; + + int inputSec=8732; + + int outputHour; + int outputMin; + int outputSec; + + //hours + outputHour=inputSec/secInHour; + //remainder in sec + outputSec=inputSec%secInHour; + //minutes + outputMin=outputSec/secInMin; + //remainder in sec + outputSec=outputSec%secInMin; + + System.out.println(inputSec+" seconds is equal to "+outputHour+":"+outputMin+":"+outputSec); + } + +} diff --git a/lab04/src/milesConversion.java b/lab04/src/milesConversion.java new file mode 100644 index 0000000..0061e30 --- /dev/null +++ b/lab04/src/milesConversion.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author gabriel.venberg + */ +public class milesConversion { + public static void main(String[] args){ + //declare constants + final int yardsInMile=1760; + final int feetInMile=5280; + final int inchesInMile=63360; + + //our input + int inputMiles=4; + + //declare output variables + int outputInches; + int outputFeet; + int outputYards; + + //calculate them + outputInches=inputMiles*inchesInMile; + outputFeet=inputMiles*feetInMile; + outputYards=inputMiles*yardsInMile; + + //and output them. + System.out.println(inputMiles+" miles is equal to "+outputYards+" yards, "+outputFeet+" feet, or "+outputInches+" inches."); + } +} diff --git a/lab04/src/quartsToGallons.java b/lab04/src/quartsToGallons.java new file mode 100644 index 0000000..981742f --- /dev/null +++ b/lab04/src/quartsToGallons.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author gabriel.venberg + */ +public class quartsToGallons { + public static void main(String[] args){ + //declare constant + final int gallonsInQuart=4; + + //our 'inpt' + int inputQuarts=23; + + //declare our outputs. + int outputGallons; + int outputQuarts; + + //calculate them + outputGallons=inputQuarts/gallonsInQuart; + outputQuarts=inputQuarts%gallonsInQuart; + + //output the whole thing. + System.out.println(inputQuarts+" quarts is equal to "+outputGallons+" gallons and "+outputQuarts+" quarts"); + } +} diff --git a/lab05/src/BankAccount.java b/lab05/src/BankAccount.java new file mode 100644 index 0000000..0d60a88 --- /dev/null +++ b/lab05/src/BankAccount.java @@ -0,0 +1,65 @@ + +/** + * BankAccount class that represents a real world entity Bank Account. It supports deposit, withdrawal + * and checking balance operations. + * + * @author Pratap Kotala + * @version 9/23/2014 + */ +public class BankAccount +{ + //instance variable balance to store the balance amount information + private double balance; + + /** + * Default constructor for objects of class BankAccount which initializes balance to zero. + */ + public BankAccount() + { + // initialise instance variables + balance = 0; + } + + /** + * Constructor for objects of class BankAccount which initializes balance to amount. + */ + public BankAccount(double amount) + { + balance = amount; + } + /** + * getBalance() method returns the current balance + * + * @param no parameter + * @return double + */ + public double getBalance() + { + return balance; + } + + /** + * deposit() method adds the amount to the current balance + * + * @param double amount + * @return void + */ + public void deposit(double amount) + { + balance += amount; + } + + /** + * withdraw() method reduces the current balance by amount + * + * @param double amount + * @return void + */ + public void withdraw(double amount) + { + if (amount > balance) + throw new IllegalArgumentException("insufficient balance"); + else + balance -= amount; + } +} \ No newline at end of file diff --git a/lab05/src/BankAccountTest.java b/lab05/src/BankAccountTest.java new file mode 100644 index 0000000..afdaa87 --- /dev/null +++ b/lab05/src/BankAccountTest.java @@ -0,0 +1,44 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * BankAccountTest program created for CS1 class. + * @author toric + */ +public class BankAccountTest { + public static void main(String[] args) { + + //initalize the first account + BankAccount account1 = new BankAccount(); + + //inital deposit + account1.deposit(1000); + + //print amount + System.out.println("account 1 has $"+account1.getBalance()); + + //withdraw + account1.withdraw(250); + + //second account + BankAccount account2 = new BankAccount(500); + + //print balance + System.out.println("account 2 has $"+account2.getBalance()); + + //withdraw 100. + account2.withdraw(100); + + //link the two accounts. + account2 = account1; + + //deposit + account1.deposit(50); + + System.out.println("account 1 has $"+account1.getBalance()); + System.out.println("account 2 has $"+account2.getBalance()); + } +} \ No newline at end of file diff --git a/lab05/src/StringTest.java b/lab05/src/StringTest.java new file mode 100644 index 0000000..350c302 --- /dev/null +++ b/lab05/src/StringTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * made for lab05 + * @author toric + */ +public class StringTest { + public static void main(String[] args) { + + //inital assignment + String string1 = new String("Hi"); + String string2 = new String("Hello World"); + + //finding the lengh of the two strings + System.out.println("string1 is "+string1.length()+" characters long"); + System.out.println("string1 is "+string2.length()+" characters long"); + + //find the first o in both strings + System.out.println("the first o in string1 is at position "+string1.indexOf("o")); + System.out.println("the first o in string2 is at position "+string2.indexOf("o")); + + //find the last o in each string + System.out.println("the last o in string1 is at position "+string1.lastIndexOf("o")); + System.out.println("the last o in string2 is at position "+string2.lastIndexOf("o")); + + //use substring() to make a variable containing "world" + String substring = string2.substring(6); + System.out.println("string2 starting with the 6th character is "+substring); + + //string2 all lowercase + System.out.println("string2 in all lowercase is "+string2.toLowerCase()); + + //string2 to all uppercase + System.out.println("string2 in all uppercase is "+string2.toUpperCase()); + } +} \ No newline at end of file diff --git a/lab06/src/DigitAddition.java b/lab06/src/DigitAddition.java new file mode 100644 index 0000000..3706cf5 --- /dev/null +++ b/lab06/src/DigitAddition.java @@ -0,0 +1,51 @@ + +import java.util.Scanner; + +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *Adds the digits of a three digit number together. + * @author toric + */ +public class DigitAddition { + public static void main(String[] args){ + //initalizing + Scanner scan = new Scanner(System.in); + int input; + int digit1; + int digit2; + int digit3; + int sum; + + //input + System.out.print("Input a 3 digit number >> "); + input = scan.nextInt(); + System.out.println(); + + //calculations + digit3 = input%10; + //temporarily use digit2 to store the first 2 digits. + digit2 = input/10; + digit2 = digit2%10; + digit1 = input/100; + sum = digit1+digit2+digit3; + + //output + System.out.println("You entered "+input+", the sum of "+digit1+"+"+digit2+"+"+digit3+" is "+sum); + } +} diff --git a/lab06/src/Morgage.java b/lab06/src/Morgage.java new file mode 100644 index 0000000..9f85078 --- /dev/null +++ b/lab06/src/Morgage.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *Calculates monthly payment and other values from annual interest rate, years of loan, and amount of loan. + * @author toric + */ +import java.util.Scanner; +import java.text.NumberFormat; +import java.text.DecimalFormat; +public class Morgage { + public static void main(String[] args){ + //initalizing things + Scanner scan = new Scanner(System.in); + NumberFormat percentFormat = NumberFormat.getPercentInstance(); + NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(); + DecimalFormat twoDecimal = new DecimalFormat("##.00"); + double interestRate; + double morgageYears; + double morgageAmount; + double monthlyPayment; + double totalPayment; + double totalInterest; + double totalInterestPercent; + + //getting input. + System.out.print("Enter the annual intrest rate as a decimal >> "); + interestRate = scan.nextDouble(); + System.out.println(); + System.out.print("Enter length of the morgage >> "); + morgageYears = scan.nextDouble(); + System.out.println(); + System.out.print("Enter the dollar amount of the morgage >> "); + morgageAmount = scan.nextDouble(); + System.out.println(); + + //calculations + /* This formula, given by the assignment word doc, is wrong. using it (with no changes to the surrounding code) + results in negative overpayment, and, in extreme cases, negative monthly payments. Go ahead, try it. + uncomment the incorrect formula and comment out the correct one. + */ + //monthlyPayment = ((interestRate/12)*morgageAmount)/(1-(1/Math.pow((1+interestRate),(12*morgageYears)))); + //it should be: + monthlyPayment = ((interestRate)*morgageAmount)/(1-(1/Math.pow((1+interestRate),(morgageYears)))); + totalPayment = monthlyPayment*morgageYears; + totalInterest = totalPayment-morgageAmount; + totalInterestPercent = totalInterest/morgageAmount; + + //output + System.out.println("Interest Rate: "+percentFormat.format(interestRate)); + System.out.println("Length of Morgage: "+morgageYears+ " Years"); + System.out.println("Monthly Payment: "+moneyFormat.format(monthlyPayment)); + System.out.println("Total Payment: "+moneyFormat.format(totalPayment)); + System.out.println("Overpayment: "+moneyFormat.format(totalInterest)); + System.out.println("Overpayment Percentage: "+percentFormat.format(totalInterestPercent)); + } +} diff --git a/lab06/src/Payroll.java b/lab06/src/Payroll.java new file mode 100644 index 0000000..d18f985 --- /dev/null +++ b/lab06/src/Payroll.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * calculates employee payroll statement given the employee name, no of hours worked, + * hourly pay rate, federal and state tax rates. + * @author toric + */ +import java.util.Scanner; +import java.text.NumberFormat; +public class Payroll { + public static void main(String[] args){ + //initialzing stuff. + Scanner scan = new Scanner(System.in); + NumberFormat percentFormat = NumberFormat.getPercentInstance(); + NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(); + String employeeName; + double hourlyPay; + double hoursWorked; + double stateTax; + double fedTax; + double grossIncome; + double netIncome; + double fedTaxWithheld; + double stateTaxWithheld; + double netTaxWithheld; + + //geting input. + System.out.print("Enter your name >> "); + employeeName = scan.next(); + System.out.println(); + System.out.print("enter your hourly wage >> "); + hourlyPay = scan.nextDouble(); + System.out.println(); + System.out.print("enter the hours you worked this week >> "); + hoursWorked = scan.nextDouble(); + System.out.println(); + System.out.print("enter your states tax rate as a decimal >> "); + stateTax = scan.nextDouble(); + System.out.println(); + System.out.print("enter your federal tax rate as a decimal >> "); + fedTax = scan.nextDouble(); + System.out.println(); + + //calculations + grossIncome = hoursWorked * hourlyPay; + fedTaxWithheld = grossIncome*fedTax; + stateTaxWithheld = grossIncome*stateTax; + netTaxWithheld = stateTaxWithheld+fedTaxWithheld; + netIncome = grossIncome-netTaxWithheld; + + //output + System.out.println("Name: "+employeeName); + System.out.println("Hourly Pay: "+moneyFormat.format(hourlyPay)); + System.out.println("Hours Worked: "+hoursWorked); + System.out.println("State Tax Rate: "+percentFormat.format(stateTax)); + System.out.println("Federal Tax Rate: "+percentFormat.format(fedTax)); + System.out.println("Gross Income: "+moneyFormat.format(grossIncome)); + System.out.println("State Tax Withheld: "+moneyFormat.format(stateTaxWithheld)); + System.out.println("Federal Tax Withheld: "+moneyFormat.format(fedTaxWithheld)); + System.out.println("Total Tax Withheld: "+moneyFormat.format(netTaxWithheld)); + System.out.println("Net Income: "+moneyFormat.format(netIncome)); + } +} diff --git a/lab07/src/LeapYear.java b/lab07/src/LeapYear.java new file mode 100644 index 0000000..3466110 --- /dev/null +++ b/lab07/src/LeapYear.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *Takes a year as input and tells you whether that year is a leap year. + * @author toric + */ +import java.util.Scanner; +public class LeapYear { + public static void main(String[] args){ + //setup + Scanner scan = new Scanner(System.in); + + int inputYear; + final int earliestYear = 1582; + + //get input + System.out.print("Enter a year in the format yyyy >> "); + inputYear = scan.nextInt(); + System.out.println(); + + //calculation stages. As usual, do the error checking with priority. + if (inputYear < earliestYear) { + System.out.println("The gregorian calander did not exist at this time in history."); + } + else if ((inputYear%400==0)||(inputYear%4==0 && inputYear%100!=0)) { + System.out.println("This year was a leap year."); + } + else { + System.out.println("This year was not a leap year."); + } + } +} diff --git a/lab07/src/Seasons.java b/lab07/src/Seasons.java new file mode 100644 index 0000000..9771c70 --- /dev/null +++ b/lab07/src/Seasons.java @@ -0,0 +1,54 @@ + +import java.util.Scanner; + +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *takes an input temp and outputs a probable season using a highly accurate (tm) + * and sophisticated (tm) algorithm (tm) + * @author toric + */ +public class Seasons { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + double degreesF; + + System.out.print("Input a temperature in terms of degrees F >> "); + degreesF = scan.nextDouble(); + System.out.println(); + + //check the out of bounds first, so we dont have to inculde OR statements in the following statemnts + if (degreesF>110||degreesF<-5){ + System.out.println("Outside the valid range"); + } + else if (degreesF>=90){ + System.out.println("It is probably summer"); + } + else if (degreesF>=70){ + System.out.println("It is probably spring"); + } + else if (degreesF>=50){ + System.out.println("It is probably fall"); + } + //Since we already checked if it is <-5 in error checking, and we checked that it is < 50 if it passed the above line, it must be winter. + else { + System.out.println("It is probably winter"); + } + } +} \ No newline at end of file diff --git a/lab07/src/Triangle.java b/lab07/src/Triangle.java new file mode 100644 index 0000000..e821db4 --- /dev/null +++ b/lab07/src/Triangle.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *Takes three numerical inputs as the length of three sides to a triangle, determines + * whether they are valid inputs, and if so, returns the perimeter. + * @author toric + */ +import java.util.Scanner; +public class Triangle { + public static void main(String[] args) { + //setup + Scanner scan = new Scanner(System.in); + + double side1; + double side2; + double side3; + double perimeter; + + //gathering input + System.out.print("Enter the length of side 1 of the triangle >> "); + side1 = scan.nextDouble(); + System.out.println(); + System.out.print("Enter the length of side 2 of the triangle >> "); + side2 = scan.nextDouble(); + System.out.println(); + System.out.print("Enter the length of side 3 of the triangle >> "); + side3 = scan.nextDouble(); + System.out.println(); + + /*find 0's and negatives first, as many 0's and negatives will also satisfy the second condition. + * we want the returns to be intuitive, so we want the 0 or negative one to be first in priority. + */ + if (side1<=0||side2<=0||side3<=0) { + System.out.println("Inputs invalid: one or more sides is zero or negative."); + } + else if ((side1+side2<=side3)||(side1+side3<=side2)||(side2+side3<=side1)) { + System.out.println("Inputs invalid: sum of two edges greater than third edge."); + } + else { + perimeter = side1+side2+side3; + System.out.println("The perimeter of the triangle is: "+perimeter); + } + + + } +} \ No newline at end of file diff --git a/lab08/grades.txt b/lab08/grades.txt new file mode 100644 index 0000000..f31e76d --- /dev/null +++ b/lab08/grades.txt @@ -0,0 +1,19 @@ +88 +78 +96 +75 +99 +56 +78 +84 +93 +79 +90 +85 +79 +90 +85 +79 +92 +99 +94 diff --git a/lab08/src/Grades.java b/lab08/src/Grades.java new file mode 100644 index 0000000..65e4d12 --- /dev/null +++ b/lab08/src/Grades.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.Scanner; +import java.io.File; +import java.io.IOException; +public class Grades { + public static void main(String args[]) throws IOException { + //initialization + int grade=0; + int as=0, bs=0, cs=0, ds=0, fs=0; + int passed; + int studentCount=0; + int highestGrade=0; + int lowestGrade=100; + int average=0; + + File inputFile = new File("grades.txt"); + Scanner file = new Scanner(inputFile); + + //start iterating over file. + while(file.hasNext()) { + grade = file.nextInt(); + studentCount ++; + //for now we use average to keep a rolling total. we will divide by num of students after. + average = average+grade; + highestGrade = Math.max(grade, highestGrade); + lowestGrade = Math.min(grade, lowestGrade); + + //calculate whether this was an a, b, c, d, or f. + if (grade>=90){ + as++; + } + else if (grade>=80) { + bs++; + } + else if (grade>=70) { + cs++; + } + else if (grade>=60) { + ds++; + } + else { + fs++; + } + } + + //final calcs, now that we have the whole file. + average = average/studentCount; + passed = as+bs+cs+ds; + + //output everything. + System.out.println("Pleas put the data in a text file, labeled \'grades.txt\', and format it as one grade per line."); + System.out.println("Out of "+studentCount+" students, "+passed+" passed,"+'\n'+ + as+" got A's, "+bs+" got B's, "+cs+" got C's, "+ds+" got D's, and "+fs+" failed."); + System.out.println("The hightest grade was "+highestGrade+" and the lowest grade was "+lowestGrade+'.'+'\n'+ + "The average of all the grades was "+average+'.'); + } +} diff --git a/lab08/src/HiLo.java b/lab08/src/HiLo.java new file mode 100644 index 0000000..0baeb8e --- /dev/null +++ b/lab08/src/HiLo.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.Scanner; +import java.util.Random; +public class HiLo { + public static void main(String args[]) { + //initialization + Random random = new Random(); + Scanner scan = new Scanner(System.in); + int target; + int guess=0; + int tries = 1; + String input; + final int SENTINEL = -1; + final int maxTarget = 100; + final int minTarget = 1; + + //generate our target. + target = random.nextInt((maxTarget-minTarget)+1)+minTarget; + + //explain the game. + System.out.println("I have chosen a number between "+minTarget+" and "+maxTarget+"."); + System.out.println("Each time you guess, I will tell you if your guess is high or low."); + System.out.println("The goal is to get the number in an few tries as possible."); + System.out.println("If you want to stop playing, type \'exit\'"); + + while(guess!=SENTINEL) { + //get next guess. + System.out.println("Try "+tries); + System.out.print("Enter your guess >"); + input = scan.nextLine(); + System.out.println(); + + + //figure out what our output should be + if (input.equals("exit")){ + //why cant we just use a break here? + guess = SENTINEL; + } + else{ + //if we are not exiting, convert the input to a proper integer, and do the comparison. + guess = Integer.valueOf(input); + if (guess < target) { + System.out.println("Your guess is too low."); + tries ++; + } + else if (guess > target) { + System.out.println("your guess is too high"); + tries ++; + } + else if (guess == target) { + System.out.println("Your guess is correct!"); + System.out.println("It took you "+tries+" tries to guess it."); + //if I didnt have to use a sentinel value here, I could have prevented the nested if statements and just used a break. + guess = SENTINEL; + } + } + } + } +} diff --git a/lab08/src/RockPaperSissors.java b/lab08/src/RockPaperSissors.java new file mode 100644 index 0000000..6cc3b21 --- /dev/null +++ b/lab08/src/RockPaperSissors.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.Scanner; +import java.util.Random; +public class RockPaperSissors { + public static void main(String args[]) { + //initialization + Random random = new Random(); + Scanner scan = new Scanner(System.in); + int wins=0; + int losses=0; + int comp; + int human; + int result; + //humanChoice must be a string for the exit command. compChoice can just be a char. + char humanChoice; + char compChoice; + + while (true) { + comp = random.nextInt(3); + System.out.println("Enter \'R\', \'P\' or \'S\' for your input."); + System.out.println("or enter \'Q\' to exit the game."); + System.out.print(">"); + humanChoice = scan.next().charAt(0); + if (humanChoice == 'Q'){ + System.out.println("You had "+wins+" victories and "+losses+" defeats."); + break; + } + //converting between the numbers and the human readable stuff. + switch(comp) { + case 0: + compChoice = 'R'; + break; + case 1: + compChoice = 'P'; + break; + case 2: + compChoice = 'S'; + break; + default: + //compiler wont shut up if variable does not have a default. + compChoice = '?'; + System.out.println("Something went wrong!"); + continue; + } + switch(humanChoice) { + case 'R': + human = 0; + break; + case 'P': + human = 1; + break; + case 'S': + human = 2; + break; + default: + //compiler wont shut up if variable does not have a default. + //we restart the loop if the input is invalid. + human = 0; + System.out.println("Sorry, invalid input."); + continue; + } + //some modulus magic finds the winner. + //Java does strange things with negative moduluses, so im adding a 3 in there so it is always positive. + result = (comp-human+3)%3; + + System.out.println("You chose "+humanChoice+", and the computer chose "+compChoice); + switch(result){ + case 0: + System.out.println("You tied."); + break; + case 1: + System.out.println("You lost."); + losses++; + break; + case 2: + System.out.println("You won!"); + wins++; + break; + } + } + } +} diff --git a/lab10/dist/javadoc/element-list b/lab10/dist/javadoc/element-list new file mode 100644 index 0000000..147af06 --- /dev/null +++ b/lab10/dist/javadoc/element-list @@ -0,0 +1 @@ +unnamed package diff --git a/lab10/src/Course.java b/lab10/src/Course.java new file mode 100644 index 0000000..0f05279 --- /dev/null +++ b/lab10/src/Course.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class Course { + private int courseID; + private int credits; + private String instructorName; + + public Course( int startCourseID, int startCredits, String startInstructorName){ + courseID = startCourseID; + credits=startCredits; + instructorName=startInstructorName; + } + /** + * returns courseID + * @return + */ + public int getCourseID(){ + return courseID; + } + /** + * returns credits + * @return + */ + public int getCredits(){ + return credits; + } + /** + * returns instructorName + * @return + */ + public String getInstructorName(){ + return instructorName; + } + /** + * outputs data about course as a string. + * @return + */ + public String toString(){ + return ("courseID: "+courseID+", credits: "+credits+", instructor: "+instructorName); + } + /** + * compares for equality with another course. + * @param testCourse + * @return + */ + public boolean equals(Course testCourse){ + return testCourse.getCourseID()==courseID&testCourse.getCredits()==credits + &testCourse.getInstructorName().equals(instructorName); + } +} diff --git a/lab10/src/NFLstats.java b/lab10/src/NFLstats.java new file mode 100644 index 0000000..a591399 --- /dev/null +++ b/lab10/src/NFLstats.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *I know nothing about football, and especially nothing about football stats... + * + * @author toric + */ +import java.util.Scanner; +import java.text.NumberFormat; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class NFLstats { + + public static void main(String[] args) throws FileNotFoundException, IOException { + // initalizing. + File inputFile = new File("stats.txt"); + Scanner file = new Scanner(inputFile); + NumberFormat percentFormat = NumberFormat.getPercentInstance(); + //getting file line size, to instatiate array. + Path path = Paths.get("stats.txt"); + //first line defines columns. + int lines = (int) Files.lines(path).count() - 1; + double[] yards = new double[lines]; + int[] attempts = new int[lines]; + int[] completions = new int[lines]; + double[] yardsPerAttempt = new double[lines]; + double[] completionPercentage = new double[lines]; + int highYardGames = 0; + final double highYardThreshold = 275; + double totalYards = 0; + double highYards = 0; + + //skip the first line, first line contains colum defs. + /*why am I reading all this info from a file, you might ask? well, this assignment didnt tell me what input method to use. + i didnt want to hardcode it, and no way was i entering all that data manually every run.*/ + file.nextLine(); + for (int i = 0; i < lines; i++) { + String line = file.nextLine(); + String[] data = line.split(","); + + //column order is game,attempts,completions,yards. not using game this program. + attempts[i] = Integer.parseInt(data[1]); + completions[i] = Integer.parseInt(data[2]); + yards[i] = Double.parseDouble(data[3]); + } + + //we can put all the arrayprocessing in one loop. + for (int i = 0; i < yards.length; i++) { + //System.out.println(yards[i] + "," + completions[i] + "," + attempts[i]); + totalYards = totalYards + yards[i]; + completionPercentage[i] = (double)completions[i] / (double)attempts[i]; + yardsPerAttempt[i] = yards[i] / attempts[i]; + if (yards[i] >= highYardGames) { + highYardGames++; + } + highYards = Math.max(yards[i], highYards); + } + + //print stuff. not sure why you only had us print a few of the completed values... + for (int i = 0; i < completionPercentage.length; i++) { + System.out.println("Game " + (i + 1) + " had a completion percentage of " + percentFormat.format(completionPercentage[i])); + } + System.out.println("The most yards thrown during any game was " + highYards + "."); + } +} diff --git a/lab10/src/Student.java b/lab10/src/Student.java new file mode 100644 index 0000000..a58b093 --- /dev/null +++ b/lab10/src/Student.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +public class Student { + private int studentID; + private double GPA; + private String name; + private char gender; + private Course courseList[]; + private static int nextID = 1000; + + public Student(String startName, char startGender, Course [] startCourseList){ + studentID=nextID; + nextID++; + GPA=0.0; + name=startName; + gender=startGender; + courseList =new Course[startCourseList.length]; + for (int i=0; i. + */ + +/** + * + * @author toric + */ +public class StudentTest { + public static void main(String[] args){ + Course CS1 = new Course(160, 4, "Pratap Kotala"); + Course linearAlgebra = new Course(129, 4, "Michal Roberts"); + Course startCourseList[]={CS1, linearAlgebra}; + Student johnDoe = new Student ("John Doe", 'm', startCourseList); + startCourseList[0]=linearAlgebra; startCourseList[1]=CS1; + Student johnDoe2 = new Student ("John Doe", 'm', startCourseList); + + //the only interesting thing about this class is that equals is order sensitive witht the course list. + + System.out.println(johnDoe.equals(johnDoe2)); + } +} diff --git a/lab10/stats.txt b/lab10/stats.txt new file mode 100644 index 0000000..c4e62ce --- /dev/null +++ b/lab10/stats.txt @@ -0,0 +1,18 @@ +game,attempts,completions,yards +08/15/19,14,10,118 +08/22/19,14,9,74 +09/08/19,46,33,304 +09/15/19,43,27,320 +09/22/19,34,29,304 +09/29/19,53,35,397 +10/06/19,46,32,330 +10/13/19,36,30,356 +10/20/19,27,16,159 +11/10/19,35,20,182 +11/17/19,31,21,311 +11/24/19,46,23,271, +11/28/19,50,35,312, +12/08/19,34,20,313, +12/15/19,39,25,210, +12/22/19,45,32,384, +12/29/19,51,30,313, diff --git a/lab11/src/Passenger.java b/lab11/src/Passenger.java new file mode 100644 index 0000000..d3d3fcd --- /dev/null +++ b/lab11/src/Passenger.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + *the assignment didnt specify what to put in this class in terms of methods, so I guessed. + * @author toric + */ +public class Passenger { + private String name; + private int serviceLevel; + + public Passenger(String startName, int startServiceLevel){ + name = startName; + setServiceLevel(startServiceLevel); + } + /** + * sets serviceLevel + * @param newServiceLevel + */ + public void setServiceLevel(int newServiceLevel){ + if (newServiceLevel==1 || newServiceLevel==2){ + serviceLevel=newServiceLevel; + } + else{ + throw new IllegalArgumentException("serviceLevel must be 1 or 2"); + } + } + /** + * gets serviceLevel + * @return + */ + public int getServiceLevel(){return serviceLevel;} + /** + * gets name + * @return + */ + public String getName(){return name;} + /** + * converts object into a human readable string. + * @return + */ + public String toString(){ + return "Name: "+name+", service level: "+serviceLevel+"."; + } + /** + * tests equality with another passenger object. + * @param testPassenger + * @return + */ + public boolean equals(Passenger testPassenger){ + return (name.equals(testPassenger.getName()) && serviceLevel==testPassenger.getServiceLevel()); + } +} diff --git a/lab11/src/Train.java b/lab11/src/Train.java new file mode 100644 index 0000000..5d265a7 --- /dev/null +++ b/lab11/src/Train.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2020 Gabriel Venberg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * + * @author toric + */ +import java.util.ArrayList; +public class Train { + ArrayList passengerList; + + public Train(){ + passengerList = new ArrayList(); + } + + /** + * adds Passenger to the passengerList. + * @param newPassenger + */ + public void addPassenger(Passenger newPassenger){ + passengerList.add(new Passenger(newPassenger.getName(), newPassenger.getServiceLevel())); //preserving encapsulation + } + /** + * returns the passenger object at index position i + * @param i + * @return + */ + public Passenger getPassenger(int i){ + return new Passenger(passengerList.get(i).getName(), passengerList.get(i).getServiceLevel()); //preserving encapsulation + } + /** + * returns number of passengers + * @return + */ + public int getNoOfPassengers(){ + return passengerList.size(); + } + /** + * returns the percentage of all passengers that are first class. + * @return + */ + public double getPercentFirstClass(){ + double firstClassPassengers = 0; + for (int i=0;i. + */ + +/** + * + * @author Gabriel Venberg + */ +import java.util.Scanner; +import java.io.File; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.text.NumberFormat; + +public class TrainTest { + public static void main(String[] args) throws FileNotFoundException, IOException { + //initial, boilerplate initialization. + File inputFile = new File("passengers.txt"); + Scanner file = new Scanner(inputFile); + NumberFormat percentFormat = NumberFormat.getPercentInstance(); + NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(); + + Train testTrain = new Train(); + double firstClassRate=10; + double secondClassRate=2; + + while(file.hasNext()){ + String line = file.nextLine(); + String[] data = line.split("\s"); // \s matches any whitespace char. + testTrain.addPassenger(new Passenger(data[0], Integer.parseInt(data[1]))); + } + + System.out.println("The current Passengers are:"); + for (int i=0; i. + */ + +/** + * + * @author toric + */ +import java.util.ArrayList; +import java.lang.Math; +public class salesTax { + public static void main(String[] args){ + //declaring variables + double [][] salesTax = new double [50][10]; + ArrayList statesWithLowTax = new ArrayList(); //we dont know at first how many states will fall in this category. + final double lowTaxThreshold = .001; + double [] highestTaxPerState = new double [50]; + int stateWithHighestAvgTax = 0; + + + //declaring computation only variables outside the loop, will be initalized on first loop run. + double highestAvgTax = 0; + boolean stateHasLowSalesTax; + double highestLocalTax; + double localAvgTax; + + System.out.println("printing a table. each row is the last 10 years of a states sales tax."); + //we can put all the computation into the same loop, so we arent iterating over the same, unchanged loop multiple times. + for (int i=0;i