Random User Names
Nov 9, 2014
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
[code]...
View Replies
ADVERTISEMENT
Jun 30, 2014
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
{
[Code]...
View Replies
View Related
May 21, 2015
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.
Here is the code so far.
/*
* File: UniqueNames.java
*/
import acm.program.*;
import java.util.*;
[Code].....
View Replies
View Related
Apr 13, 2014
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.
View Replies
View Related
Sep 24, 2014
Using Bluejay. Need code that prompts user to enter 5 test scores and their names. Calculate the average and display.
First initial and last name , 5 test scores, and average
View Replies
View Related
Sep 8, 2014
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: ".
View Replies
View Related
Feb 12, 2015
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));
[Code] ....
View Replies
View Related
Oct 28, 2014
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
[Code] ....
View Replies
View Related
Apr 7, 2014
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;
[Code] .....
View Replies
View Related
Dec 8, 2014
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?");
}
}
}
View Replies
View Related
Oct 2, 2014
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";
[Code] ......
View Replies
View Related
Oct 2, 2014
I have 2 enums like below
enum enum1{
TEST_1("name_1","name 1"),
TEST_2("name_2,"name 2");
private String name;
private String description;
[Code] .....
How can i map the same names in 2 enums and get message from enum 1 and code from enum 2.
View Replies
View Related
Jan 22, 2015
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++){
[code].....
View Replies
View Related
Jan 17, 2015
I'm trying to implement a spreadsheet-like table using JTable and this is the basic structure.
String[] colnames={"A","B","C","D","E"};
String[][]data=new String[28][5];
sheet = new JTable(data,colnames);
//sheet.setBounds(10, 36, 527, 214);
JPanel tablepane=new JPanel();
tablepane.add(new JScrollPane(sheet));
tablepane.setSize(800, 400);
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.
View Replies
View Related
Oct 1, 2014
I'm new on Java/android and I wounder how could I get name of each control in a layout, ex.
for (int i=0;i<table1.getChildCount();i++ ) {
Object child=table1.getChildAt(i);
if( child instanceof EditText)
{
//get control name here
}
}
View Replies
View Related
Feb 2, 2014
I'm trying to use the DataFactory class to pull in a list of names, as I need to populate my app in development with randomized test data for testing.
DataFactory
So, I can get a random name like so:-
package domainentities;
import java.util.Random;
import java.util.Collections;
import org.fluttercode.datafactory.AddressDataValues;
[Code] .....
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;
}
View Replies
View Related
Jul 12, 2014
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.
View Replies
View Related
Feb 24, 2014
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;
[code]...
View Replies
View Related
Feb 26, 2014
Java Code:
setseatpos: function(previouspos, position) {
this.seatelement.removeclass("seat-empty").removeclass("seat-pos-" + previouspos).removeclass("seat-inactive").addclass("seat-pos-" + position);
},
renderseat: function() {
[Code] ....
View Replies
View Related
Feb 9, 2014
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.
View Replies
View Related
Oct 16, 2014
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.
View Replies
View Related
Feb 27, 2015
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.
View Replies
View Related
Nov 4, 2014
I have a coauthorship network and I want to replace the authors names with numbers.Part of my datadet:
1992,M_DINE,R_LEIGH,P_HUET,A_LINDE,D_LINDE
1992,C_BURGESS,J_CLINE,M_LUTY
1992,M_DINE,R_LEIGH,P_HUET,A_LINDE,D_LINDE
1992,F_ZWIRNER
1992,O_HERNANDEZ
...
I want the result to be sth like this:
1992 1,2,3,4
1992 5,67
....
and a table of mappings
M_DINE 1
R_LEIGH 2
P_HUET 3
....
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();
[Code]...
View Replies
View Related
Oct 5, 2014
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?
View Replies
View Related
Mar 30, 2015
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
View Replies
View Related
Feb 26, 2015
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.
View Replies
View Related