Program is running fine. I can create usernames and everything but somehow I cannot quit or exit the program when I enter my sentinal value "QUIT". Here is my program question: Create an application that will create a username for a school computer system. Input a user’s first and last name. The username will be the first letter of the first name followed by the first 5 letters of his last name followed by a random 3 digit number. Continue to create and display usernames until a sentinel value is entered.
import java.text.*;
import java.util.Random;
import java.text.DecimalFormat;
public class username
Write a program that asks the user for the names of two files. The first file should be opened for reading and the second file should be opened for writing. Ihe program should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, except that all the characters w ill be uppercase. Use Notepad or another text editor to create a simple file that can be used to test the program
Here is my code. I Also made two text document files that are located in the same directory as the .class file (the code file) that are named OriginalFile and UpperCase respectively. Please let me know what I need to do. Here is the code.
import java.util.Scanner; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; public class UpperCaseFile { public static void main (String [] args) throws IOException {
I am trying to write a java program that asks the user for a list of names (one per line) until the user enters a blank line. At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the user entered the name in the program. I am supposed to use an ArrayList for this problem.
My idea for a solution is to create an ArrayList<String>, read each name, i.e., line, entered and then to see if that name is already in the ArrayList. I created a for loop to check each element in the ArrayList but when I try to assign an element to a string variable I get the error "Type mismatch: cannot convert from Object to String". Not sure why that is happening because the ArrayList is defined as a String list.
This application is supposed to allow a user to enter the names an phone numbers of up to 20 friends, until the user enters "zzz" or 20 names. Then the console is supposed to display the names and have the user enter a name to get the phone number. Here's my code:
import java.util.Scanner; public class PhoneBook{ public static void main(String[] args){ String name; int phoneNumber; final int nameAmount=20;
[Code] ....
I can't seem to get it correct, every time I correct a compiler error, another set of them appear.
I am wanting this program to prompt the user to enter a maximum value and a minimum value and the program should in theory generate a random number for the output. Here is my logic:
int maxRange1; int minRange1; static int range; static Random gen;
Then in my mail argument:
gen = new Random(); Scanner input = new Scanner(System.in); System.out.print("Enter the maximum number: "); int maxRange1 = input.nextInt();
[Code] ....
I am able to return both the user prompts and get the inputted answer to appear but I am not getting a response for the prompt "The random number is: ".
I need to fix a program in which the user must get a three random numbers in a row. They have five chances. This is what i have so far:
public static void main(String[] args)throws IOException { // TODO code application logic here BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int num1=(int)(Math.random()*(9-0)); int num2=(int)(Math.random()*(9-0)); int num3=(int)(Math.random()*(9-0));
My assignment is to write a program that will encrypt and decrypt a sentence entered by a user but the encryption is to be random using an array. Can I convert my sentence(string) from char to int then create a random array to encrypt?
import java.util.Scanner; import java.util.Random; /*SentenceEncryptionProgram */ public class SentenceEncryption { string sentence; //sentence entered by user
I have been assigned to write a program that has a user input random numbers then the program is to sort them in different ways. I have the coding for the different sorts but, I have an error saying that I am missing a return statement in the "Bubble" method. I am trying to return "arr[i]" in the "for loop" which gives me this error, and when I try to take the "return arr[i]" outside of the "for()" loop the error reads the it cannot locate variable "i".
import java.awt.* ; import java.awt.event.*; import javax.swing.*; public class SwingSorts extends JFrame implements ActionListener { JRadioButton bubble; JRadioButton selection;
The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".
So far I have gotten the random number generation part working. I have up to here:
import java.util.Random; public class test4 { public static void main(String[] args) { Random random = new Random(); for(int i =0; i < 1; i++){ int num = random.nextInt(10) + 1; System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?"); } } }
I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.
import java.util.Random; import java.util.Scanner; public class GuessGame { public static void main(String args[]) { String choice="y";
In my project I had to create 2 classes, Room and Animal.
Room had to have an array (NOT arrayList-I know theyre better and easier but I need to use an array, for now) This array must be able to be populated by 10 "Animals", and the Room class needs two methods, a method to add animal a to the room (rooms array) and a toString() that returns the name of the room and the names of the animals in the room. The teacher added a hint saying that this toString() should reference the animal classes toString()
Here is my code thus far:
public class Room { private String name; Animal[] inRoom = new Animal[10]; public Room(String roomName){ name = roomName; } public void addAnimal(Animal a){ for(int i = 0; i < 10; i++){
In a spreadsheet, alphabetical letters are column names and numbers represent rows. I have named the columns and I need to name the rows in the same way. Or if I am to set the first column in every row as row headers, how can I make then non-editable by the user? In addition to that, how can I make the table appear bigger? There's a lot of space but the table appears to be small.
But - it always prints 'Lindsey'. I need a way of completely randomizing but I can't see the class has a method to let me do this? I can use the randomize method but this takes an int argument which will always bring back the same index value (same name).
I wonder if I am over complicating this. I can use a simple String array of names, but I don't want, like 10,000 names in my array and I want a good way of generating good, randomized data. Perhaps a .csv file of names could be read in? Here is a second method I wrote but I don't have the skills to know how to read the array values from my large .csv file:
public String randomSecondName(){ String[] lastNames = {"Smith", "Jones", "Collins","Jackson", "Dearsley", "Trump", "Carr", "O'Connell", "Dyer", "Furstzwangler" }; Random ran = new Random(); String lastName = lastNames[ran.nextInt(lastNames.length)]; return lastName; }
I'm using MS Access database. What I want to do, is to get all names of my tables in database.My SQL query :
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
is it correct? I found it in one example and didn't change anything.
I could of course execute this and check, but the problem is, that it returns ResultSet(I'm using Java), and I do not know how to manipulate this object in this situation.Cause usually ResultSet contains columns and rows, I think now I should get only bunch of String values.
i have this problem with my code. it need to put three names in alphabetical order that are entered from the user. then output the alphabetical result. the program compiles but when you put in different names there are not alphabeticals. i think only the first if works good.
import javax.swing.JOptionPane; public class Sort { public static void main(String[] args) { String name1; String name2; String name3;
I have a JTable with the model " Names " , " Quantity " and " Unit " .
I'm coding a program where you get the ingredients names.
So i need to get the whole row of one column and String it all up together,because i need to store it in mySql and i have already set it all as String.
how i can do this ?
My code are as follows :
JTable Code:
DefaultTableModel model = (DefaultTableModel)table.getModel(); if(!txtQty.getText().trim().equals("")){ model.addRow(new Object[]{ingCB.getSelectedItem().toString(),txtQty.getText(),unitCB.getSelectedItem().toString()}); }else{ JOptionPane.showMessageDialog(null,"*Quantity field left blank"); }
Getting the values and for storing :
for(int i = 1; i<= i ; i++){ ingredients = table.getName(); }
This is for loop is wrong and it does not work because i have a constructor to take in Ingredients but because it is inside the loop, it cannot take it in.
One of my assignments was to make a program that would read a sequence of names and then list them all.Just to be clear, it would read them all first, and then it would list them all at the same time.
I'm new to Methods and do not really know how to write a method header. What would an appropriate header look like for the following instance? getFilename: This method takes no parameters. It asks the user for a filename. If that file exists, it returns the filename. If it does not exist, it asks the user for another filename. It continues to ask for filenames until the user gives the name of a file that exists.
Also, how would I make a return tag for this and call it into the main method.
I give my dataset in csv (or text) format to my program but it says "(The system cannot find the file specified)" even though the file exists.
what should I do?
here is my code:
Java Code: public class ReadCSV { HashMap<String, Integer> authorList = new HashMap<>(); File file = new File("d:/Course/thesis/predict/whole.scv"); int authorCounter = 0; public static void main(String[] args) { ReadCSV obj = new ReadCSV();
An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?
In Java® identifiers, you are allowed letters and numbers (also _ $£¢€ etc, but you should avoid them in normal identifiers). So you cannot have spaces. You cannot write public class Hello World because the javac tool will see World as a separate identifier and not understand what it means and will fail to compile the code. You must write public class HelloWorld instead. And because the class is labelled public you must call the source file Hello World. java. Since you can't have two classes with the same [fully‑qualified] name, you cannot write two public classes in the same source file.
“What about names of source files?” somebody will ask. Well, some file systems will permit spaces in file names; ext4 will and I suspect so will NTFS. Can you write file names with spaces in? You would have to have a different name of the class inside the file, because you can't have spaces, and you therefore cannot make the class public, but maybe you can write a package‑private class with a different name.
On ext4, you have to write out the name of the file and the shell will interpret the space as meaning there are two different file, so you have to escape the space.
campbell@campbellsComputer:~/java$ gedit My First Class.java // My First Class.java class Foo { public static void main(String... args) { System.out.println("Hello, World!"); } } campbell@campbellsComputer:~/java$ javac My First Class.java campbell@campbellsComputer:~/java$ java Foo
I'm new to Methods and do not really know how to write a method header. What would an appropriate header look like for the following instance? getFilename: This method takes no parameters. It asks the user for a filename. If that file exists, it returns the filename. If it does not exist, it asks the user for another filename. It continues to ask for filenames until the user gives the name of a file that exists.
Also, how would I make a return tag for this and call it into the main method.