Reading Dat File And Performing Withdrawals And Deposits

May 3, 2014

So I have these two programs

importjava.util.Scanner;
public class ManageAccounts
{

[Code].....

and i need to create a .dat file and have it perform the tasks it states, what to do, I've just been looking for existing codes and trying to modify them because i have a very limited knowledge of programming.

View Replies


ADVERTISEMENT

Reading Text File Into Object Array And Create Random Access File

Dec 9, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data. Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;

[Code]...

these continue for about 40-50 entries, they are not seperated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name seperated with spaces, then price after a comma, then quanity after the second comma.....

View Replies View Related

Reading Text File Into Object Array And Creating Random Access File?

Dec 8, 2014

I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...

The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.

Here is the base Product class that must be used to create the objects for the array.

public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
//Constructor
public Product( String pName, double price, int quanity )

[code]....

and then here is the data from the text file that i must extract to use to create product objects.

Dill Seed,938,34

Mustard Seed,100,64

Coriander Powder,924,18

Turmeric,836,80

Cinnamon (Ground Korintje),951,10

Cinnamon (Ground) Xtra Hi Oil (2x),614,31

Cinnamon (Ground) High Oil (1X),682,19

these continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quanity after the second comma.....

View Replies View Related

Performing Regular Expression - Valid Last Name

Feb 4, 2015

I have some problems about performing regular expression. In the following code, the output as a result is being "valid last name". But in my opinion, it should be "invalid last name". Because "Doe" has not any space, apostroph or any hypen. Look at the regular expression statement: "[a-zA-Z]+([ '-][a-zA-Z]+)*"
 
package deneme; 
public class Deneme {
public static void main(String[] args) {
String lastName = "Mc-Something"; // Mc-Something 
if(!lastName.matches("[a-zA-Z]+([ '-][a-zA-Z]+)*"))
System.out.println("Invalid last name");
else
System.out.println("Valid last name");
}
}

I know that the asterisk qualifier means character(s) in any number.(Is this wrong?) So for "Mc-Something", 'M' corresponds to [a-zA-Z], 'c' corresponds to +, - corresponds to [ '-], 'S' corresponds to [a-zA-Z], "o" corresponds to +, and finally "mething" corresponds to *, doesn't they? But for "Doe", there is no any space, apostroph or hypen.

View Replies View Related

LISP Expression - Performing Operations

Jan 29, 2015

Given a LISP expression, perform operations on the expression. There will be no list elements that also contain a list such as '(A (B (C D))), which has one atom and one list but the list contains a sublist

INPUT: There will be 5 lines of input. Each line will contain a valid LISP expression. There will be a space between each atom and each list. There are no spaces immediately after or immediately before parentheses in a list. The entire expression must be inputted as a single string.

OUPUT: Perform the given operation on the like numbered expression. The 5 operations are:

1. Print the expression with the list in reverse order. The list will contain only atoms.

2. Print the expression with the list written with consecutive duplicates encoded as sublists in (count element) order. The list will contain only atoms.

3 Print the expression with the list written with consecutive duplicates encoded as sublists in (count element) order except that singletons are listed as atoms. The list will contain only atoms.

4. Print the expression with the list written with every Nth element deleted and where N is the last element of the list.

5. Print the expression written as 2 expressions where the number of lists in first expression is the last element of the expression.

SAMPLE INPUT SAMPLE OUTPUT
1. '(A B C D) 1. ′(D C B A)
2. '(A A A A B C C A A D E E E E) 2. ′((4 A) (1 B) (2 C) (2 A) (1 D) (4 E))
3. '(A A A A B C C A A D E E E E) 3. ′((4 A) B (2 C) (2 A) D (4 E))
4. '((4 A) (1 B) (2 C) (2 A) (1 D) (4 E) 2) 4. ′((4 A) (2 C) (1 D) 2)
5. '((4 A) (1 B) (2 C) (2 A) (1 D) (4 E) 3) 5. ′((4 A) (1 B) (2 C)) ′((2 A) (1 D) (4 E) 3)

View Replies View Related

Reading CSV File

Jan 18, 2014

I have a CSV file with 16K entries of a data table. Does Java work well with CSV file? So I found this code. And it seems its quite easy to read in the data I need. Say for example if I wanted a loop to randomly pick the first field of a specific line in the CSV data table. How would i go about coding that??????

package cvs.test;
 
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
 
[code]....

The CSV looks like the above. and I basically would like to read in the Hand to get it to show in a text box and then randomly have the program ask me to correctly identify the True/False return for one of the SB/BB/UG/MP/CO/BN columns.

View Replies View Related

String To A Double In Scanner - Performing Calculation?

Apr 23, 2015

This may be a multipart question. Basically I have to write a program that accepts a string, converts it to a double splits it and then performs a calculation.

public static void main(String[] args) {
String input = ""; // initalize the string
boolean isOn = true; // used for the while loop...when false, the program will exit.
String exitCommand = "Exit"; // exit command
String[] token = input.split(("(?<=[-+*/])|(?=[-+*/])"));

[Code] ....

This is the error I get:

Enter a math problemException in thread "main" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1842)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecim al.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at Calculator.main(Calculator.java:22)

[Code] .....

How do I go about actually fixing it. Without that line commented out I get this:

Enter a math problem
2+2 <-What I entered
[Ljava.lang.String;@135fbaa4

Also, how would I go about using the submethods to check for valid operands and operators (also part of the problem) I have the actual lists made obviously, but am unsure how to get those to work with the problem.

View Replies View Related

JSP Calculator - Performing Basic Operations On Numbers

Jul 8, 2014

I want a simple jsp page that performs basic operations on numbers such as addition, subtraction, multiplication, division and modulus . How to run that file?

View Replies View Related

Int And Double - Performing Floating Point Arithmetic

Sep 19, 2014

I am new Java Programming and I am struggling to pass my Java class. How to perform Java but I am trying. For this particular assignment I supposed to:

* Change all variables' data types to double.
* Change the two prompts to request double values
* Change change the two calls to the nextInt() method to nextDouble().

This is the original assignment:

import java.util.Scanner;
public class ArithmeticDemo
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
int firstNumber;
int secondNumber;
int sum;
int difference;
int average;

[code]....

View Replies View Related

2D Array Computation - Performing Certain Matrix Calculations

Apr 22, 2015

I've created several methods in another class to perform certain matrix calculations. Do I need to have mutator method in this calculation class to define the column length of the matrix object? I understand why the following code is not working, but I was hoping to get a quick and easy workaround. I'm not sure how to initialize the size of the column for newMatrix within the method.

public int [][] sum(int matrixOne[][], int matrixTwo[][]) {
int sumMatrix [][] = new int[matrixOne.length]["WHAT TO PUT HERE"];
for (int i = 0; i < matrixOne.length; i++) {
for (int j = 0; j < matrixOne[i].length; j++) {
sumMatrix[i][j] = matrixOne[i][j] + matrixTwo[i][j];
System.out.println("matrixSum" + sumMatrix[i][j]);
}
}
return sumMatrix;
}

Then I will use this method to print the new matrix:

public void printMatrix(int newMatrix [][]) {
for (int i = 0; i < newMatrix.length; i++) {
for (int j = 0; j < newMatrix[i].length; j++) {
System.out.print(newMatrix[i][j] + " ");
}
System.out.println("");
}
}

Is all of this overkill and should I just define all the methods within the same class to avoid these issues?

View Replies View Related

Reading A File Header / Hex?

Mar 3, 2013

how to get the first few hex symbols of a file in java, for example if i input a pdf into my coding i want my program to output, e.g "25 46 44 38" ....

I have been able to print out the hex of a whole file but not managed to set a maximum read limit so that my code only takes a certain amount of values ....

View Replies View Related

BNF Grammar And Reading From A Txt File?

Mar 21, 2014

I am implementing a recursive descent parser that recognizes strings in the language below. The input should be from a file "input.txt" and output should be to the console.

The grammar:

A -> I = E | E
E -> T + E | T - E | T
T -> F * T | F / T | F
F -> P ^ F | P
P -> I | L | UI | UL | (A)
U -> + | - | !
I -> C | CI
C -> a | b | ... | y | z
L -> D | DL
D -> 0 | 1 | ... | 8 | 9

An example session might look like this:

String read from file: a=a+b-c*d

The string "a=a+b-c*d" is in the language.

String read from file: a=a**b++c

The string "a=a**b++c" is not in the language.

Java Code: /**

* The Grammar
* A -> I = E | E
*E -> T + E | T - E | T
*T -> F * T | F / T | F
*F -> P ^ F | P
*P -> I | L | UI | UL | (A)
*U -> + | - | !

[code]....

My current output looks like this:

Java Code: The string read from file: a=a+b-c*d

The string "" is not in the language. mh_sh_highlight_all('java');

So it seems to be reading the input file correctly. My error seems to be on this part

Java Code: s = args.length == 1 ? args[0] : ""; mh_sh_highlight_all('java');

When I put the string in that line such as: s = args.length == 1 ? args[0] : "a=a+b-c*d";

My output is:

Java Code: The string read from file: a=a+b-c*d

The string "a=a+b-c*d" is in the language. mh_sh_highlight_all('java');

How can I go about it reading the string from the input file though?

Also, I am not too sure my boolean functions for P, I and, L are correct. Mainly when two terms are together (UI, UL, CI, DL).

View Replies View Related

Reading Content From FTP File?

Jan 27, 2013

I am trying to read a content of file downloaded from ftp and return it as a String. This is what I use:

Java Code:

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.net.ftp.FTPClient;
public class Test {
public static void main(String [] args) throws IOException{
FTPClient ftp = new FTPClient();

[code]....

The code does not work, although all the links are correct.

View Replies View Related

Reading From A File - While Loop

Oct 22, 2014

I have to read from a file that is formatted like that :

name
status
friend
END
name
status
friend
END
.. etc

could be more than one line of friends, which where I have my problem. I can't get it to check if after the friend name the word "END"

I have tried to write a while loop inside the main while loop but it didn't work, and now I have tried to check that in a separate function which it also failed, thats my two while loops

BufferedReader br = null;
FileReader fr = null;
int getLine = 0;
try {
String line;
fr = new FileReader(fileName);
br = new BufferedReader(fr);

[Code] .....

Most of the time I got nullPointerException or missed up order for printing the file !!

View Replies View Related

File Reading / Writing

Sep 9, 2014

I've looked at multiple sources and everyone is saying different stuff. Which one should I be using? FileWriter/FileReader, other people was saying PrintWriter, and one even said : "Formatter" which is the one I'm doubting mostly. My purposes for writing files is for like saving maps, saving high scores, etc.

View Replies View Related

Not Reading Entire File

Mar 29, 2014

I'm new to Java and have not been able to figure this out. I'm reading a text file that contains this:

110001 commercial 500000.00 101
110223 residential 100000.00 101
110020 commercial 1000000.00 107
110333 land 30000.00 105
110442 farm 200000.00 106
110421 land 40000.00 107
112352 residential 250000.00 110

The output goes to a text file and should look like this:

COMMERICAL

FARM
LAND
RESIDENTIAL

101 600000.00
105 30000.00
106 200000.00
107 1040000.00
110 250000.00

I'm creating the output file, but it only contains the categories and not the details below them. Cant seem to figure out why.

Java Code:

package propertylistings;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

[Code] ....

View Replies View Related

Reading From A Txt File Using A Loop

Oct 6, 2014

I am trying to read from a text file that has that contains a list of stock tickers and pairs letting the user choose a ticker and provide analysis of stock. Given a ticker from the user provide

1) the max price, the min price and the avg price of the stock from all lines in the file.
2)Additionally the user should be able to find the stock with the highes price as well as the lowest price in the list.
3)lastly the user should be able to specify a different filename for the stock file.

Im trying to do part 1 and I am having trouble trying to read the whole text file and outputting the stock price with the max,min and avg. Am I heading towards the right track at least? Keep in mind I have just attempted trying to read the text file I have and not tried to find the max or min or avg Right now my code is crashing when I enter the stock ticker that is my primary concern.

package hw01b;
import java.util.Scanner;
import java.io.*;
public class Hw01b
{
static Scanner in = new Scanner(System.in);
static Scanner console = new Scanner(System.in);

[Code] .....

View Replies View Related

Reading The Name Of The File From The Keyboard

Feb 20, 2014

Write a program that extracts words from a file. For the purposes of this program, a word is defined as a series of adjacent letters. Only print words that are at least four and no more than 12 letters long. Print each word on a different line.

The program should read the name of the file from the keyboard.

************************************************** ************************************************** **************

I need to get the filename from the user for this particular program. Usually I would have the name of the file prewritten into the source code like this....

Scanner input = new Scanner(new File("gettsy_burg.txt");

I tried different ways but I just can't seem to figure it out.... I guess what I'm really asking is how to rearrange Scanner input = new Scanner(new File("gettsy_burg.txt"); since I want the user to input the filename instead of the filename being prewritten by the programmer(me).

This is what I have so far to let the user for input....

Scanner keys = new Scanner(System.in);
System.out.println("Enter the filename: ");
String fileName = keys.nextLine();
keys = new Scanner(new File(fileName));

View Replies View Related

Reading Text File

Feb 28, 2014

I'm trying to read a .txt file and put each line in a array of strings but it's not working! What is wrong with this code?He stops in "while" loop.

import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.lang.Character;
import java.lang.String;

[code]...

View Replies View Related

Reading Name Of File From Keyboard

Feb 20, 2014

Write a program that extracts words from a file. For the purposes of this program, a word is defined as a series of adjacent letters. Only print words that are at least four and no more than 12 letters long. Print each word on a different line.

The program should read the name of the file from the keyboard.

************************************************** ************************************************** **************

I need to get the filename from the user for this particular program. Usually I would have the name of the file prewritten into the source code like this....

Scanner input = new Scanner(new File("gettsy_burg.txt");

I tried different ways but I just can't seem to figure it out....

View Replies View Related

Reading And Writing To A File

Jan 10, 2014

I have accountsData.txt file in my default package, this is the file it should be writing to and reading from.

There is an ATM class, which has the main in it. From here the program is supposed to work like an atm, you type in your account number and can withdraw or deposit. It is supposed to then write the changes to the file.

//Read from a file.
public void loadAccounts(String inputFileName) throws IOException
{
Scanner fin = new Scanner(new File(inputFileName));
// Variables to store the values.[/color]
int account = 0;
double balance = 0.0;

[Code] .....

View Replies View Related

Reading Off A Text File

Apr 26, 2010

What I am trying to use this code for is to scan the files for a match that was typed with the corresponding name. here is what i have:

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

[code]...

View Replies View Related

Reading A File And Methods

Mar 18, 2015

package project3;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
 
[code]....

method countMail!! Also the text file you are reading from is attached as ampo_uumail.txt and i also have a picture of the output.

View Replies View Related

Java File Reading

Sep 22, 2014

Im trying to read a file called m1 and put that information into a 2-D array with the first two numbers being the size of the array i was able to set the size of the array but how do i populate array?

import java.util.Scanner;
import java.io.*;
public class test{
public static void main(String [] args)throws IOException{
Scanner fr = new Scanner(new File("m1.txt"));
String line = fr.nextLine();

[code]....

View Replies View Related

Performing Method On Instance Inside Abstract Class

Mar 12, 2015

How do I create an instance of a class in a method?

I am a bit rusty whenever I think of instances. I always think of main method and objects when I see instance which gets me confused on what to do when I am not in a main method. The example:

I have a abstract class, School, and inside School I have some methods that must preform some action on an instance. For example, there is a move() method that must move the instance of School. Another method named, personOld(), which returns whether or not an instance of School surpassed some determined age.

How do I do this and create this instance?

View Replies View Related

JavaFX 2.0 :: TreeView - Performing Drag / Drop With No Selection

Jul 14, 2014

How do I keep an item (TreeItem) from being selected when performing a drag -n- drop? I don't want it to be selected because it will end up making the target disappear (selection of TreeItem changes target panel).
 
Related question: Is there a way to "veto" a tree selection change as well?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved