Giter VIP home page Giter VIP logo

android_collections's Introduction

Android_Collections

This project will help you practice the skills and concepts you learned related to collections in Java. For this project you'll build an app with a text field for the user to enter a word. When they tap the button, the app will look for synonyms for the entered word, and will display them in a text view if any are found.

A synonym is a word with the same meaning as another word. For example, difficult and hard are synonyms.

Create an Android Studio Project

  1. Create a new Android project
  2. Name the project "Thesaurus"
  3. Make sure you select Kotlin as the development language

Add UI Elements to activity_main.xml

  1. Open the app's activity_main.xml file.
  2. Add a edit text field to the main screen
  3. Add a button to the main screen
  4. Make the button's text "Show Synonyms"
  5. Add a text view to the screen.
  6. Add ids to all the elements

Create Listeners

  1. Create an onClickListener for the button in the MainActivity.kt file.

Write A Thesaurus Lookup Function

  1. In MainActivity.kt, create a variable that is a 2 dimensional String array where each element is an array of strings that are synonyms of the key word.
  2. If you need help getting started, you can copy and paste the list found here. Feel free to add any additional words that you'd like.
  3. In this file, create a function called synonyms. It should take a single string as an argument, and return a array of String objects.

The return type should be Array<String>? so you can return a null array if there isn't a list of synonyms

  1. Write the synonyms function. It should return an array of strings that are synonyms for the passed in string, or null if there are no synonyms.
  2. Use a for loop to step through the top level array and look for the string in the first element of each element array.

Implement The User Interface

  1. In the listener for the "Show Synonyms" button, get the string entered in the text field, look up synonyms for it using your synonyms function, and if any synonyms are found, display them in the text view.
  2. Be sure to combine the strings in the array into a single string to be displayed in the text view.

Build, Run, and Test Your App

  1. Build and run your app using your preferred testing environment.
  2. Enter various words, including those you know are in your synonyms directory, and others that aren't into the text field and make sure the synonym listing works.

Bonus

If you finish and want another challenge try making it so that if a any word in the element array is equivalent to the value entered, that all its sibling synonyms are found and returned.

For example, if your synonyms array were:

val synonyms = arrayOf(arrayOf("learn", "determine", "master", "study", "get", "grasp")))

and the user entered "study", the app should output "determine", "master", "get", "grasp", and "learn".

android_collections's People

Contributors

chancepayne avatar

Stargazers

Danielle P avatar

Watchers

James Cloos avatar Austen Allred avatar  avatar Amanda Ellis avatar

android_collections's Issues

Your synonym list isn't a double array ...

Here's one from Swift (iOS) :
import Foundation
let synonyms = [
"swift" : ["abrupt", "expeditious", "hasty", "nimble", "quick", "rapid", "speedy", "sudden", "unexpected"],
"objective" : ["detached", "disinterested", "dispassionate", "equitable", "evenhanded", "nonpartisan", "open-minded", "unbiased"],
"calculate" : ["adjust", "appraise", "consider", "count", "determine", "forecast", "gauge", "guess", "measure", "multiply", "reckon", "subtract", "tally", "weigh", "work out"],
"create" : ["build", "conceive", "constitute", "construct", "design", "devise", "discover", "establish", "forge", "form"],
"programming" : ["formulate","itemize","process","schedule", "set", "compute", "compile", "plan out", "supply instructions"],
"storyboard" : ["outline", "representation", "design", "layout", "sketch"],
"start" : ["begin", "commence", "takeoff", "day one", "first step", "square one", "dawn", "kickoff", "inception"]]
Note the synonym word is separate from the synonym list.
There's no distinction between what is to be the synonym in your case and the words to output.
I guess I don't understand since you have a double array but only declare one set of elements.
Suggest maybe the following:
String[][] synonyms = new String[][] { {"swift"}{"abrupt"}, {"swift"}{"expeditious"}, {"swift"}{"hasty"}, {"swift"}{"nimble"}, {"swift"}{"quick"}, {swift}{"rapid"}, {"swift"}{"speedy"}, {"swift"}{"sudden"}, {"swift"}{"unexpected"}};
or maybe ...
String[][] synonyms = new String[][] { {"objective"}{"detached", "disinterested", "dispassionate", "equitable", "evenhanded", "nonpartisan", "open-minded", "unbiased"}};

I uninstalled and reinstalled android studio. Still can't see any buttons/text fields no matter which phone skin I try and which emulator I try to use (x86 ones crash). Blame Windows 10 Home and an AMD processor (different from Intel).

And since I'm rambling anyway, a note on design.
The file handling the i/o should be separate from the calculation. In this case you should have a separate file for the synonym routine. Where I used to work we put everything into small functional chunks so that we wouldn't exceed a McCabe complexity of greater than 10, and when we made a change we wouldn't need to test things irrelevant to the scope of the change.

I knew nothing about apps before I took the Lambda iOS prep course, so I'm not much of a resource.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.