I simply need to write a program that asks a user to input a password. It has to be in this format: DDD-LL-DDDD. The D's mean Digit and the L's stands for Letter. The User has to enter the Hyphens.
If the password isn't entered in that exact format the program should read out a error. If the hyphens aren't entered the program should read out a error. If there are too many characters entered, there should be a error.
import java.util.Scanner;
public class security {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Security Code: ");
System.out.println("Use the format: DDD-LL-DDDD and include dashes");
String code = input.next();
char c;
[Code] ....
I'm trying to figure how how to get the code to check if the values entered are in the correct place. I'm also not sure how to make the program check for hyphens. I feel like I'm close though. I can easily add the correct error and valid messages later if I could just figure out this part.
My homework is asking me to write a program that prompts the user to enter a password and displays "valid password" if the rule is followed or "invalid password"
Sample enter a string for password: wewewx valid password
It's being graded on Design of my GUI Dialog box User friendliness Creativity
My current issues with the current code I have written is simply the password doesn't work unless it starts with 2 digits, the other order it displays as wrong. and I have no idea how to add a GUI.
The goal of this section of my assignment is to ask the user for a password. The password entered has to match the password I set in the code. If it is correct the next dialog box will pop up.
my password is set to: String enterpwd = ""; String correctPassword = "Setpassword";
I am asked to use JOption, I completed as follows:
So obviously I'm new to java and i need to write a program that gives exact change in quarters, dimes, nickels, and pennies. For some reason it seems to work correctly but the nickels never is correct and I'm not sure why, seeing as though everything else is.
Java Code:
public class Coins{ private int c; public Coins(int coins){ c = coins; } public void calculate(){ int quarters = c / 25;
I have being trying to figure out why my string doesn't work as a passcode and I can't seem to figure out why.
import java.util.*; public class Login { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Hello there, please state your name"); String userName = in.nextLine();
I am trying to write a password checker program and thats the error i get. (the final error!) but this one i dont know how to fix. here is my code.
/* Text Text text */
import java.util.Scanner; // Imports the Scanner class to get Keyboard Inputs class PriceRichardChapter5Test { public static void main (String [] args) { String Password; // Creates the Password variable
so I had to create a program that allows the user to enter a day using a number and then enter a year and after they did that it would create an entire calendar for that year ..so I have that but the only issue is I can not get the numbers to line up neatly.how to do the entire thing in loops, I tried a couple in here..what this would look like as loops instead of switches and cases and if else
import java.util.Scanner; public class Calendar { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
I have to write a gui program where I can enter a file name and then it gets displayed in a text area when I click Open. Conceptually, I do not get this. I was thinking of appending the text file into a string or something, but I guess I'm confused on how it all works and how I can open the text file. Not asking for the code, but just a compass or something.
I wrote a java program for my gui number converter app, the main purpose of this program is to make sure that user enters only a binary number for conversion from binary to other number formats. the problem is my program keeps prompting me to enter correct binary number, no matter if i enter correct binary number, it will still keep prompting me to enter correct number. Here is the code
import java.util.*; public class test { Scanner key = new Scanner(System.in); String in; int b; public test()
I'm using Jgrasp and my prompt is asking me to write a program where the program prompts the user to enter 4 grades between 0 and 100. And you have to display the grades, and the program has to calculate the minimum grade, the maximum grade and the average.I'm just having problems with the max?
// Import Java Scanner. import java.util.Scanner; // Name Class. public class Practice_4_1
package question.pkg3; import java.util.Scanner; public class Question3 { public static void main(String[] args) { // TODO code application logic here Scanner Luka=new Scanner(System.in); double sum=0;double count=0; int[] a=new int[10];
[code]....
I'm required to write a program that allows the user to enter up to 10 integer grades into an array. Stop the loop by typing in ‐1. Your main method should call an Average method that returns the average of the grades.I There's something wrong with my program , the count always stays 0 and the sum is always 1 less than the actual sum.Sample input and output :
Enter grade 1: 8 Enter grade 2: 9 Enter grade 3: 10 Enter grade 4: 5 Enter grade 5: 8 Enter grade 6: 9 Enter grade 7: -1 output
Average grade is 8.1666666667On line 13 I had count=count+1 ;
I have to meet certain requirements for this one program, and one of them is as follow: The program will require the user to enter the needed values one after another. If any of the entered values is invalid, then the program will detect that and go into a loop requiring the user to enter a valid value. The program must keep track of the total number of invalid values that the user has entered.
I know how to set a restriction and create a loop to keep asking the same question until it is satisfactory ( in this case I used a while loop) but I am at loss on how I should keep track of the total number of invalid values. I know I can use an increment but how do I set a variable for when the program meets an wrong input from the user.
so I had to make a program that prompts the user to enter a loan amount and the years for the loan and I have the conversions and everything my only issue is that when the chart pops up it just looks like a bunch of numbers and its missing the column headers
for example
Interest Rate Monthly Payment Total Payment
import java.util.Scanner; public class InterestRate { public static void main(String[] args) { double monthlypayment = 0; double totalpayment = 0; Scanner input = new Scanner(System.in); System.out.println("Enter Loan Amount");
I am writing a short quiz program, and when the user inputs their answer they hit the enter key (the are int). But the last question on my quiz is asking the user to they want to repeat the quiz, but when I run the program, it won't allow me to input any information. I can briefly remember my lecturer saying something about entering in a code after each int the user inputs but I can't remember what it was.
Here is a snippet of my code:
//Question 3 do{ System.out.println("Question 3- What Hollywood actor did Mila Kunis have a baby with recently?"); System.out.println( question3 + ".Ashton Kutcher 2.Bradly Cooper 3.Leonardo Dicaperio h.Get a hint"); answer3 = stdIn.nextInt(); if(answer3 != question3)
I am trying to write a program that asks the user to enter a number from 1 through 10 and then the program will display the roman numeral for that number.
I am also adding a error message in which i haven't yet because im still trying to figure out how to the program will do the roman numeral.'
I have used the if and else if. but when i input a number it just repeats the number back to me.
The program cimpiles but it doesn't do what i want. here is what i have so far. how can i get the program to display the roman numeral after the number is entered.
import javax.swing.JOptionPane; public class Romannumeral { public static void main(String[] args) { double number;
I work for my local probate court, and one service we offer is email reminders. They fill out a form, it's entered in the system, and they will be notified when something is due. I've been allowed to create a program that will allow me to enter the information from the form to keep track of the attorney's who have signed up.
public class Attempt1 { public static void setConnection() throws SQLException { Connection conn = null; Statement state = null;
[Code] ....
The issue I have is the method setQuery. It displays a table with the data entered. Where it currently sits at line 21, it does not display the table, nor does it seem to terminate the program. The goal was to update the table with a few entries, and then display the Jtable. When placed above the setInsert method, it displays just fine, and will reflect the new entries added the next time you start it. I'm still learning Java outside of a classroom environment on my own, so I can only imagine that this is riddled with poor coding, but I just can't seem to figure out why it doesn't display the table after the setInsert method is called. In it's current state, this program is just meant to test functions of SQLite with Java. From there it will be created with a GUI.
I did a problem from my book which is "Write a method that displays an n-by-n matrix. Each element is 0 or 1, which is generate randomly. Write a test program that prompts the user to enter n and displays the n-by-b matrix".
So if a user would enter 3, and output could be 0 1 1 0 1 0 1 0 1
So here's my question... I was able to get the program to work in the way my book describes (by just writing the code in the class with the main), but for practice, I want to learn how to do this OOP-style...
I'm not sure how to do this, though, since the method is a void method, so I can't seem to call it within a toString method.
import java.util.Scanner; public class MatrixTest { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter an int"); int number = input.nextInt(); MatrixClass mc = new MatrixClass(number);
Now the problem here is it replaces all the occurrence of abc in the string value and I get the below output as :
value=""/xyz_12_1/xyz234/xyz/filename.txt";
However my requirement is only in the case the value exactly matches with source the replacement shd happen. I am expecting the output like this :
String value ="/abc_12_1/abc234/xyz/filename.txt";
Also the above code is in a function which will be called multiple times and the values will keep on changing. However the target and source will remain the same always.
I am using NetBeans IDE 8.0.2 to program Java code. I am a beginner in Java.
Instead of getting two decimal places after the point, I am getting three despite using the code format for two ("##.##"). Actually, this happens even if I remove the format code between the quotes. It is as if the program cannot see the format code. Why this happens ?
Here is the relevant program code:
private void convertButtonActionPerformed(java.awt.event.Action Event evt) { double inputNumber = 0; // sets the decimal format
How to improve my code. I finally was able to create a program that gives you the corresponding letter grade, when you enter in a numeric grade without using an array. The only issue left is that I have to be able to enter 5 grades at a time, and it give me the letter grade for all 5. I have the programming working, but only am able to enter 1 at a time. I am not sure what kind of loop or if I am supposed to use a loop.
public static void main(String[] args){ { int grade = 0; Scanner input = new Scanner(System.in); System.out.println("Enter : "); grade = input.nextInt(); if (grade >= 90)
Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:
Enter two positive integers: 5 3 The sum is 8. The product is 15. The difference is 2. The quotient is 1. The remainder is 2.
import java.util.Scanner; public class TwoIntegers { public static void main(String[] args) { System.out.println("Enter two positive integers: "); Scanner userInput = new Scanner("System.in"); int integer1 = userInput.nextInt(); int integer2 = userInput.nextInt();
Ok so I have my program working for the most part. In this program I am supposed to take input from the user until they enter a negative number and that works, the problem is that it doesn't work if I enter a negative number on the first prompt. For example if I enter a 100 it would prompt me again and if I enter a negative number it would quit and give me the average, but if I enter a negative number the first time I am prompted the program just gives me an error. How do I fix that?
import java.util.List; import java.util.ArrayList; import java.util.Scanner; public class Application { public static void main(String [] args){ Scanner input = new Scanner(System.in); List<Integer> grades;
I need to write the exact directory path like C:LisaestUpdate to a properties file.
I am trying it by
FileInputStream in = new FileInputStream(test.properties); Properties props = new Properties(); props.load(in); in.close(); FileOutputStream out = new FileOutputStream(newprop.properties); props.setProperty("myDirectory","C:Lisa estUpdate" ); props.store(out, null); out.close();
but the properties file is updated as C:Lisa estUpdate
Extra comes before :.
How can I remove that.
Even I tried it with an command but got same output.
so I need my program to print in decimal format and I keep getting an error saying that it cant find symbol "decimalFormat". here's what I have so far.
import java.util.Scanner; public class GPACalculator { public static void main(String[] args) { int creditHours = 0; int gradePoints = 0;
I am writing a program using a given test drive... I am supposed to write two classes according to the test drive. The calculated correct answer should be 115.50 but i keep getting 115.52 instead and i just can't figure out what i'm doing wrong.
Here is the test drive code:
import java.text.NumberFormat; public class FinalTester { public static void main(String[] args) { double avgPurchase; Order[] lastYear = new Order[4];