How To Add Doubles From A Text File

Apr 13, 2014

I have a text file that looks like this:

JacobAndrews8159RoseCtMill CityOR97322555212787964.00
RyanPerkins7546PrinceAveLas VegasNV87126555345198913.00
JoshuaGilbert9278MonroeDrCorvallisCA97330555283265695.00
MilesCrain4578ChesterDrCorvallisOR9733155523456781544.00
ButchCassidy5498SuttonPlGresham AZ9738054165657971798.56
PerryWinkle8185ShaverAveLas VegasNV871265553812346195.66

everything is separated by tabs.

My while loop is like this:

while(fileScan.hasNextLine()) {
String currentLine = fileScan.nextLine();
String[]dataSet = currentLine.split(" ");
String zip = dataSet[7];
String phone = dataSet[8];
String donation = dataSet[9];
int ZIP = Integer.parseInt(zip);
Double Donation = Double.parseDouble(donation);

As you can see I made the donation read as a double, my question is how do I get the donation total? I need to write the code to add up and get the total donations but cannot figure it out.

View Replies


ADVERTISEMENT

How To Make A Text File Only Use Lines In A Text File Beginning With A Certain Letter

Mar 15, 2015

I have a program that reads lines of text, but some of the lines of text aren't applicable and break the program. I'd like to put a letter in front of the lines in the .txt file I want to use, such as a #.

I need to make an if loop that'll check for the first letter on the line being #, and use the line in the program if true and skip if false. I'm guessing a boolean variable would be useful here to be true or false depending on the presence of #, but I don't know how to only read the first letter of each line, how can I do this?

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

Dec 12, 2014

I am checking how to do following task.

01. pickup the selected text file and read the line by line and output the text in to visual text pane.

what i did:.

01. I wrote code that read the text file and output in to jave console/ also some of the interface.

the code read txt file:

Java Code:

String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){

[code]....

so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?

View Replies View Related

User Enter A File On Text Field And Display Its Hex Representation In Text Area

Apr 17, 2015

I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.

Here's my code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {

[Code] .....

It's not doing anything, I don't understand why.

View Replies View Related

Read A Text File And Split The Text Into Tokens

Feb 2, 2014

I am trying to read a text file into Java and split the text into tokens. Eventually I want to be able to count the number of instances of a specific word. However, at this point, when I run the file, all I get is the location of the file rather than the text in the file.

import java.util.*;
import java.io.*;
public class textTest3 {
/**
* Prints the number of words in a given file
*
* @param args
* @throws IOException
*/

[Code]...

View Replies View Related

Add Doubles In Array

Jan 20, 2014

I'm allowing the user to choose certain items to buy that is moved to an array.Now I'm trying to add those thing in the array use a different class. how I can call the array from my driver class to my checkout class that adds them together.

View Replies View Related

Scanner Isn't Accepting Doubles

Jan 25, 2014

I had to use scanner to receive input from the user for a formula and everything compiled and worked correctly except when I entered a double into the Scanner, it only accepts ints and gives me this error every time I enter a double:

java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at TestA1Q2.main(TestA1Q2.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

I know that you usually get that error when the Scanner expects something else that is different from what you type and I have looked over my code time and time again and cannot find anything. I created a test program to see if it was just that problem and not something else in the code and I still got the same error but when I tried compiling and running it here browxy.com everything worked and I got the right answer for the formula. Here's the test I used:

import java.util.Scanner;
public class TestA1Q2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a double");
double velocity = keyboard.nextDouble();
}
}

At this point I'm thinking it might be a problem with my install of DrJava and I've tried re-installing but nothing changed.

View Replies View Related

How To Work With Doubles In Arrays

Sep 13, 2014

import java.util.*;
public class OneDimenArray {
public static void main(String[] args) {
double[] decimals = new double[12];
double nums = 0.0;
double a = 1.0;
[Code] ....

These are the erroe codes I'm getting;

OneDimenArray.java:13: error: ']' expected
double[] decimals = double[Scanner.nextDouble()];
^
OneDimenArray.java:13: error: ';' expected
double[] decimals = double[Scanner.nextDouble()];
^
2 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

View Replies View Related

Floats / Doubles And Currency

Mar 8, 2014

Just done a quick test to try and figure out the difference between floats and doubles.I made a quick program which outputs the result of 3.3 * 2 as both a float and a double.

I assumed since a float is the larger and more precise of the two data types that there would be more numbers after the decimal point, however this was not the case, it was in fact the double which had more numbers after the decimal point. Result was as follows:

Float: 29.699999
Double: 29.7

BTW for the above code I simply had a few text fields and a button with the following code:

Java Code:

textBox3.setText("" + Float.parseFloat(textBox1.getText()) * Float.parseFloat(textBox2.getText()));
textBox6.setText("" + Double.parseDouble(textBox1.getText()) * Double.parseDouble(textBox2.getText())); mh_sh_highlight_all('java');

Also, as these are limited to a certain amount of numbers im thinking there must be a more precise way for currency, if so what would I use for that? I suppose what im trying to figure out is what data type to use in different scenarios? When to use integer, float, double and long.

View Replies View Related

Read 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;

[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 quantity after the second comma.....

View Replies View Related

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

Read Text File Into Array Ask User To Save File And Print Data

Jul 14, 2014

New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows

(1) The original list of N numbers from the input file,
(2) The original list of N numbers printed in reverse order of how they appear
in the input file.
(3) The sum and average of these numbers,
(4) The minimum of all the numbers,
(5) The maximum of all the numbers.

[import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

[Code]....

View Replies View Related

Creating A System That Will Ask User To Create A File That Will Store To Text File

Mar 9, 2015

I am new to java and I am creating a system that will ask the user to create a file that will store to a text file, Once the user created the file I have a class that will let the user input the subject name that has been created, However, I keep on getting this java.util.nosuchelementexception.Here's my code:

public void display_by_name()
{
String id, name,total;
String key[]=new String[30];
String value[]=new String[30];
int i=0;

[code]....

View Replies View Related

Set And Assign Doubles - String For Gross Pay?

Dec 15, 2014

I'm working with doubles I'm trying to figure out how to set this up so it works?

I'm just stuck on how to set and Assign a double FedTaxWitholding that gets the Fed Tax Withholding = Gross Pay * Fed
Tax Withholding Rate.

Do I need a string for Gross pay?

View Replies View Related

Java Program Using If / Else - Multiple Doubles

Oct 14, 2014

I am new to Java and I am having trouble figuring out why input.nextDouble(); is not working for the multiple doubles.

import java.util.Scanner;
public class SimpleMenu
{
public static void main(String [] args)
{
int userInput;
int input = 0;
double circleArea = 0;
double triangleArea = 0;
double rectangleArea = 0;

[Code] ....

View Replies View Related

File Handling - Display Path Of The File In Text Field

May 6, 2014

I am facing a problem while executing a task. My task is to make such a code which will search for my source code file (abc.java) in all directories and then displays the code in textarea inside frame and along with that i also have to display the path of the file in text field. I have coded something but i am really not getting anywhere near my task.

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*
 
public class Lab extends JFrame {

[Code] ....

View Replies View Related

Method That Returns Largest Value Of Array Of Doubles?

Jan 26, 2015

Write a Java method that returns the largest value of an array of doubles passed to the method as an argument.

Back into java wasn't sure how to do it for doubles did one in the main for integers and then added a method changed from int to double and now i'm lost as go why its not working.

package kickstarter9;
public class Kickstarter9 {
public static void main(String[] args){
double myList;
double[] myList = {6.0, 4.1, 2.4, 6.8, 1.9, 9.4, 2.8, 4.6, 9.3};
// find the largest value in the list

[Code]...

View Replies View Related

Infix To Prefix - Pow Only Takes Int Values Not Doubles

Feb 7, 2014

I am having a problem with infix and prefix ... Here is the code

import java.util.StringTokenizer;
import static java.lang.Math.pow;
import java.util.Stack;
 public class Calculator {
static int precedence(char op) {
switch(op) {

[Code] ....

it says in line 72
possible loss of precision
required: int
found: double
the pow only takes int values?not doubles?how do i fix it?

View Replies View Related

Return Smallest Of 10 Doubles (User Input)

Oct 1, 2014

This code will let a user type 10 double's, and return the smallest of those 10 double's. But I don't really understand what happens in de last for-loop.

package hsleiden.webcat.exercise06_09;
import java.util.Scanner;
public class Exercise06_09
{
public static void main (String[] args){
double[] allNumbers = new double [10];
 
[Code] ....

View Replies View Related

Program For Adding One Text File Into Zip File Without Extracting

Apr 9, 2015

java code for adding one text file into the zipped file without extracting It is possible in java code ?

View Replies View Related

I/O / Streams :: Retrieving File Directories From A Text File?

Jun 25, 2014

Let's say I have a text file and in the text file exists file directories as such:

'assets/picture1.png'
'assets/picture2.png'

And so on...

How would I then read from this text file and then create those files using 'new File()'?

Here is my code:

private void getFiles() throws IOException{
files = new File[10];
Scanner scan = new Scanner(new File("files.dat"));
int count = -1;

[Code]....

It does print out those files, but it doesn't create them.

View Replies View Related

Swing/AWT/SWT :: Using Doubles For Positioning Objects And Testing Equality

Aug 15, 2014

I've been noticing some of my programs have been a little buggy recently, and think it's down to confusion over doubles and positioning. Lets say I have a label called banner that I want to scroll across the screen. Now I need to know the label's width in order to position it, but the width depends on the amount of text, so i use this code:

double bannerWidth = banner.getWidth();

Which forces me into using a double if I want to be accurate.

But the problem is that I'm trying to use a condition that compares the label's horizontal position (currentX) to the left edge of the screen (LEFT_EDGE), minus the width of the label (bannerWidth). In other words when the label is off the screen, it should go back to its starting position.

I assume that means that any variables I use to track the label's position (in this case currentX), or constants that I use to check equality (LEFT_EDGE), have to be doubles as well?

My difficulty is that I iterate currentX. But currentX--; won't work because doubles don't iterate as I'd expect.

So casting becomes an option..... but if I cast to an integer I effectively lose width on the label. And that is magnified each loop, resulting in the label's starting position moving further and further to the left.

View Replies View Related

Arithmetic Expression That Will Display Doubles To Only One Decimal Place?

Sep 29, 2014

I am looking to find a way to display the number of decimal places without using any type of formatting string.

Only to make it xxx.x instead of xxx.xxxxxx.

View Replies View Related

Formatting Doubles To Two Decimal Places Within Return Statement

Jan 25, 2015

I'm attempting to format my doubles to two decimal places within my return statement. I have tried to use DecimalFormat but it gives me an error because my method needs to return a double and that results in a string being returned. I have also tried using the *100.00/100.00 method and that doesn't work when the number already ends in 0.

If I pass -150.00 it gives me -150.0 when I need two decimal places.

How can I go about doing this?

View Replies View Related

How To Create Jar File Of Program With Text File

Jan 29, 2015

i have made one desktop application with swing and i have uses one textfile (File) in it. i want to handover to another friend to use it . How to create jar file of that program with that text file so that my friend use it without any issue . I have made it in NetBeans

View Replies View Related







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