Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

looking for correct commands  RSS feed

 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im a student CIS Major at an University taking a Java 211 course at the moment.  Although I had one semester of beginners Java 104 , all my instructor taught and focused was on for loops. 

I have a few projects to work on, but this one right now its a very simple project, and I want to make it myself, but I need a little kick start to know what commands to research.

Basically I have my first Line saying " Want to see how hello is said in another language? Press (f) for French, (s) for Spanish, (v) for Vietnamaese: "

What I want to code to do is detect the input from the person.. if they press f it will return Bonjour, if they press s it will return Hola, if they press v it will return Chao

So far from my research, I figured out I need to import scanner
i have scanner in= new Scanner(System.in)

Will i need to use string command and define what f , s, v will do when a person hits that key ?

I want to figure out how to put it all together myself, but I just need some basic help with what commands I should be researching to make this .  Simple, nothing complex.  Any help in the right direction would be appreciated.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy and welcome

Scanner is indeed one of the API you need to look into. Since you working with multiple language, you may want to look into ResourceBundle, rather than hard-coding the French "Bonjour".

By the way, command isn't the correct term, it's API.
 
Junilu Lacar
Sheriff
Posts: 11153
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

It's a bit appalling that you could complete a semester of Java programming and be this much in the dark still although I'm not surprised because my son, who is also in the CIS program at The Ohio State University, is not much better off.

You would use either a series of if-then-else statements or a switch statement to control the execution flow based on the user's choice.

The Java Tutorials will shed some light on what you need to do.
 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Welcome to the Ranch!

It's a bit appalling that you could complete a semester of Java programming and be this much in the dark still although I'm not surprised because my son, who is also in the CIS program at The Ohio State University, is not much better off.

You would use either a series of if-then-else statements or a switch statement to control the execution flow based on the user's choice.

The Java Tutorials will shed some light on what you need to do.


I am also appalled.  We use the book " Java for Everyone by Cay Horstmann.  This book is ridiculous, it was never an easy read for me. I am lost the entire time I read it. Our professor is about 70 years old and really knows his code, but he gets stuck on For Loops, and just stressed that the entire semester.  Then toward the end he had us go to a website like CodingBat and have us try the problems on there.  I dont know any of the commands they were using on that thing.
The only other thing that I learned was how to draw lines, rect, circles, poly.. add some color, make some clouds out of circles using a forloop.. just simple stuff.

My Major is CIS with a specialization in Networking/Cyber Security.

The class is bad, but on a brighter note he is extremely hilarious.


I will look at the website you linked.  As for the the If then else statements.. I am guessing some kind of code that If input is F then print bonjour. Else print nothing...  etc.. I will figure something out
 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is what I have made.  It works fine as long as you input one of those 3 letters, and its its something else it prints that last line..  How ever my next thing will be how to figure out to keep the program running.. I dont want it to end when I hit a letter and enter.  I want to be able to hit f, then the first line saying what it does.. press f, s, v .. etc.. so I dont have to keep closing out the program and rerunning it again.
 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it to do what I want.. just had ot use what the instructor last year made us do all the time. a For Loop

Final code.. Im done and I am happy..
 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about adding "(x) exit"?
 
Junilu Lacar
Sheriff
Posts: 11153
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
damon greenfield wrote:I got it to do what I want.. just had ot use what the instructor last year made us do all the time. a For Loop

Final code.. Im done and I am happy..

Sorry to rain on your parade but you shouldn't be. Having one semester of Java programming under your belt and not knowing about if-then-else and while-loop is atrocious. Your CIS department chair should be informed about this. You're basically like a 3rd grader who is at a kindergarten level of reading and writing. This is both a disservice to the students and the school.

As Carey pointed out, you should have an option to exit. The for-loop you used is not appropriate since it will execute 99 times at which point it will  unceremoniously terminate whether you want it to or not. That you probably would want to terminate well before 99 iterations anyway is beside the point. The point is that the program won't exit when you, the user, want it to exit. (Challenge: why will the for-loop iterate only 99 times instead of 100 times?)

You should use a while-loop with an appropriate termination condition.
 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:
damon greenfield wrote:I got it to do what I want.. just had ot use what the instructor last year made us do all the time. a For Loop

Final code.. Im done and I am happy..

Sorry to rain on your parade but you shouldn't be. Having one semester of Java programming under your belt and not knowing about if-then-else and while-loop is atrocious. Your CIS department chair should be informed about this. You're basically like a 3rd grader who is at a kindergarten level of reading and writing. This is both a disservice to the students and the school.

As Carey pointed out, you should have an option to exit. The for-loop you used is not appropriate since it will execute 99 times at which point it will  unceremoniously terminate whether you want it to or not. That you probably would want to terminate well before 99 iterations anyway is beside the point. The point is that the program won't exit when you, the user, want it to exit. (Challenge: why will the for-loop iterate only 99 times instead of 100 times?)

You should use a while-loop with an appropriate termination condition.


The challenge for the forloop is easy.. its starting at 1, and going up 1 each time, it will stop at 99 because i told it <100.
As i said before my first semester was pretty much nothing but for loops.
The point of the exercise was to get a program to work.  Its not the most effective, but it works and until I learn more, this will suffice for my homework to turn in.
 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also , it sucks that he is the only teacher that teaches Java 104, and 211.. There is no one else i can take it from.  This is his website with his credentials. http://webpages.shepherd.edu/JROMANO/

If you look at Shepherd University ( WV) and see their class schedule, you can see he is the only one who teaches it.

https://oas3.shepherd.edu/prod/schedule?cterm=201630&csubj=CIS&clevl=&ccamp=

After this semester, it is very likely that I will be moving to Maryland with my wife, and I will apply for Fort Hood College, which looks like it has a much better CIS program.
 
Junilu Lacar
Sheriff
Posts: 11153
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
damon greenfield wrote:The point of the exercise was to get a program to work.  Its not the most effective, but it works and until I learn more, this will suffice for my homework to turn in.

That's fine.

But just to give this dead horse a final whip, that the program "works" is debatable. It runs, sure, but does it really perform correctly? How do you terminate the program gracefully? There's no way that program terminates gracefully as it's written. What if the user enters a valid letter in response, except it's a capital letter? Right now, your program only accepts lowercase letters. And what if the user wants to continue running the program more than 99 times? Right now it will stop after the 99th time.

If this is good enough to get the grade, that's fine. I'd encourage you to figure out the answers to the above questions though and try to raise the bar on your definition of "works". It will only help you and others who have to work with the code that you write in the future. As a professional developer, I see all kinds of code that just "kinda works" and these are more often the parts of the application that are the most troublesome. And I'm usually the one left holding the bag and doing cleanup duty.

Good luck.
 
Liutauras Vilda
Marshal
Posts: 4650
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
damon greenfield wrote:We use the book " Java for Everyone by Cay Horstmann.  This book is ridiculous, it was never an easy read for me. I am lost the entire time I read it.
I'm surprised you didn't like that book. That is my favourite for the beginners with an extensive explanations and full bunch of exercises.

Some extra comments on a current program you wrote, which might could lose you some points:
1. Class names supposed to start with an upper case.
2. Variable names should not be separated with an underscore, unless it is a constant. "user_input" should read as "userInput".
3. Indentation is inconsistent as it uses two different braces placing styles (choose one):

And Junilu is absolutely right, better not to blame the professor but rather set the bar higher by yourself.
Consider getting book "Clean Code" by Robert C. Martin, Junilu recommended it me some time ago, and I really liked it. That could change the way you think about the "works" idiom.
 
Liutauras Vilda
Marshal
Posts: 4650
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch, nice to see you here
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!