• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help with advice on how to solve this  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am changing my career path and I found a MS in IT for no computer background. I've just started my coding endeavor and its name is Java. I've never coded before and this is my 4th coding week. The book is overwhelming because it's not explaining much. Can someone please advise how I should approach this homework? Thank you very much!

The following critical elements will be addressed in this submission:

Data Structure for Message Storage:

1. Storing the Array: Write an application that uses an Array to store 10messages of type String. You will store this Array with 10 messages of your choosing. For example, a message could be “I love Java the programming language!” or another message could be “I love Java the drink!”
2. Initializing the Array: You may initialize your Array with the messages or have the user enter the messages. The choice is yours. Your Java code will contain a method called
shoutOutCannedMessage() that will loop through the Array to iterate through your entire list and display each message and allow the user to select one. The shoutOutCannedMessage() will return the selected message String.

I managed to loop the array messages but I cannot have the subsequent methods be read and I cannot retrieve user input. My brain is on fire.
 
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Sabina

Can you post the code you have tried so far? We should be able to advise more then. Please use the code tags as well, makes it a lot easier to read.

Ash
 
Sabina Strat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I've done so far:

 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!


Line 21 declares an array variable message and allocates enough room for 10 strings.
Line 22 to 31 declares another array variable Message and assigns it an array that has 1 single string in it. Do you understand why this is so?

Case matters in Java. That means that the names message and Message are two different variables. Also, by convention, variables names start with a lowercase letter. Class names start with an uppercase letter.


 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by properly declaring your array. Also, i would not recommend naming two variables the same name with deferent capitalization. It will just confuse you. Which i think it already has based on your code As they look like they are supposed to be the same variable.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good that you're trying to break up the program into small chunks by using methods. However, methods will not be automatically executed. They have to be called/invoked. In the code that you showed us, you define the methods choseMessage and shoutOutCannedMessage but you never invoke them.
 
Sabina Strat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, guys!
As y'all can see, I'm struggling. It is a lot of information that I have to digest on my own because my school is fully online and the professor only takes questions. I hope that this forum will help me understand Java.
 
Ash Jon
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I've given you a bit of code to work with, please read the comments on it carefully.



An updated while loop to work with:



If you don't understand anything here, please let me know and I will try to expand on the topics. Remember, this doesn't work yet (it does, but it doesn't choose which message to display)
I've probably expanded more than I should have here (Not doing someone's homework rule!), but I think this gives you a good base to work from. As you're making a career change, I have no doubt you will try and see why it works

Also, this is just one way to implement this, which I think is the easiest and most convenient at the moment based it on your requirements.

Hope it helps
 
Sabina Strat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ash Jon

Thank you! You gave me a lot of valuable information and more help that I would have dared to ask for. I can't wait to work on this code!

The book that we are using is Big Java Late Objects by Cay Horstmann and so far, we had to study loops, arrays, just 4 pages of classes and objects, if statements, and booleans. No methods whatsoever. I don't find this book to be helpful. I just need simple, clarifying information like you have provided me with in your comments.
"
 
Ash Jon
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's no problem Happy to help.

As you're completely new to the world of programming, I would advise you to check out a youtube user called Bucky: https://www.youtube.com/watch?v=Hl-zzrqQoSE&list=PL484D73FA74A11AC9 .

It will help a lot with the fundamentals of Java, including how to use methods correctly. Sometimes it's easier to grasp a concept when you see it being taught (as you would in a classroom) rather than a book. Use both and you should do fine

I'm new to this forum myself (and to Java. C#, PHP etc background), but it is amazingly friendly, so please, if you need help with anything, just ask, we'll be more than happy to help and before long you'll be the one helping others

Ash
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sabina Strat wrote:
The book that we are using is Big Java Late Objects by Cay Horstmann

The book is actually pretty good. We even had Cay here just a week or so ago as a guest author to promote one of his books, Java 8 for the Impatient.

In the Big Java Late Objects book, Chapter 5 is all about methods. First, I suggest you look at Chapter 4, section 4.6, about storyboarding. This is what I do when I have a problem to solve. I teach other developers at my work and I often tell them that a program is nothing more than a story of what we think is happening in the system. To write a good program, that is, to tell the story well, you have to organize your thoughts and you have to organize all the actions and actors in your story. How well this organization is planned and carried out is called "design". Design and programming are very tightly intertwined activities and there is one school of thought that believes that coding is actually a design activity, not "implementation" as is traditionally taught. I am, of course, a student of this school of thought.
 
Sabina Strat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Junilu Lacar

Thank you very much for the advice!
I like this forum a lot and I guess I am going to ask a lot of theory questions.
About the book... Let me put it this way: I am not at its level. I need a dumb down book. I read Big Java and I'm freaking out going blank.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!