My assignment was to create a class and then write a program that uses the methods of the class I created. All the output is correct except for the Question # Missed. It prints [I@1dd0fe7. The wrong question numbers have to be stored into an array and that array printed. I've tried using a for loop to print, rearranging the code, setting the code to how I did in the other methods. I either get this [I@1dd0fe7 -or- a bunch of 0's. I'm not sure if I am calling the method incorrectly, or just do not have the correct set-up to print the array, or if I am just not grabbing the ones that are incorrect.
public class DriverExam {
// Fields
private boolean result;
private int testTotal;
private int numWrong;
private int [] numMissed;
private char [] answerKey;
I need to store the data of a bunch of objects of a particular class in files in a predefined directory. Later, I want to get all the files from the directory and turn them into the objects again. Ideally, I'd like to have one file per object and have the files be human-readable and editable without too much difficulty. The class used by the objects will likely be subject to change in the future, as well. To keep things simple, all the data members are either primitives, Strings, or arrays of them. What is the best library/API to use to deal with this situation? Or should I write my own classes for these operations?
I read into serialization, but I read that it doesn't deal well with classes that are frequently modified. I also found articles on Preferences, but none of the ones I saw seem to explain how to best handle reading and writing to and from multiple objects, especially when I don't know a prior all the objects that were written to disk.
Now I want to store those username and age(in .html) somewhere and I want those information in welcome.jsp. Now, I'm storing all those in session itself(In doGet method(servlet)).
2 Doubt) Also, when I get the session in servlet HttpSession session = request.getSession(); line No. 27. The session value is org. apache. catalina. session. StandardSessionFacade@69a8bf4f...I'm expecting that session is to be empty. Because, I dint store anything until that line.
I have created this project and want to be able to add new members to my members arraylist, store the input in a .txt file and load the new members after closing and opening the program.
I am working on my second javafx program and I am getting confused. The program that I am writing is a payroll calculator. A secondary window opens at the start of the program where the user first enters the number of employees and clicks submit to save the number and to close this window. Then, the user begins to enters the employee information (first name, last name, pay rate and hours worked) when the user clicks the NextEmp button, I want the data in the text fields to be entered into arrays for later use, then clear the fields for the next use. I am running into 2 issues. The first is the close event for the secondary window that pops up. I cannot figure out the syntax. The second issue that I am running into is the loop to store the data into the arrays. I believe I am getting the text field data correctly, but I cannot figure out how to stop the loop until the NextEmp button is pressed again.
I have declared an array list that will store data type of 1 Character and 2 integer. The data that will be store in this list is
1. A = {0 3} 2. B = {0 5} 3. C = {0 3} 4. D = {0 3} 5. E = {0 5} 6. F = {0 6}
Now here the alphabets are routers and integers are there con1 and con2 respectively. I have a set of router={ A,B,C,D,E,F}.
Step 1:I have to subtract con1 from con2 i.e. (3-0) of all the routers and Step 2: then put the router having largest value in new set 1 and Step 3: then this router will be subtract from the router set. Step 4:then again I have to repeat the step 1 until the value of routers become <= 1.
Now what I did is I defined 3 arrays first is String array that stores names of routers, 2nd array that stores the first value and 3rd array that stores the second value. I can find the largest value but how to store the name of router against the largest value in the set.
I've spent almost 3 hours on googling about java beans and where it is usable. What I've figured out is that a bean has a public non-arg constructor, properties and getters/setters to manipulate them. I also know that a bean contains no logic, only fields. However, I don't fully understand why I need to use beans instead of normal classes even if a class can do the same things like a bean? Are beans used to store data or what?
I have created this project and want to be able to add new members to my members arraylist, store the input in a .txt file and load the new members after closing and opening the program.
My problem is that in my program, I have the user input data for one of three product objects, however when I read the data for all three objects, the same data is stored in all of them.
Anyway this is the method from the Interface class:
private void readInput() // the only method in the program that accepts product data from the user { Store matesStore = new Store(); String name; int demandRate, productChoice; double setupCost, unitCost, inventoryCost, sellingPrice; Scanner console = new Scanner(System.in);
[Code] ....
And here is the method from the Store class:
public static void addData(int option, String newName, int newDemand, double newSetup, double newUnit, double newInventory, double newPrice) //sets the product data for a particular product { if (option==1) setData(product1, newName, newDemand, newSetup, newUnit, newInventory, newPrice); else if (option==2) setData(product2, newName, newDemand, newSetup, newUnit, newInventory, newPrice); else /*(option==3)*/ setData(product3, newName, newDemand, newSetup, newUnit, newInventory, newPrice);
[Code] ....
The problem I had was with static variables and methods.
We were given a class lab that asks us to write a program that create a multidimensional array ( 5 x 5 ), populates the array using nested loops with letter from A until Y, and displays the array to the screen. and the result should look like this:
A B C D E F G H I J K L M N O P Q R S T U V W X Y
How to write this program.. I have tried all my best but the results are not coming like this..
It works in the first time. But, after sometime the data is not retrieved and display empty screen. Once, i stop and start the server again, the data is getting retrieved again. But, later when we refresh the empty page is getting displayed again.
One of the requirements of my programming assignment is that a user enters a command along with two numbers. For example, if I entered the following command:
I 5 6
The program create an image like this (it wouldn't be outputted though):
00000 00000 00000 00000 00000 00000
It creates a 5 x 6 "image". This is where my troubles begin. The program should also accepts other commands, such as:
L 3 2 F
which would produce (also not outputted):
00000 00F00 00000 00000 00000 00000
Here is my method for creating an "image" with an M * N array
for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++) { System.out.print("0"); } System.out.println(); }
The code works, but I need to store the image in an array so it can be changed by other methods (I can't create the image manually every time). I tried doing something like this but it doesn't work:
public static String[][] createImage(int row, int column) { String[][] image = new String[row][column]; for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++) { image[j][i] = "0"; } System.out.println(); } return image; }
This method outputs as many blank lines as the columns I entered and the memory location of image.
So my question is: how would I store "0" in a 2D array so that it can be accessed and changed by other methods?Or, am I using a 2D array incorrectly and will the image have to be created manually every time? If so, how would I output image if it is created in a separate method?
I'd like to be able to sort them so that if I want to search for one of the entries, I can then create a function which allows me to sort them by date or even return all the numbers by a given date or day, etc....
However, I'd like to be able to set it up so that each set is "linked" meaning that again that I can search by date and it returns everything at that date.
I am having trouble fixing and figuring out how to change my code. My out put is very off.
" Enter a 3-by-3 matrix row by row: 1 1 1 1 1 1 1 1 1 Sum of the major diagonal is 6.0 Sum of the values of the column are: 10.0 Sum of the values of the column are: 20.0 Sum of the values of the column are: 30.0 "
Code is below:
public static void main(String[] args) { double[][] m = new double[3][3]; m = createArray(); } private static double[][] createArray() {
I need to generate a league table in Java based on results provided in the shape of user input. I have the 6 teams in an array. I need to ask the user how many wins, draws, losses each team has had.
for (String element : teams) { System.out.println( "Please enter the number of wins, draws and losses for " + element); int[] wins = new int [6]; int[] draws = new int [6]; int[] losses = new int [6]; }
How do I pull 3 separate values from the user and then store each value in a separate element of each array? so if one team wins 3, draws 2 and loses 1 - I need to put 3 into the wins array, 2 into the draws array and 1 into the losses array? I then need to total all this in a table.
public class MonthsName { static String monthsName[]; public static void main(String[] args) { String[] months = new String[13]; months[0] = null ;
[Code] .....
I keep getting 1 error that tells me this. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at MonthsName.main(MonthsName.java:22) Java Result: 1
Just before that netbeans couldn't find the main class. I was wondering if it netbeans or my code that's wrong.
I am reading records from a txt file and storing it into an array
import java.util.*; import java.io.*; public class PatientExercise { //patients exercise time public static void main (String[]args) throws IOException{ Scanner in = new Scanner(new FileReader("values.txt")); double [] patientTimeRecords = new double [300]; int noExerciseCount=0, numPatients =0; double highest=0, lowest=0, avg=0, totalTime=0;
[Code] ....
However an error msg keeps popping up:
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:907) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextDouble(Scanner.java:2456) at pastpapers.PatientExercise.main(PatientExercise.ja va:44)
line 44 is:patientTimeRecords[i]= in.nextDouble();
The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:
Reads file: Beginningbalance.txt Displays Data with calculation Creates a file called "Newbalance.txt" with the following values:
111 251.41 222 402.00
With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.
import java.io.*; import java.util.Scanner; import java.text.DecimalFormat; public class Output { public static void main(String[]args) throws IOException {
This particular program is supposed to prompt the user to input either an uppercase or lowercase Y to process a phone number, they are then prompted to enter the character representation of a phone number (like CALL HOME would be 225-5466), this repeats until the user enters something other than the letter Y. All of the words entered are to be stored into a single array. The program is then to convert these words in the array to actual phone numbers.
import java.util.*; public class Program1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String begin; int phoneNumber = number.convertNum(); System.out.println("Please enter an uppercase or lowercase Y when you are ready to enter a telephone number: ");
[code]....
I realize that the second method doesn't have anything to return yet, I just wanted to put that in there while I was doing things that I actually know how to do ha. The convertNum() method is supposed to be the method with which the array of characters is converted to phone numbers.
would think it'd be easier to store the inputs from the user as individual letters rather than words for the sake of converting to phone numbers.
Also, we are only supposed to recognize the first 7 letters of each word that is entered, like the CALL HOME example, there are 8 letters but it's still a seven digit phone number, so I'm not sure how that would work.Also, when printing the phone numbers after they've been converted, we're supposed to print the hyphen after the third number, I have no clue how that would be done from an array.
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so
I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.
Here is the main important GUI from my CheckerBoard class:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CheckerBoard extends JPanel implements ActionListener, MouseListener { // Main routine that opens an Applet that shows a CheckerBoard public static void main(String[] args) { new CLayout();
So I'm trying to write a program that will take in 5 numbers, store them in an array and then print out the array and the average of the array. Problem is that every time I run my program I get a "ArrayIndexOutOfBoundsException: 5" error and I don't know who to fix it.
public class ConstructorHomework { final static int size = 5; static double[] myArray = new double[size]; public static double average; public void printArray(){
So for fun I've decided to write a program that can keep track of a simple card game my friends and I designed. I've built a class for an array, that stores the basic stats of each card. I need to be able to access this array from another class, that will print the array information to a file, so we can easily keep track of who's cards have leveled up and their stats. The main class will also be using a random number generator to determine how much damage the attacker/defender deals and takes respectively. So far I have the random number generator built as well. I'm just having issues creating a print to file class and what I need to change in my array class to make it accessible by the other class that prints it to a file.
public class StartingStats { public static void main(String[] args) { //Variable to use for how many spots in a stat array there are final int statArray = 2;
[code]...
what I need to change so that a print to file class can access EACH array in this array folder. Also if any cookie cutter printToFile class I could use/borrow/change that'd be really useful, as I've never done any printing to file before. Also, the levels of each stat and exp will be changing so that's why I need a separate class to print so that I can call it when it's been updated so we always have the most up to date stats saved.
My array isn't printing. I have tried everything. I have tried putting a nested for loop in different methods but still no luck. I have also tried System.out.print but that prints random characters/numbers.
import java.util.Scanner; public class Square { public static void main(String[] args)
[Code].....
^For some reason the site doesn't show the spaces between the *. It's supposed to be a 5x5 square.