Simple Java Programming Help? Cutting words using IndexOf?

Simple Java Programming Help? Cutting words using IndexOf? Topic: Prompts for writing a letter to yourself
June 19, 2019 / By Deloris
Question: I want to know how to take the input of someone's first name and last name, and then cut off anything past the first three letters of each and then put them together. Then I use a random number generator to generate the password (6 digits), and then I want to use a boolean to prompt them on whether or not they want to change the password, then if they say yes or no, prompt them for the changed password. The changed password has to fit the criteria of 6 or more digits. If not, then it says that there is an error with the inputed password, and it doesn't change it. Example: First Name: John // I have this Last Name: Williams // I have this ID: wiljoh054 // I have this, except can't get it to cut the name into the first 3 letters of each Password: 820348 // I have this as well. Change Password? (y-yes, n-no) // i have this, but it doesn't read Y or N. y or Y -> enter new password: //checks to see if equal to or greater than 6 characters. hello (5): Error. Less than 6 characters. bobbie (6): ID: wiljoh054 Password: bobbie n or N -> end of code. Thanks for help. okay, I understand that. then how about help on the boolean resetting the password?
Best Answer

Best Answers: Simple Java Programming Help? Cutting words using IndexOf?

Caelie Caelie | 4 days ago
Use substring(..) to get parts of a string: String lastName = "Williams"; String lastName3ltrs = Name.substring(0,3); lastName3ltrs now contains Wil substring(j,k) gives chars from j through k-1, inclusive. Keep in mind that, like arrays, strings are indexed from 0. String first = "John"; I'll be more concise to add the first three letters of the first name: String pw6 = lastName3ltrs + first.substring(0,3); pw6 now contains "WilJoh"; pw6 = pw6.toLowerCase(); pw6 now contains "wiljoh"; You can convert strings to/from upper/lower case with toUpperCase() toLowerCase() they are non-static methods. +add Here's the problem with 'resetting'. You've shown me only the prompt. Did you write code that doesn't work properly or are you fishing for me to write code for you? I don't want to go to some other site to see your code, either.
👍 276 | 👎 4
Did you like the answer? Simple Java Programming Help? Cutting words using IndexOf? Share with your friends

We found more questions related to the topic: Prompts for writing a letter to yourself

Caelie Originally Answered: Java codes: How to write a java application (using GUI) to implement a simple Calculator?
Hmm, sounds like a homework assignment... The GUI is really straightforward. Use two JPanels, one to hold the buttons and one to contain the entire calculator. Use a GridLayout on the one with the buttons and a BorderLayout on the overall panel (so you can get the text box across the top.) If you really wanted to I guess you could do a GridBagLayout, but it's easier to combine the simpler ones. For the calculations, use two Stacks, one that holds doubles or floats to hold your numbers, and one that holds ints representing your operations. Define constants such as Calculator.ADD and Calculator.DIVIDE to store in the operator stack. When the user clicks a number button it will append that number to the number in the text field. When an operation button is clicked, add the number in the text field to the numerical stack. When equals is clicked, iterate through both stacks until you have a result. A better method would be to show the entire equation in the text window and wait until equals is pressed to evaluate to allow for complex equations. This would require you to code a standard-to-postscript evaluator, which is a bit above what you need to complete this project.
Caelie Originally Answered: Java codes: How to write a java application (using GUI) to implement a simple Calculator?
If you want me to write this program for you then tough. I don't have a GUI editor. The best thing for you to do is to picture on paper or in your mind the actions that are required. First you will need to type in a number. The number will be typed in one digit at a time and appear on the "display". You will be using the calculator keypad for this so each number will have to update the "display". You will now press an operation key, but no operation will be performed at this stage in this example. (The final program may be different to this) but you will need to store the operation. Now you enter another number. This second number will refresh the "display" but you will need to store the previous number because you have an operation to process. Now you press any operation key or an equals operation and the previous operation will be performed. The result will be shown on the "display". I think you will find that this is called a use case. A very important tool in the development of OO programs. Or of course you could always just cobble something together and hope that it works.
Caelie Originally Answered: Java codes: How to write a java application (using GUI) to implement a simple Calculator?
I also use NetBeans I generally use NetBeans for designing my GUI then code in Eclipse or BlueJ NetBeans saves time But it is frustating sometimes because it always use GroupLayout

Alma Alma
This exact task is exceptionally foolish in Java, only for the list. But I count on the instructor's seeking to get you to turn out you recognize how the mod operator and integer department works. Think of the mod operator and integer department as 2 constituents of a steady department hindrance like those you do in basic university; Integer department produces the quotient and mod produces the the rest. so, for instance: 25/10 could yield two (how often 10 is going into 25) 25percent10 could yield five (what is left over after 10 is going into 25) Knowing this, you'll be able to use powers of 10 to peel off unmarried digits of a quantity; ex: Say your quantity is 546 546/one hundred = five 546percentone hundred = forty six forty six/10 = four 46percent10 = 6 a code snippet to exhibit you kind of how to do that. This assumes x is the given Integer, num is the string so one can be produced, and y is a energy of 10 with the identical quantity of digits as x (e.g. if x = 500 then y == one hundred, x = 53433 then y = ten thousand) If the quantity of digits is not given the easiest (if no longer essentially the most effective) method to discover y is to make use of a loop to multiply y by means of 10 even as y *10 < x This code could move in a loop, wherein you decrement y by means of 10 till y = zero; (y/10 in integer department) num = (num + (x/y)); x = xpercenty; I say that the task is foolish, considering the fact that this one line could exchange the whole loop: num = Integer.toString(x);
👍 120 | 👎 -2

Alma Originally Answered: Help in java Programming.?
Too much code for the task, not even going to look for mistakes. Here's how I would do it: int p=Integer.parseInt(a.getText()); int q=Integer.parseInt(b.getText()); int r=Integer.parseInt(c.getText()); int[] array = new int[3]; array[0]=p; array[1]=q; array[2]=r; //sorts in ascending order java.util.Arrays.sort(array); //reverse it int temp = array[0]; array[0]=array[2]; array[2]=temp; answer.setText(""+array[0] + array[1]+array[2]); //you can use for loops if you have more than 3 elements
Alma Originally Answered: Help in java Programming.?
Don't know what error you're having, but I'm pretty sure you have some kind of error that says something like can't parse integers as string for labels. And I spotted the errors by looking at your code on these lines: answer.setText(""+p+q+r); answer.setText(""+p+r+q); answer.setText(""+q+p+r); answer.setText(""+q+r+p); answer.setText(""+r+q+p); answer.setText(""+r+p+q); You're basically trying to set integers of r, p, and q as text for the label; the compile doesn't like that. What I would do is use String.valueOf() to parse it as a string because labels are strings. So: answer.setText(""+ String.valueOf(r) + String.valueOf(p) + String.valueOf(q)); That will parse it into strings for the label. I might try it too and see if it works, however, I guarantee that it should work. Edit: Your way works as well, so no need to do String.valueOf(). So I'm not sure what error you're receiving; I'm pretty sure this is not your whole code and the error is probably else where in your program. So a little update would help. Perhaps, you're trying to display the numbers with a space? Because I see you're displaying the numbers without any space, so you would need to add a space in between: answer.setText(""+ r +" " + p + " " + q);

If you have your own answer to the question prompts for writing a letter to yourself, then you can write your own version, using the form below for an extended answer.