diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md new file mode 100644 index 00000000..63e0e64f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -0,0 +1,44 @@ +--- +name: 🐛 Bug Report +about: Submit a bug report to help us improve +labels: "bug" +--- + +## 🐛 Bug Report + +(A clear and concise description of what the bug is) + +## Have you spent some time to check if this issue has been raised before? + +(Have you googled for a similar issue or checked our older issues for a similar bug) + +## To Reproduce + +(Write your steps here:) + +## Expected behavior + + + +(Write what you thought would happen.) + +## Actual Behavior + + + +(Write what happened. Add screenshots, if applicable.) + +## Your Environment + + + +(Write Environment, Operating system and version etc.) diff --git a/.github/ISSUE_TEMPLATE/documentation.md b/.github/ISSUE_TEMPLATE/documentation.md new file mode 100644 index 00000000..b103d8a7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation.md @@ -0,0 +1,17 @@ +--- +name: 📚 Documentation +about: Report an issue related to documentation +labels: "documentation" +--- + +## 📚 Documentation + +(A clear and concise description of what the issue is.) + +## Have you spent some time to check if this issue has been raised before? + +(Have you googled for a similar issue or checked our older issues for a similar bug) + +### Have you read the [Contributing Guidelines](https://github.com/dubesar/Java-A-Z/blob/master/CONTRIBUTING.md)? + +(Write your answer here.) diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md new file mode 100644 index 00000000..0730c0c6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -0,0 +1,21 @@ +--- +name: 🚀 Feature +about: Submit a proposal for a new feature +labels: "feature" +--- + +## 🚀 Feature + +(A clear and concise description of what the feature is.) + +## Have you spent some time to check if this issue has been raised before? + +(Have you googled for a similar issue or checked our older issues for a similar bug) + +### Have you read the [Contributing Guidelines](https://github.com/dubesar/Java-A-Z/blob/master/CONTRIBUTING.md)? + +(Write your answer here.) + +## Pitch + +(Please explain why this feature should be implemented and how it would be used. Add examples, if applicable.) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..6c525a9f --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ + + +## What does this PR do? + +(Provide a description of what this PR does.) + +## Test Plan + +(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.) + +## Related PRs and Issues + +(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.) + +### Have you read the [Contributing Guidelines](https://github.com/dubesar/Java-A-Z/blob/master/CONTRIBUTING.md)? + +(Write your answer here.) diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7e47debb --- /dev/null +++ b/.gitignore @@ -0,0 +1,689 @@ + +### Android ### +# Built application files +*.apk +*.aar +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ +# Uncomment the following line in case you need and you don't have the release build type files in your app +# release/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +# Android Studio 3 in .gitignore file. +.idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild +.cxx/ + +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json + +# Replacement of .externalNativeBuild directories introduced +# with Android Studio 3.5. + +### AppEngine ### +# Google App Engine generated folder +appengine-generated/ + +### Code-Java ### +# Language Support for Java(TM) by Red Hat extension for Visual Studio Code - https://marketplace.visualstudio.com/items?itemName=redhat.java + +.project +.classpath +factoryConfiguration.json + +### Java ### +# Compiled class file + +# Log file + +# 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* + +### Java-Web ### +## ignoring target file +target/ + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### SublimeText ### +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### AndroidStudio ### +# Covers files to be ignored for android development using Android Studio. + +# Built application files + +# Files for the ART/Dalvik VM + +# Java class files + +# Generated files + +# Gradle files +.gradle + +# Signing files +.signing/ + +# Local configuration file (sdk path, etc) + +# Proguard folder generated by Eclipse + +# Log Files + +# Android Studio +/*/build/ +/*/local.properties +/*/out +/*/*/build +/*/*/production +*.ipr +*.swp + +# Keystore files +*.jks +*.keystore + +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Android Patch + +# External native build folder generated in Android Studio 2.2 and later + +# NDK +obj/ + +# IntelliJ IDEA +*.iws +/out/ + +# User-specific configurations +.idea/caches/ +.idea/libraries/ +.idea/shelf/ +.idea/.name +.idea/compiler.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/misc.xml +.idea/scopes/scope_settings.xml +.idea/vcs.xml +.idea/jsLibraryMappings.xml +.idea/datasources.xml +.idea/dataSources.ids +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml +.idea/jarRepositories.xml + +# OS-specific files +.DS_Store? + +# Legacy Eclipse project files +.cproject +.settings/ + +# Mobile Tools for Java (J2ME) + +# Package Files # + +# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) + +## Plugin-specific files: + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Mongo Explorer plugin +.idea/mongoSettings.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### AndroidStudio Patch ### + +!/gradle/wrapper/gradle-wrapper.jar + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*[.json, .xml, .info] + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..681f41ae --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d937403d..7c02c942 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/Algorithms/Bellmann_Ford.java b/Algorithms/Bellmann_Ford.java new file mode 100644 index 00000000..0a533439 --- /dev/null +++ b/Algorithms/Bellmann_Ford.java @@ -0,0 +1,107 @@ +import java.util.ArrayList; +import java.util.HashMap; + +public class Bellmann_Ford { + + public static void main(String[] args) { + + ArrayList Vertices = new ArrayList<>(); + ArrayList EdgeList = new ArrayList<>(); + + // vertices + Vertices.add("A"); + Vertices.add("B"); + Vertices.add("C"); + Vertices.add("D"); + + // edges + EdgeList.add(new Edge("A", "B", 3)); + EdgeList.add(new Edge("A", "D", 8)); + EdgeList.add(new Edge("B", "C", 1)); + EdgeList.add(new Edge("C", "A", -1)); +// EdgeList.add(new Edge("C", "A", -5)); // negative cycle case + EdgeList.add(new Edge("C", "D", 2)); + + // result + HashMap result = new HashMap<>(); + + String srcname = "A"; + + for (String vname : Vertices) { + BFpair bfp = new BFpair(); + if (vname.equals(srcname)) { + bfp.csf = 0; + bfp.psf = vname; + } else { + bfp.csf = Integer.MAX_VALUE; + bfp.psf = null; + } + result.put(vname, bfp); + } + + for (int i = 1; i <= Vertices.size() - 1; i++) { + for (Edge edge : EdgeList) { + String svname = edge.v1name;// source vertex + String dvname = edge.v2name;// destination vertex + int wt = edge.weight; + + BFpair sp = result.get(svname);// src pair + BFpair dp = result.get(dvname);// dest pair + + if (sp.psf == null) { + continue; + } else if (sp.csf + wt < dp.csf) { + dp.csf = sp.csf + wt; + dp.psf = sp.psf + dvname; + } + + result.put(dvname, dp); + } + } + + // check for cycle + for (Edge edge : EdgeList) { + String svname = edge.v1name;// source vertex + String dvname = edge.v2name;// destination vertex + int wt = edge.weight; + + BFpair sp = result.get(svname);// src pair + BFpair dp = result.get(dvname);// dest pair + + if (sp.psf == null) { + continue; + } else if (sp.csf + wt < dp.csf) { + System.out.println("negative cycle present"); + break; +// dp.csf = sp.csf + wt; +// dp.psf = sp.csf + dvname; + } + result.put(dvname, dp); + } + + System.out.println(result); + + } + + public static class Edge { + String v1name; + String v2name; + int weight; + + public Edge(String v1, String v2, int w) { + this.v1name = v1; + this.v2name = v2; + this.weight = w; + } + } + + public static class BFpair { + int csf; + String psf; + + public String toString() { + return " @ " + this.csf + " via " + this.psf; + } + } + +} diff --git a/Algorithms/Brian_Kernighan.java b/Algorithms/Brian_Kernighan.java new file mode 100644 index 00000000..51968825 --- /dev/null +++ b/Algorithms/Brian_Kernighan.java @@ -0,0 +1,31 @@ +/* + Brain Kernighan Algorithm is used to count the + No. of 1's or set bits in an Integer. + + e.g., 6 = 110 + Therefore, No. of set bits in 6 = 2 + +*/ +public class Brian_Kernighan { + + static int countSetBits(int n) { + + int count = 0; + + while(n > 0) { + n = n & (n-1); + count++; + } + + return count; + } + + public static void main(String[] args) { + + int n = 6; + int result = countSetBits(n); + System.out.println("There are " + result + " set bits or 1's in " + n); + + } + +} diff --git a/Algorithms/Ciphers/Diffie_Hellman.java b/Algorithms/Ciphers/Diffie_Hellman.java new file mode 100644 index 00000000..22f584af --- /dev/null +++ b/Algorithms/Ciphers/Diffie_Hellman.java @@ -0,0 +1,30 @@ +import java.util.*; +public class Diffie_Hellman +{ + public static void main(String args[]) + { + Scanner sc=new Scanner(System.in); + System.out.println("Enter modulo(p)"); + int p=sc.nextInt(); + System.out.println("Enter primitive root of "+p); + int g=sc.nextInt(); + System.out.println("Choose 1st secret no(DEEPANSHU)"); + int a=sc.nextInt(); + System.out.println("Choose 2nd secret no(GOYAL)"); + int b=sc.nextInt(); + int A = (int)Math.pow(g,a)%p; + int B = (int)Math.pow(g,b)%p; + int S_A = (int)Math.pow(B,a)%p; + int S_B =(int)Math.pow(A,b)%p; + if(S_A==S_B) + { + System.out.println("DEEPANSHU and GOYAL can communicate with each other...."); + System.out.println("They share a secret no = "+S_A); + } + + else + { + System.out.println("DEEPANSHU and GOYAL cannot communicate with each other...."); + } + } +} diff --git a/Algorithms/Ciphers/rsa.java b/Algorithms/Ciphers/rsa.java new file mode 100644 index 00000000..66bbd06a --- /dev/null +++ b/Algorithms/Ciphers/rsa.java @@ -0,0 +1,66 @@ + +/** + * RSA algorithm is asymmetric cryptography algorithm. Asymmetric actually means that it works on + * two different keys i.e. Public Key and Private Key. As the name describes that the Public Key is + * given to everyoneand Private key is kept private. + */ + +package ciphers; + +import java.math.BigInteger; +import java.security.SecureRandom; +import javax.swing.JOptionPane; + +public final class rsa { + + public static void main(String[] args) { + + RSA rsa = new RSA(1024); + String text1 = JOptionPane.showInputDialog("Enter a message to encrypt :"); + + String ciphertext = rsa.encrypt(text1); + JOptionPane.showMessageDialog(null, "Your encrypted message : " + ciphertext); + + JOptionPane.showMessageDialog(null, "Your message after decrypt : " + rsa.decrypt(ciphertext)); + } + + private BigInteger modulus, privateKey, publicKey; + + public RSA(int bits) { + generateKeys(bits); + } + + public synchronized String encrypt(String message) { + return (new BigInteger(message.getBytes())).modPow(publicKey, modulus).toString(); + } + + public synchronized BigInteger encrypt(BigInteger message) { + return message.modPow(publicKey, modulus); + } + + public synchronized String decrypt(String encryptedMessage) { + return new String((new BigInteger(encryptedMessage)).modPow(privateKey, modulus).toByteArray()); + } + + public synchronized BigInteger decrypt(BigInteger encryptedMessage) { + return encryptedMessage.modPow(privateKey, modulus); + } + + public synchronized void generateKeys(int bits) { + SecureRandom r = new SecureRandom(); + BigInteger p = new BigInteger(bits / 2, 100, r); + BigInteger q = new BigInteger(bits / 2, 100, r); + modulus = p.multiply(q); + + BigInteger m = (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE)); + + publicKey = new BigInteger("3"); + + while (m.gcd(publicKey).intValue() > 1) { + publicKey = publicKey.add(new BigInteger("2")); + } + + privateKey = publicKey.modInverse(m); + } + +} diff --git a/Algorithms/Ciphers/vigenere.java b/Algorithms/Ciphers/vigenere.java new file mode 100644 index 00000000..f51c11fe --- /dev/null +++ b/Algorithms/Ciphers/vigenere.java @@ -0,0 +1,69 @@ + +/** + * Vigenere Cipher is a method of encrypting alphabetic text. It uses a simple form of polyalphabetic + * substitution. A polyalphabetic cipher is any cipher based on substitution, using multiple + * substitution alphabets .The encryption of the original text is done using the Vigenère square or + * Vigenère table. + */ + +package ciphers; + +public class vigenere { + + public static String encrypt(final String message, final String key) + { + + String result = ""; + + for (int i = 0, j = 0; i < message.length(); i++) { + char c = message.charAt(i); + if (Character.isLetter(c)){ + if(Character.isUpperCase(c)) { + result += (char) ((c + key.toUpperCase().charAt(j) - 2 * 'A') % 26 + 'A'); + + } else { + result += (char) ((c + key.toLowerCase().charAt(j) - 2 * 'a') % 26 + 'a'); + + } + } else { + result+=c; + } + j = ++j % key.length(); + } + return result; + } + + public static String decrypt( final String message, final String key) + { + String result =""; + + for(int i = 0, j = 0; i < message.length(); i++){ + + char c = message.charAt(i); + if (Character.isLetter(c)){ + if(Character.isUpperCase(c)) { + result += ((char)('Z'-(25-(c-key.toUpperCase().charAt(j)))%26)); + + } else { + result += ((char)('z'-(25-(c-key.toLowerCase().charAt(j)))%26)); + + } + } else { + result+=c; + } + + j = ++j % key.length(); + + } + return result; + } + public static void main (String [] args){ + String text="Hello World!"; + String key="itsakey"; + System.out.println(text); + String ciphertext=encrypt(text, key); + System.out.println(ciphertext); + System.out.println(decrypt(ciphertext, key)); + + } +} diff --git a/Algorithms/CycleDetectionInLinkedList.java b/Algorithms/CycleDetectionInLinkedList.java new file mode 100644 index 00000000..542b4b8b --- /dev/null +++ b/Algorithms/CycleDetectionInLinkedList.java @@ -0,0 +1,55 @@ +/** + * Definition for singly-linked list. + * class ListNode { + * int val; + * ListNode next; + * ListNode(int x) { + * val = x; + * next = null; + * } + * } + */ + + /** + * Detection of a cycle/loop in a Singly-Linked List by using Two pointer approach specifically Fast and Slow pointers. + */ + +public class CycleDetectionInLinkedList{ + + public ListNode detectCycle(ListNode head) + { + if(head==null || head.next==null) + return null; + + ListNode slow = head; + ListNode fast = head; + + + while(fast!=null && fast.next!=null) + { + slow = slow.next; + fast = fast.next.next; + + if(slow==fast) + { + break; + } + + } + + if(slow==fast) + { + slow = head; + + while(slow!=fast) + { + slow = slow.next; + fast = fast.next; + } + + return fast; + } + return null; + + } +} \ No newline at end of file diff --git a/Algorithms/Fibonacci.java b/Algorithms/Fibonacci.java new file mode 100644 index 00000000..c7318cd7 --- /dev/null +++ b/Algorithms/Fibonacci.java @@ -0,0 +1,31 @@ +/** + * Fibonacci series in Java + * Program that prints the first N numbers of the Fibonacci series + * The first number in the series is 1, the second number is 1, and each of the + * following is the sum of the previous two + * + * @author IryaDev + */ + +import java.util.*; +public class Fibonacci{ + + public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + long number,fib_1 = 1,fib_2 = 1,i; + + do{ + System.out.print("Enter a number greater than one: "); + number = sc.nextInt(); + }while(number<=1); + System.out.println("The first " + number + " terms of the Fibonacci series are:"); + System.out.print(fib_1 + " "); + + for(i=2;i<=number;i++){ + System.out.print(fib_2 + " "); + fib_2 = fib_1 + fib_2; + fib_1 = fib_2 - fib_1; + } + System.out.println(); + } +} diff --git a/Algorithms/FloydWarshall.java b/Algorithms/FloydWarshall.java new file mode 100644 index 00000000..266ebfd4 --- /dev/null +++ b/Algorithms/FloydWarshall.java @@ -0,0 +1,39 @@ +import java.util.Arrays; + +public class FloydWarshall { + static final int INF = 10000; + + public static int[][] solve(int graph[][]) { + int result[][] = new int[graph.length][graph.length]; + + for (int i = 0; i < graph.length; i++) + for (int j = 0; j < graph.length; j++) + result[i][j] = graph[i][j]; + + for (int k = 0; k < graph.length; k++) + { + for (int i = 0; i < graph.length; i++) + { + for (int j = 0; j < graph.length; j++) + { + result[i][j] = Math.min(result[i][j], result[i][k] + result[k][j]); + } + } + } + + return result; + } + + public static void main(String args[]) + { + int graph[][] = + {{0, 3, INF, INF, 2}, + {INF, 0, 3, INF, 4}, + {1, INF, 0, 1, 3}, + {INF, 2, INF, 0, INF}, + {4, 5, INF, INF, 0}}; + + int result[][] = solve(graph); + System.out.println(Arrays.deepToString(result)); + } +} \ No newline at end of file diff --git a/Algorithms/GaussJordanAlgo.java b/Algorithms/GaussJordanAlgo.java new file mode 100644 index 00000000..7ab92aea --- /dev/null +++ b/Algorithms/GaussJordanAlgo.java @@ -0,0 +1,114 @@ +import java.util.Scanner; + +public class mainclass { + //got this convert to fraction from stack overflow + static private String convertDecimalToFraction(double x){ + if (x < 0){ + return "-" + convertDecimalToFraction(-x); + } + double tolerance = 1.0E-6; + double h1=1; double h2=0; + double k1=0; double k2=1; + double b = x; + do { + double a = Math.floor(b); + double aux = h1; h1 = a*h1+h2; h2 = aux; + aux = k1; k1 = a*k1+k2; k2 = aux; + b = 1/(b-a); + } while (Math.abs(x-h1/k1) > x*tolerance); + if (k1==1) + return ""+h1; + else + return h1+"/"+k1; + } + private static void displayMat(float[][] matrixdisp) + { + for (int i=0;i<3;i++) + { + for (int j=0;j<4;j++) + { + System.out.print(convertDecimalToFraction(matrixdisp[i][j])+ " "); + + } + System.out.println(); + } + System.out.println("***********************************************************"); + } + private static void pivot(float[][] piviotmat, int x, int y) + { + float value= piviotmat[x][y]; + float z=1/value;// value to piviot + System.out.println("piviting row "+ x+ "by multiplying "+convertDecimalToFraction(z)); + for (int k=0;k<4;k++) { + + piviotmat[x][k] = piviotmat[x][k] * z;//here we multiply the pivit + } + displayMat(piviotmat); + float multiplier; + for (int l=0;l<3;l++) + { + if (l!=y) { + multiplier = piviotmat[l][y];//value to multiply to piviot + System.out.println("multiplying row "+ x+ "by "+convertDecimalToFraction(multiplier)); + for (int k = 0; k < 4; k++) { + piviotmat[x][k] = piviotmat[x][k] * multiplier;//multiply pivit with row multiplier + } + displayMat(piviotmat); + System.out.println("substracting row "+ l+ "from row "+x); + for (int k = 0; k < 4; k++) { + piviotmat[l][k] = piviotmat[l][k] - piviotmat[x][k]; + + } + displayMat(piviotmat); + System.out.println("restoring pivit row "+ x+ "by dividing "+convertDecimalToFraction(multiplier)); + for (int k = 0; k < 4; k++) { + piviotmat[x][k] = piviotmat[x][k] /multiplier;//restore the multipied pivit matrix + } + displayMat(piviotmat); + } + + } + + } + public static void main(String[] args) { + float[][] matrix; + matrix = new float[3][4]; + for (int i=0;i<3;i++) + { + for (int j=0;j<4;j++) + { + System.out.println("enter the values : "); + Scanner sc= new Scanner(System.in); + float value= sc.nextFloat(); + matrix[i][j]=value;// checking matrix + + } + } + displayMat(matrix); + for (int i=0;i<3;i++) + { + for (int j=0;j<4;j++) + { + if (i==j&&matrix[i][j]!=1) + { + pivot(matrix, i, j); + + } + } + } + for (int m=0;m<3;m++) + { + switch (m) + { + case 0: System.out.println("value of x is "+ convertDecimalToFraction(matrix[0][3])); + break; + case 1: System.out.println("value of y is "+ convertDecimalToFraction(matrix[1][3])); + break; + case 2: System.out.println("value of z is "+ convertDecimalToFraction(matrix[2][3])); + break; + } + } + } +} + + diff --git a/Algorithms/Jump_Search.java b/Algorithms/Jump_Search.java new file mode 100644 index 00000000..0fdbefe3 --- /dev/null +++ b/Algorithms/Jump_Search.java @@ -0,0 +1,21 @@ +public static int jumpSearch(int[] arrayToSearch, int element) { + int blockSize = (int) Math.floor(Math.sqrt(arrayToSearch.length)); + + int currentLastIndex = blockSize-1; + + // Jump to next block as long as target element is > currentLastIndex + // and the array end has not been reached + while (currentLastIndex < arrayToSearch.length && element > arrayToSearch[currentLastIndex]) { + currentLastIndex += blockSize; + } + + // Find accurate position of target element using Linear Search + for (int currentSearchIndex = currentLastIndex - blockSize + 1; + currentSearchIndex <= currentLastIndex && currentSearchIndex < arrayToSearch.length; currentSearchIndex++) { + if (element == arrayToSearch[currentSearchIndex]) { + return currentSearchIndex; + } + } + // Target element not found. Return negative integer as element position. + return -1; +} diff --git a/Algorithms/Kosaraju.java b/Algorithms/Kosaraju.java new file mode 100644 index 00000000..ee617741 --- /dev/null +++ b/Algorithms/Kosaraju.java @@ -0,0 +1,123 @@ +// Implementation of Kosaraju's algorithm to print all Strongly Connected Components + +import java.util.*; + +class Graph +{ +// Adjacency List representation of Graph + int size; + LinkedList adjacencyList[]; + + Graph(int n) + { + size = n; + adjacencyList = new LinkedList[n]; + for (int i=0; i i = g.adjacencyList[v].iterator(); + while (i.hasNext()) + { + n = i.next(); + if (!visited[n]) + DFS(g, n,visited); + } + } + + // Function that returns reverse of this graph + Graph reverse() + { + Graph rev_graph = new Graph(graph.size); + for (int v = 0; v < graph.size; v++) + { + Iterator i = graph.adjacencyList[v].listIterator(); + while(i.hasNext()) + rev_graph.adjacencyList[i.next()].add(v); + } + return rev_graph; + } + + void fillOrder(int v, boolean visited[], Stack stack) + { + visited[v] = true; + + Iterator i = graph.adjacencyList[v].iterator(); + while (i.hasNext()) + { + int n = i.next(); + if(!visited[n]) + fillOrder(n, visited, stack); + } + + stack.push(v); + } + + void printSCCs() + { + Stack stack = new Stack(); + + boolean visited[] = new boolean[graph.size]; + for(int i = 0; i < graph.size; i++) + visited[i] = false; + + for (int i = 0; i < graph.size; i++) + if (visited[i] == false) + fillOrder( i, visited, stack); + + Graph rev_graph = reverse(); + + for (int i = 0; i < graph.size; i++) + visited[i] = false; + + while (stack.empty() == false) + { + int v = (int)stack.pop(); + if (visited[v] == false) + { + DFS(rev_graph, v, visited); + System.out.println(); + } + } + } + + public static void main(String args[]) + { + + Graph graph = new Graph(9); + graph.addEdge(0, 3); + graph.addEdge(1, 7); + graph.addEdge(2, 5); + graph.addEdge(3, 6); + graph.addEdge(4, 1); + graph.addEdge(5, 8); + graph.addEdge(6, 0); + graph.addEdge(7, 4); + graph.addEdge(7, 5); + graph.addEdge(8, 6); + graph.addEdge(8, 2); + + System.out.println("Strongly connected components are:\n"); + Kosaraju scc = new Kosaraju(graph); + scc.printSCCs(); + } +} diff --git a/Algorithms/LongestCommonSubsequence.java b/Algorithms/LongestCommonSubsequence.java new file mode 100644 index 00000000..8e5ff391 --- /dev/null +++ b/Algorithms/LongestCommonSubsequence.java @@ -0,0 +1,54 @@ +public class LongestCommonSubsequence { + + /** + * Given 2 string get the length of the longest subsequence that occurs in both the Strings + * + * For Example : + * 1 - LCS("abcde","ace") = "ace", so the program return 3 + * 2 - LCS("abcd", "abcd") = "abcd" so the program return 4 + * 3 - LCS("abc", "def") = "" it return 0 as there is no common subsequence in both the Strings. + * + * */ + public int longestCommonSubsequence(String s1, String s2) + { + int rows = s1.length(); + int cols = s2.length(); + char[] s = s1.toCharArray(); + char[] t = s2.toCharArray(); + + //2d array to keep track of max count of subsequence encountered so far. + int[][] dp = new int [rows][cols]; + + + for(int i=0; i 0 && j > 0) + + { + // If current character in X and Y are same, then + // current character is part of shortest supersequence + if (X.charAt(i - 1) == Y.charAt(j - 1)) + + { + // Put current character in result + str += (X.charAt(i - 1)); + + // reduce values of i, j and index + i--; + j--; + index--; + } + + // If current character in X and Y are different + else if (dp[i - 1][j] > dp[i][j - 1]) + { + + // Put current character of Y in result + str += (Y.charAt(j - 1)); + + // reduce values of j and index + j--; + index--; + } + else + { + + // Put current character of X in result + str += (X.charAt(i - 1)); + + // reduce values of i and index + i--; + index--; + } + } + + // If Y reaches its end, put remaining characters + // of X in the result string + while (i > 0) + { + str += (X.charAt(i - 1)); + i--; + index--; + } + + // If X reaches its end, put remaining characters + // of Y in the result string + while (j > 0) + { + str += (Y.charAt(j - 1)); + j--; + index--; + } + + // reverse the string and return it + str = reverse(str); + return str; + } + + static String reverse(String input) + { + char[] temparray = input.toCharArray(); + int left, right = 0; + right = temparray.length - 1; + + for (left = 0; left < right; left++, right--) + { + // Swap values of left and right + char temp = temparray[left]; + temparray[left] = temparray[right]; + temparray[right] = temp; + } + return String.valueOf(temparray); + } + + // Driver code + public static void main(String[] args) + { + String X = "geeke"; + String Y = "eke"; + System.out.println(printShortestSuperSeq(X, Y)); + } +} diff --git a/Algorithms/Strassen Algorithm.java b/Algorithms/Strassen Algorithm.java new file mode 100644 index 00000000..ae1ea3e0 --- /dev/null +++ b/Algorithms/Strassen Algorithm.java @@ -0,0 +1,153 @@ +import java.util.Scanner; + + +public class Strassen +{ + // Function to multiply matrices + public int[][] multiply(int[][] A, int[][] B) + { + int n = A.length; + int[][] R = new int[n][n]; + + /** base case **/ + if (n == 1) + R[0][0] = A[0][0] * B[0][0]; + else + { + int[][] A11 = new int[n/2][n/2]; + int[][] A12 = new int[n/2][n/2]; + int[][] A21 = new int[n/2][n/2]; + int[][] A22 = new int[n/2][n/2]; + int[][] B11 = new int[n/2][n/2]; + int[][] B12 = new int[n/2][n/2]; + int[][] B21 = new int[n/2][n/2]; + int[][] B22 = new int[n/2][n/2]; + + /** Dividing matrix A into 4 halves **/ + split(A, A11, 0 , 0); + split(A, A12, 0 , n/2); + split(A, A21, n/2, 0); + split(A, A22, n/2, n/2); + + + /** Dividing matrix B into 4 halves **/ + split(B, B11, 0 , 0); + split(B, B12, 0 , n/2); + split(B, B21, n/2, 0); + split(B, B22, n/2, n/2); + + /** + M1 = (A11 + A22)(B11 + B22) + M2 = (A21 + A22) B11 + M3 = A11 (B12 - B22) + M4 = A22 (B21 - B11) + M5 = (A11 + A12) B22 + M6 = (A21 - A11) (B11 + B12) + M7 = (A12 - A22) (B21 + B22) + **/ + + int [][] M1 = multiply(add(A11, A22), add(B11, B22)); + int [][] M2 = multiply(add(A21, A22), B11); + int [][] M3 = multiply(A11, sub(B12, B22)); + int [][] M4 = multiply(A22, sub(B21, B11)); + int [][] M5 = multiply(add(A11, A12), B22); + int [][] M6 = multiply(sub(A21, A11), add(B11, B12)); + int [][] M7 = multiply(sub(A12, A22), add(B21, B22)); + + /** + C11 = M1 + M4 - M5 + M7 + C12 = M3 + M5 + C21 = M2 + M4 + C22 = M1 - M2 + M3 + M6 + **/ + + int [][] C11 = add(sub(add(M1, M4), M5), M7); + int [][] C12 = add(M3, M5); + int [][] C21 = add(M2, M4); + int [][] C22 = add(sub(add(M1, M3), M2), M6); + + /** Joining 4 halves into one result matrix **/ + join(C11, R, 0 , 0); + join(C12, R, 0 , n/2); + join(C21, R, n/2, 0); + join(C22, R, n/2, n/2); + } + + /** Returning the resultant matrix **/ + return R; + } + + /** Funtion to add two matrices **/ + public int[][] add(int[][] A, int[][] B) + { + int n = A.length; + int[][] C = new int[n][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + C[i][j] = A[i][j] + B[i][j]; + return C; + } + + /** Funtion to subtract two matrices **/ + public int[][] sub(int[][] A, int[][] B) + { + int n = A.length; + int[][] C = new int[n][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + C[i][j] = A[i][j] - B[i][j]; + return C; + } + + /** Funtion to split parent matrix into child matrices **/ + public void split(int[][] P, int[][] C, int iB, int jB) + { + for(int i1 = 0, i2 = iB; i1 < C.length; i1++, i2++) + for(int j1 = 0, j2 = jB; j1 < C.length; j1++, j2++) + C[i1][j1] = P[i2][j2]; + } + + /** Funtion to join child matrices intp parent matrix **/ + public void join(int[][] C, int[][] P, int iB, int jB) + { + for(int i1 = 0, i2 = iB; i1 < C.length; i1++, i2++) + for(int j1 = 0, j2 = jB; j1 < C.length; j1++, j2++) + P[i2][j2] = C[i1][j1]; + } + + /** Main function **/ + public static void main (String[] args) + { + Scanner sc = new Scanner(System.in); + + /** Making an object of Strassen class **/ + Strassen s = new Strassen(); + + System.out.println("Enter the order of matrices (n) :"); + int N = sc.nextInt(); + + /** Accepting two 2d matrices **/ + System.out.println("Enter N*N order matrix 1\n"); + int[][] A = new int[N][N]; + for (int i = 0; i < N; i++) + for (int j = 0; j < N; j++) + A[i][j] = sc.nextInt(); + + System.out.println("Enter N*N order matrix 2\n"); + int[][] B = new int[N][N]; + for (int i = 0; i < N; i++) + for (int j = 0; j < N; j++) + B[i][j] = sc.nextInt(); + + int[][] C = s.multiply(A, B); + + System.out.println("\nProduct of matrices 1 and 2 is : "); + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + System.out.print(C[i][j] +" "); + System.out.println(); + } + + } +} \ No newline at end of file diff --git a/Algorithms/bubble_sort.java b/Algorithms/bubble_sort.java deleted file mode 100644 index 97b7f31d..00000000 --- a/Algorithms/bubble_sort.java +++ /dev/null @@ -1,32 +0,0 @@ -class BubbleSort -{ - void bubbleSort(int arr[]) - { - int n = arr.length; - for (int i = 0; i < n-1; i++) - for (int j = 0; j < n-i-1; j++) - if (arr[j] > arr[j+1]) - { - int temp = arr[j]; - arr[j] = arr[j+1]; - arr[j+1] = temp; - } - } - - void printArray(int arr[]) - { - int n = arr.length; - for (int i=0; i 1) + { + // Check if fibMm2 is a valid location + int i = min(offset+fibMMm2, n-1); + + /* If x is greater than the value at + index fibMm2, cut the subarray array + from offset to i */ + if (arr[i] < x) + { + fibM = fibMMm1; + fibMMm1 = fibMMm2; + fibMMm2 = fibM - fibMMm1; + offset = i; + } + + /* If x is less than the value at index + fibMm2, cut the subarray after i+1 */ + else if (arr[i] > x) + { + fibM = fibMMm2; + fibMMm1 = fibMMm1 - fibMMm2; + fibMMm2 = fibM - fibMMm1; + } + + /* element found. return index */ + else return i; + } + + /* comparing the last element with x */ + if(fibMMm1 == 1 && arr[offset+1] == x) + return offset+1; + + /*element not found. return -1 */ + return -1; + } + + // driver code + public static void main(String[] args) + { + int arr[] = {10, 22, 35, 40, 45, 50, + 80, 82, 85, 90, 100}; + int n = 11; + int x = 85; + System.out.print ("Found at index: "+ + fibMonaccianSearch(arr, x, n)); + } +} diff --git a/Algorithms/segmentedsieve.java b/Algorithms/segmentedsieve.java new file mode 100644 index 00000000..0383b845 --- /dev/null +++ b/Algorithms/segmentedsieve.java @@ -0,0 +1,79 @@ +import java.util.*; +public class segmentedsieve { + + static int MAX =10000001; + static ArrayList sieve() + { + boolean isp[]=new boolean[MAX]; + Arrays.fill(isp,true); + ArrayList primes=new ArrayList<>(); + for(int i=2;i*i primes) + { + long prod=1; + long p=1000000007; + + int base=0; + boolean pr[]=new boolean[r-l+1]; + Arrays.fill(pr,true); + int currprime=0; + for(int i=0;primes.get(i)*(long)primes.get(i)<=r;i++) + { + currprime=primes.get(i); + base=(l/currprime)*currprime; + if(base primes; + primes=sieve(); + for(int j=0;j + + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/.idea/gradle.xml b/Android/Android Apps/AgeCalculator/.idea/gradle.xml new file mode 100644 index 00000000..b9f8a5eb --- /dev/null +++ b/Android/Android Apps/AgeCalculator/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/.idea/jarRepositories.xml b/Android/Android Apps/AgeCalculator/.idea/jarRepositories.xml new file mode 100644 index 00000000..a5f05cd8 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/.idea/misc.xml b/Android/Android Apps/AgeCalculator/.idea/misc.xml new file mode 100644 index 00000000..7bfef59d --- /dev/null +++ b/Android/Android Apps/AgeCalculator/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/.idea/runConfigurations.xml b/Android/Android Apps/AgeCalculator/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/Android/Android Apps/AgeCalculator/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/README.md b/Android/Android Apps/AgeCalculator/README.md new file mode 100644 index 00000000..3abfdd1e --- /dev/null +++ b/Android/Android Apps/AgeCalculator/README.md @@ -0,0 +1,18 @@ +# Age Calculator App +The app takes date of birth and current date as input and show the age as result and tell days left to your next birthday. + +## Screenshots + + +## Concepts Used +- Text View +- Linear Layouts +- Calendar +- SimpleDateFormat +- Image View +- ViewBinding + +# Improvement +- UI can be improved +- add feature to calculate date difference between any two dates using same logic +- add feature to remember other birthdays and notify user diff --git a/Android/Android Apps/AgeCalculator/app/.gitignore b/Android/Android Apps/AgeCalculator/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/build.gradle b/Android/Android Apps/AgeCalculator/app/build.gradle new file mode 100644 index 00000000..3d80c953 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/build.gradle @@ -0,0 +1,45 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + applicationId "com.orangeink.agecalculator" + minSdkVersion 21 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + buildFeatures{ + viewBinding = true + } + + compileOptions { + sourceCompatibility = '1.8' + targetCompatibility = '1.8' + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + testImplementation 'junit:junit:4.13' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + + //Google Material + implementation 'com.google.android.material:material:1.2.1' + +} \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/proguard-rules.pro b/Android/Android Apps/AgeCalculator/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/androidTest/java/com/orangeink/agecalculator/ExampleInstrumentedTest.java b/Android/Android Apps/AgeCalculator/app/src/androidTest/java/com/orangeink/agecalculator/ExampleInstrumentedTest.java new file mode 100644 index 00000000..72026a00 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/androidTest/java/com/orangeink/agecalculator/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.orangeink.agecalculator; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.orangeink.agecalculator", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/AndroidManifest.xml b/Android/Android Apps/AgeCalculator/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..300ac3df --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/java/com/orangeink/agecalculator/AgeCalculator.java b/Android/Android Apps/AgeCalculator/app/src/main/java/com/orangeink/agecalculator/AgeCalculator.java new file mode 100644 index 00000000..47794ee4 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/java/com/orangeink/agecalculator/AgeCalculator.java @@ -0,0 +1,98 @@ +package com.orangeink.agecalculator; + +import java.util.Calendar; + +public class AgeCalculator { + + private int startYear, startMonth, startDay; + private int endYear, endMonth, endDay; + private int resYear, resMonth, resDay; + private int dayOfBirth; + + + public AgeCalculator(Calendar startCalendar, Calendar endCalendar) { + endYear = endCalendar.get(Calendar.YEAR); + endMonth = endCalendar.get(Calendar.MONTH); + endDay = endCalendar.get(Calendar.DAY_OF_MONTH); + startYear = startCalendar.get(Calendar.YEAR); + startMonth = startCalendar.get(Calendar.MONTH); + startDay = startCalendar.get(Calendar.DAY_OF_MONTH); + dayOfBirth = startCalendar.get(Calendar.DAY_OF_WEEK); + } + + public String getDayOfBirth() { + switch (dayOfBirth) { + case 1: + return "Sunday"; + case 2: + return "Monday"; + case 3: + return "Tuesday"; + case 4: + return "Wednesday"; + case 5: + return "Thursday"; + case 6: + return "Friday"; + case 7: + return "Saturday"; + default: + return ""; + } + } + + public void calculateYear() { + resYear = endYear - startYear; + } + + public void calculateMonth() { + if (endMonth >= startMonth) { + resMonth = endMonth - startMonth; + } else { + resMonth = endMonth - startMonth; + resMonth = 12 + resMonth; + resYear--; + } + } + + public void calculateDay() { + if (endDay >= startDay) { + resDay = endDay - startDay; + } else { + resDay = endDay - startDay; + resDay = 30 + resDay; + if (resMonth == 0) { + resMonth = 11; + resYear--; + } else { + resMonth--; + } + } + } + + public String getResult() { + calculateYear(); + calculateMonth(); + calculateDay(); + return resDay + ":" + resMonth + ":" + resYear; + } + + public String getNextBirthday() { + Calendar earlier = Calendar.getInstance(); + Calendar later = Calendar.getInstance(); + int currentDay, currentYear, currentMonth; + currentYear = earlier.get(Calendar.YEAR); + currentMonth = earlier.get(Calendar.MONTH); + currentDay = earlier.get(Calendar.DATE); + earlier.set(currentYear, currentMonth, currentDay); + if (earlier.get(Calendar.MONTH) >= later.get(Calendar.MONTH)) { + later.set(currentYear + 1, startMonth, startDay); + } else + later.set(currentYear, startMonth, startDay); + int earlierDays = earlier.get(Calendar.DAY_OF_YEAR); + int laterDays = later.get(Calendar.DAY_OF_YEAR); + long remain = earlierDays - laterDays; + return String.valueOf(remain); + } + +} diff --git a/Android/Android Apps/AgeCalculator/app/src/main/java/com/orangeink/agecalculator/MainActivity.java b/Android/Android Apps/AgeCalculator/app/src/main/java/com/orangeink/agecalculator/MainActivity.java new file mode 100644 index 00000000..7baac0ed --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/java/com/orangeink/agecalculator/MainActivity.java @@ -0,0 +1,121 @@ +package com.orangeink.agecalculator; + +import androidx.appcompat.app.AppCompatActivity; + +import android.annotation.SuppressLint; +import android.app.DatePickerDialog; +import android.os.Bundle; +import android.view.View; +import android.widget.DatePicker; +import android.widget.TextView; +import android.widget.Toast; + +import com.orangeink.agecalculator.databinding.ActivityMainBinding; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; +import java.util.Objects; +import java.util.TimeZone; +import java.util.concurrent.TimeUnit; + +public class MainActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener { + + private ActivityMainBinding binding; + private boolean isDob; + private Calendar dobCalendar, dateCalendar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = ActivityMainBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + initViews(); + } + + private void initViews() { + Objects.requireNonNull(getSupportActionBar()).hide(); + setupDate(Calendar.getInstance(TimeZone.getDefault()), binding.tvDate); + dateCalendar = Calendar.getInstance(TimeZone.getDefault()); + binding.tvDob.setOnClickListener(v -> { + isDob = true; + openDatePicker(); + }); + binding.tvDate.setOnClickListener(v -> { + isDob = false; + openDatePicker(); + }); + binding.btnClear.setOnClickListener(v -> clear()); + binding.btnCalculate.setOnClickListener(v -> { + if (binding.btnCalculate.getText().toString().equalsIgnoreCase(getString(R.string.calculate))) + calculateAge(); + else + clear(); + }); + } + + private void clear() { + if (binding.btnClear.getVisibility() == View.GONE) + binding.btnClear.setVisibility(View.VISIBLE); + dateCalendar = Calendar.getInstance(TimeZone.getDefault()); + binding.tvCalculate.setText(getString(R.string.calculate)); + binding.tvYourAge.setText(getString(R.string.your_today_s_age)); + binding.tvDob.setText(getString(R.string.dd_mm_yyyy)); + setupDate(Calendar.getInstance(TimeZone.getDefault()), binding.tvDate); + binding.tvHeadingDob.setVisibility(View.VISIBLE); + binding.tvDob.setVisibility(View.VISIBLE); + binding.tvAge.setVisibility(View.GONE); + binding.tvHeadingDate.setVisibility(View.VISIBLE); + binding.tvDate.setVisibility(View.VISIBLE); + binding.tvNextBirthday.setVisibility(View.GONE); + } + + @SuppressLint("SetTextI18n") + private void calculateAge() { + if (binding.tvDob.getText().toString().equalsIgnoreCase(getString(R.string.dd_mm_yyyy))) { + Toast.makeText(this, "Enter your date of birth!", Toast.LENGTH_SHORT).show(); + return; + } + AgeCalculator ageCalculator = new AgeCalculator(dobCalendar, dateCalendar); + String[] age = ageCalculator.getResult().split(":"); + binding.tvCalculate.setText(R.string.today_you_re); + binding.tvYourAge.setText(age[2] + " years old"); + binding.btnClear.setVisibility(View.GONE); + binding.btnCalculate.setText(R.string.calculate_again); + binding.tvAge.setText("Your age (" + dobCalendar.get(Calendar.YEAR) + " - present )\nDAY OF BIRTH- " + ageCalculator.getDayOfBirth() + "\n" + age[2] + " years " + age[1] + " months " + age[0] + " days"); + binding.tvNextBirthday.setText("Your next birthday is in\n" + ageCalculator.getNextBirthday() + " days"); + binding.tvHeadingDob.setVisibility(View.GONE); + binding.tvDob.setVisibility(View.GONE); + binding.tvAge.setVisibility(View.VISIBLE); + binding.tvHeadingDate.setVisibility(View.GONE); + binding.tvDate.setVisibility(View.GONE); + binding.tvNextBirthday.setVisibility(View.VISIBLE); + } + + private void openDatePicker() { + Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); + DatePickerDialog dialog = new DatePickerDialog(this, this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); + dialog.show(); + } + + @Override + public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { + Calendar myCalendar = Calendar.getInstance(TimeZone.getDefault()); + myCalendar.set(Calendar.YEAR, year); + myCalendar.set(Calendar.MONTH, month); + myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); + if (isDob) { + setupDate(myCalendar, binding.tvDob); + dobCalendar = myCalendar; + } else { + setupDate(myCalendar, binding.tvDate); + dateCalendar = myCalendar; + } + } + + private void setupDate(Calendar calendar, TextView tv) { + String myFormat = "dd-MM-yyyy"; //Date Format + SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.ENGLISH); + tv.setText(sdf.format(calendar.getTime())); + } +} \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..5c3bfcd6 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/age_pic.png b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/age_pic.png new file mode 100644 index 00000000..8eb67ae0 Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/age_pic.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_age_text.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_age_text.xml new file mode 100644 index 00000000..ee55f07b --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_age_text.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_calculate_button.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_calculate_button.xml new file mode 100644 index 00000000..cd7a6753 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_calculate_button.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_clear_button.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_clear_button.xml new file mode 100644 index 00000000..22c3bec1 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_clear_button.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_edit_text.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_edit_text.xml new file mode 100644 index 00000000..caa7bb1f --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/bg_edit_text.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_launcher_background.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..140f8294 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_outline_account_circle_24.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_outline_account_circle_24.xml new file mode 100644 index 00000000..3c6b8ac4 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_outline_account_circle_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_outline_calendar_today_24.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_outline_calendar_today_24.xml new file mode 100644 index 00000000..4fa8eb4d --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/drawable/ic_outline_calendar_today_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/layout/activity_main.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..aecc6def --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..03eed253 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 00000000..03eed253 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-hdpi/ic_launcher.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..a571e600 Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 00000000..61da551c Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-mdpi/ic_launcher.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..c41dd285 Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 00000000..db5080a7 Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..6dba46da Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 00000000..da31a871 Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..15ac6817 Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 00000000..b216f2d3 Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..f25a4197 Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 00000000..e96783cc Binary files /dev/null and b/Android/Android Apps/AgeCalculator/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/values-v23/styles.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/values-v23/styles.xml new file mode 100644 index 00000000..03ce8f50 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/values-v23/styles.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/values/colors.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..a3b62475 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/values/colors.xml @@ -0,0 +1,7 @@ + + + #3E6825 + #FAF5EF + #FEDC5F + #DAE0C6 + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/values/strings.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..c4e9b771 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/values/strings.xml @@ -0,0 +1,10 @@ + + Age Calculator + Calculate + your today\'s age + Enter your date of birth + dd-mm-yyyy + Age at the date of + Calculate again + Today you\'re + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/main/res/values/styles.xml b/Android/Android Apps/AgeCalculator/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..b61e0249 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/main/res/values/styles.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/app/src/test/java/com/orangeink/agecalculator/ExampleUnitTest.java b/Android/Android Apps/AgeCalculator/app/src/test/java/com/orangeink/agecalculator/ExampleUnitTest.java new file mode 100644 index 00000000..73dfd48d --- /dev/null +++ b/Android/Android Apps/AgeCalculator/app/src/test/java/com/orangeink/agecalculator/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.orangeink.agecalculator; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/build.gradle b/Android/Android Apps/AgeCalculator/build.gradle new file mode 100644 index 00000000..6754c23d --- /dev/null +++ b/Android/Android Apps/AgeCalculator/build.gradle @@ -0,0 +1,24 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + google() + jcenter() + } + dependencies { + classpath "com.android.tools.build:gradle:4.0.1" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/gradle.properties b/Android/Android Apps/AgeCalculator/gradle.properties new file mode 100644 index 00000000..c52ac9b7 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/gradle.properties @@ -0,0 +1,19 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true \ No newline at end of file diff --git a/Android/Android Apps/AgeCalculator/gradle/wrapper/gradle-wrapper.properties b/Android/Android Apps/AgeCalculator/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..5edc4e94 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sun Oct 04 20:40:15 IST 2020 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/Android/Android Apps/AgeCalculator/gradlew b/Android/Android Apps/AgeCalculator/gradlew new file mode 100644 index 00000000..cccdd3d5 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/Android/Android Apps/AgeCalculator/gradlew.bat b/Android/Android Apps/AgeCalculator/gradlew.bat new file mode 100644 index 00000000..f9553162 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/Android/Android Apps/AgeCalculator/settings.gradle b/Android/Android Apps/AgeCalculator/settings.gradle new file mode 100644 index 00000000..3b73e0b1 --- /dev/null +++ b/Android/Android Apps/AgeCalculator/settings.gradle @@ -0,0 +1,2 @@ +include ':app' +rootProject.name = "Age Calculator" \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/.gitattributes b/Android/Android Apps/BMI Calculator/.gitattributes new file mode 100644 index 00000000..dfe07704 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/Android/Android Apps/BMI Calculator/.gitignore b/Android/Android Apps/BMI Calculator/.gitignore new file mode 100644 index 00000000..23de6e20 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/.gitignore @@ -0,0 +1,88 @@ +# Built application files +*.apk +*.aar +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ +# Uncomment the following line in case you need and you don't have the release build type files in your app +# release/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +# Android Studio 3 in .gitignore file. +.idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild +.cxx/ + +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +# Android Profiling +*.hprof diff --git a/Android/Android Apps/BMI Calculator/.idea/.name b/Android/Android Apps/BMI Calculator/.idea/.name new file mode 100644 index 00000000..34a07738 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/.idea/.name @@ -0,0 +1 @@ +BMI Calculator \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/.idea/codeStyles/Project.xml b/Android/Android Apps/BMI Calculator/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..681f41ae --- /dev/null +++ b/Android/Android Apps/BMI Calculator/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/.idea/jarRepositories.xml b/Android/Android Apps/BMI Calculator/.idea/jarRepositories.xml new file mode 100644 index 00000000..a5f05cd8 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/.idea/misc.xml b/Android/Android Apps/BMI Calculator/.idea/misc.xml new file mode 100644 index 00000000..37a75096 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/.idea/runConfigurations.xml b/Android/Android Apps/BMI Calculator/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/Android/Android Apps/BMI Calculator/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/README.md b/Android/Android Apps/BMI Calculator/README.md new file mode 100644 index 00000000..07af1040 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/README.md @@ -0,0 +1,18 @@ +# BMI Calculator App +The app takes height and weight as input and show the BMI result and tell BMI report. + +## Screenshots +![rsz_screenshot_1601812229](https://user-images.githubusercontent.com/36789334/95015095-edc0c400-066c-11eb-95d3-ae52eac1af95.png) +![rsz_screenshot_1601812252](https://user-images.githubusercontent.com/36789334/95015125-26609d80-066d-11eb-9e5d-aa17f914f374.png) + +## Concepts Used +- Text View +- Scroll View +- Edit Text +- Button +- Image View + +# Improvement +- make the UI more responsive +- add suggestion guide as per BMI value +- add various scale of height and weight diff --git a/Android/Android Apps/BMI Calculator/app/.gitignore b/Android/Android Apps/BMI Calculator/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/app/build.gradle b/Android/Android Apps/BMI Calculator/app/build.gradle new file mode 100644 index 00000000..f6326940 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + + defaultConfig { + applicationId "com.example.bmicalculator" + minSdkVersion 19 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + +} \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/app/proguard-rules.pro b/Android/Android Apps/BMI Calculator/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/app/src/androidTest/java/com/example/bmicalculator/ExampleInstrumentedTest.java b/Android/Android Apps/BMI Calculator/app/src/androidTest/java/com/example/bmicalculator/ExampleInstrumentedTest.java new file mode 100644 index 00000000..fa14e9a8 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/src/androidTest/java/com/example/bmicalculator/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.bmicalculator; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.bmicalculator", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/app/src/main/AndroidManifest.xml b/Android/Android Apps/BMI Calculator/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..02f7485e --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/app/src/main/java/com/example/bmicalculator/MainActivity.java b/Android/Android Apps/BMI Calculator/app/src/main/java/com/example/bmicalculator/MainActivity.java new file mode 100644 index 00000000..1b316814 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/src/main/java/com/example/bmicalculator/MainActivity.java @@ -0,0 +1,51 @@ +package com.example.bmicalculator; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity { + + EditText etHeight,etWeight; + Button btnSubmit; + TextView tvResult; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + etHeight=findViewById(R.id.etHeight); + etWeight=findViewById(R.id.etWeight); + btnSubmit=findViewById(R.id.btnSubmit); + tvResult=findViewById(R.id.tvResult); + + btnSubmit.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String H=etHeight.getText().toString().trim(); + String W=etWeight.getText().toString().trim(); + double height=Double.parseDouble(H); + double weight=Double.parseDouble(W); + if(H.equals("") || W.equals("")) { + Toast.makeText(MainActivity.this,"please fill the data",Toast.LENGTH_SHORT).show(); + } else { + String predict,bmiResult; + height=height/100.0; + double bmiCal = weight/(height*height); + bmiResult=String.format("%.2f",bmiCal); + if(bmiCal<18.5) predict="Underweight"; + else if(bmiCal>=18.5 && bmiCal<25) predict="Normal"; + else if(bmiCal>=25 && bmiCal<30) predict="Overweight"; + else predict="Obese"; + tvResult.setText("Your BMI is "+bmiResult+"("+predict+")"); + } + } + }); + } +} diff --git a/Android/Android Apps/BMI Calculator/app/src/main/res/drawable-v24/bmi.png b/Android/Android Apps/BMI Calculator/app/src/main/res/drawable-v24/bmi.png new file mode 100644 index 00000000..5dbed980 Binary files /dev/null and b/Android/Android Apps/BMI Calculator/app/src/main/res/drawable-v24/bmi.png differ diff --git a/Android/Android Apps/BMI Calculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Android/Android Apps/BMI Calculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..2b068d11 --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Android/Android Apps/BMI Calculator/app/src/main/res/drawable/ic_launcher_background.xml b/Android/Android Apps/BMI Calculator/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..07d5da9c --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Android/Android Apps/BMI Calculator/app/src/main/res/layout/activity_main.xml b/Android/Android Apps/BMI Calculator/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..ce73126b --- /dev/null +++ b/Android/Android Apps/BMI Calculator/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + +