Producing Image By Reading From A Data File Filled With Digits

Nov 16, 2014

I'm a complete beginner in Java programming and I'm interested to learn more about its concepts.

Recently, I've been given an exercise which instructs me to display two versions of a picture. The picture to be displayed is provided in the form of a data file of 40,000 digits that are arranged in rows (although there is no marker between rows) and it starts from the top of the picture. So the first digit represents the top left corner of the picture and the last is the bottom right.

Basically, what the exercise wants me to construct a program that plots a dot in one of two colours for each digit. If the digit is in the range 0 to 3 the output should be one colour and for digits in the range 4 to 9 the dot should be in the other colour.

I understand I have to use arrays and also loops to perform this. I'm familiar with the fillEllipse, drawEllipse, drawRectangle and fillRectangle but this exercise is nothing I've attempted before.

View Replies


ADVERTISEMENT

Reading Data From A File And Putting That Data In Arrays

Feb 8, 2015

I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .

Java Code:

public static void main(String[] args) {
// TODO Auto-generated method stub
// Variables Declaration Section
//******************************
BufferedReader br;
String sCurrentLine;
String str;

[Code] ....

My issue is that the 'str' value is not initialized, but if I initialize it, it ruins the code. I'm not sure what to do in the situation.

View Replies View Related

File Reading Values To Draw Image (java Graphics DrawString / ArrayList / Array)

Sep 13, 2014

//compiler error I'm receiving
J:CS3Student Folder Review Lab #2APlusImage.java:41: error: cannot find symbol
xcor.add(read.nexInt());

[Code].....

View Replies View Related

Reading Data From A File And Setting It To Array

Jun 5, 2014

I can read the data to a monitor perfectly. But, I'm having problem reading data from an external file into an array of class objects. Here's my attempt at writing the method:

private void openFile()
//This method asks the user to enter a file name(including the file extension) and then
//Sets the data to an array of Product type {
String fileName, storeName="", emptyLine1="", emptyLine2="", name="", productName="";
int demandRate=0;
double setupCost=0.0, unitCost=0.0, inventoryCost=0, sellingPrice=0;
Scanner inputStream = null;

[code]...

View Replies View Related

Reading Tabular Format Data From PDF File

Feb 20, 2015

I am working on a project where as an input I need to read to data from PDF.

The PDF data will look like

As shown below:

Serial NoName of bookQuanity of BooksLibrary NamePrice

1aaa1London

2bb2Newyork

3cc1Paris

Total number of books4

Payment info

The number of books are dynamic in every pdf which I am going to receive.

View Replies View Related

Reading Different Types Of Data From A Single Line Of A File?

Oct 12, 2014

I have to read data from a text file and print it in a new text file. An example of one line is like this:
Johnson 85 98 75 89 82

I then have to take the average of all the numbers and assign a "grade" to the numbers for each line of the text file and make a new file so it looks like this for 10 lines:

Name 1 2 3 4 5 Average Grade

Johnson 85 98 75 89 82 85.80 B

My problem is extracting the data from the file so I can use it.

View Replies View Related

How To Improve File Reading Efficiency And Its Data Insertion In Java

Feb 8, 2014

We have an autosys job running in our production on daily basis. It calls a shell script which in turn calls a java servlet. This servlet reads these files and inserts the data into two different tables and then does some processing. Java version is 1.6 & application server is WAS7 and database is oracel-11g.

We get several issues with this process like it takes time, goes out of memory etc etc. Below are the details of the way we have coded this process.

1. When we read the file using BufferedReader, do we really get a lot of strings created in the memory as returned by readLine() method of BufferedReader? These files contain 4-5Lacs of line. All the records are separated by newline character. Is there a better way to read files in java to achieve efficiency? I couldnt find any provided the fact that all the record lines in the file are of variable length.

2. When we insert the data then we are doing a batch process with statement/prepared statement. We are making one batch containing all the records of the file. Does it really matter to break the batch size to have better performance?

3. If the tables has no indexes defined nor any other constraints and all the columns are VARCHAR type, then which operation will be faster:- inserting a new row or updating an existing row based upon some matching condition?

View Replies View Related

I/O / Streams :: Reading From And Writing To A File Then Read Again Including Data Written

Oct 11, 2014

I'm having a bit of trouble with using the Scanner and the Printwriter. I start with a file like this (1 = amount of Houses in the file)

1
FOR SALE:
Emmalaan 23
3051JC Rotterdam
7 rooms
buyprice 300000
energylevel C

The user gets (let's say for simplicity) 3 options:

1. Add a House to the file,
2. Get all Houses which fullfil requirements (price, FOR SALE / SOLD etc.) and
3. Close the application.

This is how I start:

Scanner sc = new Scanner (System.in);
while (!endLoop) {
System.out.println("Make a choice);
System.out.println("1) Add House");
System.out.println("2) Show Houses");
System.out.println("3) Exit");
int choice = sc.nextInt();

Then I have a switch for all of the three cases. I keep the scanner open, so Java can get the user input (house = for sale or sold, price = ... etc). If the user chose option 1, and all information needed is inputted and scanned, the House will be written to the file (which looks like what I typed above).

For this, I use try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("Makelaar.txt", false)))). This works perfectly (at least so it seems.)

If the user chose option 1, and all requirements are inputted and scanned, the Houses will be read (scanner) from the file and outputted. For this I use the same Scanner sc. This also works perfectly (so it seems atleast).

My problem is as follows: If a House has been added, I can only read the House(s) which were already in the file. Let's say I have added 2 houses, and there were from the start 3 houses. If option 2 is chosen, the first 3 houses will be scanned perfectly. An exception will be caught for the remaining 2 (just added) Houses. How can I solve this? I tried to close the Scanner, and reopening it, but apparently Java doesn't agree with this

View Replies View Related

Reading From File And Sort Data Based On Person GPA - Catching Error

Dec 9, 2014

I am catching an error in my driver class that reads from a file and sorts the data based on a person's GPA. Here is my code:

import java.io.*;
import java.util.*;
public class Driver {
public static void main(String[] args) {
new Driver(args[0]);

[Code] ....

Why throwing this exception?

View Replies View Related

User To Input Integer And Then Outputs Both Individual Digits Of Number And Sum Of Digits

Feb 2, 2015

Goal is to: Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.

First I don't know where I made mistakes here, and the only error it finds right now is that str2 was not initialized and I cannot figure out where/when to initialize it.

import javax.swing.JOptionPane;
public class DigitsAndSum {
public static void main (String[] args) {
String str1;
String str2;
int int1 = 0;
int int2 = 0;

[Code] ....

View Replies View Related

Reading DICOM Image From Another Directory

May 5, 2014

I am trying to crate an interface for the following file (code). The interface that I am trying to create will display a open dialog box where the user chooses which image (.dcm) it would like to open and then it should open it in a frame. The code below shows opening the image. The image opens when the image is in the same folder as the source code but I need it to open from a given path and I am really confused on how to do that. I have tried a lot of methods but still doesn't seem work. How to make it work.
 
This is the code (assuming the parameter that you are passing in image.dcm, I have tried a full path name on mac computer which is like /Users/Documents/image.dcm, where this path name never works):
 
/**
* This class displays the first frame of a file from any format
* supported by ImageIO.
* In the case of DICOM files, stored values are displayed as
* is, without using Value of Interest or Presentation LUTs.
*/
class Read1 {
  public static void main(String[] s) {

[Code] .....

View Replies View Related

Reading Image From Folder And Draw It On Jlabel

Jul 1, 2014

I'm trying to read images and draw them on JLabel. This code snippet below is reading images from a folder

private ArrayList<ShowItem> getData() {
int score = 0;
ArrayList<ShowItem> item = new ArrayList<ShowItem>();
File dir = new File(getImageFolderPath());
if (dir.isDirectory()) {
for (final File f : dir.listFiles(IMAGE_FILTER)) {
BufferedImage img = null;
try {

[Code]...

ShowItem is a class that extends Image. DisplayImage extends ShowItem.

One of the overridden methods in ShowItem is

@Override
public Graphics getGraphics() {
return null;
}

I'm not exactly sure what to do here so I left it.

In another class, where I draw the images on Jlabel. This is what I have:

ShowItem theImage;
private ArrayList<ShowItem> listofImages;
theImage = listofImages.get(random.nextInt(listofImages.size()));
ImageIcon icon = new ImageIcon(theImage);
label.setIcon(icon);

I tried to run it, and check if I'm actually getting the images, and did system out and it listed all the jpg images I have but it's not displaying on the panel.

View Replies View Related

JSP :: String URL For Image In Database And Show Image In File

Dec 24, 2014

I had string url for image in mysql database and I want show image in mu jsp file bu I can't.

<c:forEach var="urun" items="${listUrun.rows}">
<tr>
<td><c:out value="${urun.kitapresim}" /></td>
<img src="<c:url value="${urun.kitapresim}" /> " width="270" height="190"/>

URL...

View Replies View Related

Code Keeps Producing NaN

Mar 18, 2015

Code isn't giving me the output that I want and keeps giving me NaN

What I want -

Enter the A value for the line: 2.45
Enter the B value for the line: 4
Enter the C value for the line: -8
Enter the x coordinate of the point: 2.17
Enter the y coordinate of the point: -4

Distance from the point to the line is: 3.9831092774319026

What I am getting

Distance from the point to the line is: NaN

Here is my code-

Tester-

import java.io.*;
import java.util.*;
 class tester
{
public static double A;
public static double B;
public static double C;
public static double distance;
public static void main(String args[])

[Code] ....

View Replies View Related

Reading ASCII Data Correctly

Jan 21, 2015

I have two programs that talk to each other over a TCP connection. When I write the data "STX+1234" where STX is the Ascii character STX or Ctrl B and I expect the written String length to be 6 which it is. On the other side of the socket I create the ServerSocket and use the client socket's InputStream to create a BufferedReader. When I receive the string it now has 12 characters where each original character has been replaced by NUL and the character.  How do I read the string as it is originally specified without the conversion? And is the problem on the reader side or the writer side?

View Replies View Related

How To Make Square Which Is Filled With (dot)

Oct 17, 2014

Do I want to make something like this:

*****
*.....*
*.....*
*.....*
*****

I am stuck, I have made a code that creates this and don't know how to complete it.

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

Code:

class Main {
public static void main( String args[] ) {
System.out.print("#Enter number of stars :");
int stars = BIO.getInt();

[Code] ....

View Replies View Related

Programme Producing NullPointerException

Mar 18, 2014

Am new to programming and am trying to create a system that is similar to a train timetable system.I want the user to be able to enter the stops between two stations ( from a preset list of 5 stations ) and this be saved as an array list, and this array list be saved accordingly within a 2D array so if they were to look in [1][2] there would be an arraylist of stops between station 1 and 2.I used this to initialise the array of arraylists (in a class i created called stops)

ArrayList<String>[][] stopsArray= (ArrayList<String>[][])new ArrayList[5][5];
 
public void stops(){
for (int i = 0; i<5; i++){
for (int j=0; j<5; j++){
stopsArray[i][j]= new ArrayList<String>();
}
}
}

Then I use this code to set the stops

public void setNoStops(int stopsNo){
noOfStops = stopsNo;
}
 
[code]...

The bottom written line of code is mentioned in the null pointer error I recieve. Then.Then in my main programme I declare the new object and use these methods the method options displays the list of five stations with a number reference

System.out.println("Please choose a start station :");
options();
place1 = scanner.nextInt();
System.out.println();
 
System.out.println("Please choose an end station :");
options();
place2 = scanner.nextInt();
System.out.println();

[code]...

mystops is the object I created to store the information.

when compiling I recieve no errors.when I run the program it runs smoothly, asks for the number of stops, allows the user to enter a number, then says enter stop 1, I enter a word and the program crashes giving the error java.lang.NullPointerException

View Replies View Related

Producing Output From Two Different Files

Feb 13, 2015

How can I extract data from two different files but produce one output. For example, the first three columns are from text_file_1 and the last column (the last foruth column of the output) is from text_file_2...

View Replies View Related

JTable Filled From Database

Oct 9, 2014

Im building a program that tracks overtime for employees. Basically there will be a list of employees. Number will be dynamic as different departments will have different amounts of employees.A user could pick the department from a JCombobox. E.g Quality Control. A Jtable will be populated with the employees from Quality Control.

The problem is this.

The way it will work is the list will be in a specific order. Whoever is at the top of the list will be asked if they want to do overtime. Then they will be moved to the back of the queue. If they do the work or not doesnt matter.How would i go about planning a system like this? Specifically creating a dynamic list that people can be moved up and down and stored persistently. URL...

View Replies View Related

Importing CSV / Reading Data And Have A Count Using Queries

Oct 11, 2014

Ok so I know how to import a csv using java. What I'm curious about doing is importing a csv using file chooser, reading the data, sorting the data out by certain parameters, and then outputting a count of each parameter I chose. Say for example I have columns 1,2 and 3. Column 1 has the name, column 2 has the percentage, column 3 has an o'clock time. I want to use queries to sort through the parameters and have a count of each parameter I choose...

View Replies View Related

Reading XML Schema And Obtaining Data From It Using Java

Jan 20, 2015

A method in Java returns a schema. In .net, we use DataTable to get the data from the schema. How to write the following code in Java:

/* Result r = method();
r.DataSchema; */
using (DataTable tbl = new DataTable())
{
using (MemoryStream ms = new MemoryStream())
using (StreamWriter sr = new StreamWriter(ms))

[code]....

View Replies View Related

Run Time Error In Reading Data From Keyboard

Aug 9, 2014

i tried to run simple program od adding two number by using scanner class but there is run time error here it is code file and error.

View Replies View Related

Value Format While Reading Excel Data Into Java

Jan 20, 2015

I am reading Excel data using java apache. I got format issue while reading double value such as 869.87929 (in excel) into 869.8792899999999 (in java).

I'm using following files to read excel data.

1. Schema.csv: SheetName,2-int-Double
2. File.xls:

col1 | col2
123 | 869.87929

Sample code:

if(type.equals("Double")){
String str = content[i-1];
//System.out.println(str);
BigDecimal d = new BigDecimal(str);
listObjects.add(d);
}

Note: type from schema.csv & content [] value from file.xls
If I print **str**, it shows value as 869.8792899999999.
But i need to get **str** value as 869.87929. How can I get it?

View Replies View Related

Stack Is Filled With Numbers And Characters

Oct 31, 2014

I have a Char stack: ArrayStack<Character> stek=new ArrayStack<>();

The stack is filled with numbers and characters (only '+' and '*' ), but I need to make calculations, so I need the INT values of the numbers i pop from the stack. So each time I need to make a calculation, I have to pop two numbers, convert them into INT ,then add/multiply them, and put them back into the stack again, but as CHAR (because the stack is not accepting them to be added as INT)

int a= Character.getNumericValue(stek.pop()); //stack no1
int b= Character.getNumericValue(rezultat.pop()); //stack no2
int tmp=a*b;
char tmp2 = (char) tmp;
stek.push(tmp2);

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







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