Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Help with accepts user inputs?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Create a java program that accepts user inputs specially full name and favorite motto/bible verse or any sentence, the program must return character statistics, encrypted code, total numbers of words, character count, and character without spaces. full name format must be in firstname middleinitial surname as shown in the sample output below. the encryption rule is for vowels -1 (e = d), and for consonants +1 (g=h).

sample output
enter full name: Juan P. Pedro
enter motto or bible verse: The quick brown fox jumps over the lazy dog
--------------------------------------------------------------------------------
Character Statistic
T - 1
h - 2
e - 3
  - 8
q - 1
u - 2
i - 1
c - 1
k - 1
b - 1
r-2
o-4
w-1
n-1
f-1
x-1
j-1
m-1
p-1
s-1
v-1
t-1
l-1
a-1
z-1
y-1
d-1
g-1
Encrypted code: Uod!rthdl!csnxo!gny!ktnqt!nwds!uid!m`{z!enht
total number of words: 9
Character count: 43
Characters count without spaces: 35

heres my code and im stuck here i dont know what the next is



i dont know how to get the encrpytion and the statistic is not accurate about what is needed like the i and the spaces it should be 1 per letters in statistic but my output has 2 i  in "time is gold" like this
t 1
i 2
m 1
e 1
 2
i  2
s 1
 2
g 1
o  1
l  1
d  1
please help me thank you
 
Marshal
Posts: 71760
312
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Afraid you have put the cart before the horse. Write down the algorithm you are going to use for one part of the assignment. You shouldn't write any code before you have decided what you are going to do. Don't try to do the whole assignment all at once.
 
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not tracking which letters you've already counted.

Hint: sort 'c'

But still follow Campbell's advice and work it out with pencil and paper first.
 
Bartender
Posts: 2783
135
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see a small flaw in the encryption algorithm itself. If you subtract 1 from vowels and add one to consonants, how will the decryption algorithm work ?
e.g  Both "c" and "e" would result in "d".
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:I see a small flaw in the encryption algorithm itself. If you subtract 1 from vowels and add one to consonants, how will the decryption algorithm work ?
e.g  Both "c" and "e" would result in "d".



yeah that's what he wanted, my teacher give this and yet he doesnt teach us how to do it so, my head hurts aha.. can you give me a little help? im so confuse a
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:You are not tracking which letters you've already counted.

Hint: sort 'c'

But still follow Campbell's advice and work it out with pencil and paper first.



sorry im confuse, im just new to java, and my teacher did'nt taught us about encrpytion, thanks for your answer.
 
Marshal
Posts: 26309
80
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:I see a small flaw in the encryption algorithm itself.



True... but the requirements (at least those posted here) don't say anything about decryption. So that isn't a problem.
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Afraid you have put the cart before the horse. Write down the algorithm you are going to use for one part of the assignment. You shouldn't write any code before you have decided what you are going to do. Don't try to do the whole assignment all at once.



sorry i don't get it. hehe. the other algorithm is not given, he just gave this and we don't even know how to do it, sorry but i'm just new to java, i am nobody but a scratch in java. thanks btw for the comment and advice
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

salvin francis wrote:I see a small flaw in the encryption algorithm itself.



True... but the requirements (at least those posted here) don't say anything about decryption. So that isn't a problem.



yeah, and the encrpytion is my only problem now and a little bit in statistic . im just figuring out the statistic what could be is missing.
 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yan cle wrote:

Carey Brown wrote:You are not tracking which letters you've already counted.

Hint: sort 'c'

But still follow Campbell's advice and work it out with pencil and paper first.



sorry im confuse, im just new to java, and my teacher did'nt taught us about encrpytion, thanks for your answer.


I was referring to your character counts, not the encryption.
 
salvin francis
Bartender
Posts: 2783
135
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:... don't say anything about decryption. So that isn't a problem.


Yes, but it does strike out like a sore thumb to me.

yan cle wrote:... yeah, and the encrpytion is my only problem now and a little bit in statistic . im just figuring out the statistic what could be is missing.


I would take a step back and read through all comments here. You have been told to write down the algorithm that you are going to use for the the assignment part by part. Have you done that ? Can you share that with us ?
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i didn't write anything i'm just typing and coding sorting out how would i do it, i didnt do any writing and thinking about it, because i really dont know the code or what to use, some of the code he taught us but the statistic he doesnt taught us, or what the code to be use, he just give us this and say use our logic but then again not giving a reviewer, or anything he just want us to make the out on ourself, but here is the problem, i dont know the java coding, im just a newbie and noob about java. sorry, that's, yeah its a self taught code, not because he gives us that code.
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

yan cle wrote:

Carey Brown wrote:You are not tracking which letters you've already counted.

Hint: sort 'c'

But still follow Campbell's advice and work it out with pencil and paper first.



sorry im confuse, im just new to java, and my teacher did'nt taught us about encrpytion, thanks for your answer.


I was referring to your character counts, not the encryption.



what should i do then. i am willing to learn. can you help me?
 
Master Rancher
Posts: 4107
37
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what should i do then


Stop trying to write java code.  Work with some physical tools like paper and pencil  or a deck of cards and some buckets to put the cards in as they are counted.
Work out the steps a program needs to take to solve the problem.   Once you have a list of steps that will solve, the problem, then look at writing the code that follows those steps.

The description of what the program must do lists several requirements.  Choose one of them to work on first.  When you have solved that, them move to the next one.
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks im just new, but i will do your advice thank you
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but because i go this site is to have an idea, what is the code is. or what to use. aha
 
Campbell Ritchie
Marshal
Posts: 71760
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yan cle wrote:. . . what to use. . . .

Your brain. That is what people mean about thinking about it. You need to think with paper pencil and eraser (the latte needs to be large because you will use it often), or buckets, or something. The one thing you won't be able to do is write code that will work straight away. If you don't have an algorithm for getting input, for counting, etc., you will have no success.
Also, do those tasks individually.
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, Thank you.Godbless
 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i dont know how to get the encrpytion and the statistic is not accurate about what is needed like the i and the spaces it should be 1 per letters in statistic but my output has 2 i  in "time is gold" like this
t 1
i 2
m 1
e 1
2
i  2
s 1
2
g 1
o  1
l  1
d  1


If you sort the letters first before trying to count them you get
Then if you read them from left to right you can detect when a character is the same as the previous character so as to not report it as a new character but increment the count.

There are other techniques you can use. One would be to allocate an array of buckets to keep a count for each letter and add to the count in the appropriate bucket when a letter is encountered. Yet another  way would be to keep track of which letters you've already processed so that you can skip over them in subsequent passes.

Forget about the encryption part of the assignment until you get this worked out. Ideally you'd put the logic for just this part into its own method.
 
Campbell Ritchie
Marshal
Posts: 71760
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:. . . allocate an array of buckets to keep a count for each letter . . .

. . . and I won't tell YC that there is an example just like that in the Java™ Tutorials (Map interface section).
 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...or, if you know the input is only ASCII characters then the buckets can be an array of int[128].
 
Campbell Ritchie
Marshal
Posts: 71760
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I prefer the map technique. Both that and the array technique have the advantage that they run in linear time whereas the sorting runs in nlog(n) time.
 
Carey Brown
Saloon Keeper
Posts: 7622
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not all beginners are ready for Maps yet. Maybe yes? Maybe no?
 
Campbell Ritchie
Marshal
Posts: 71760
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's call that a no, then.
 
yan cle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the comments.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic