Jump to content

Does Anyone here Know Java Programming?


Jrod

Recommended Posts

[quote name='bengalrick' post='455948' date='Mar 13 2007, 02:00 PM']the counts[randomNumbers[i]]++ line will build a count for counts[i] whatever i is... therefore, whatever randomNumbers equals, it will add another count to counts[i]...

what might be confussing you about my program is that i am not actually dismissing any duplicates, but am filtering through them with method checkOccurs and then only printing them with the last two methods...

i am seeing somewhat of what your saying, but i got real busy at work all the sudden, so i'll have to figure this out better later on tonight.. thanks again for your help...[/quote]


Yeah I followed that that was what you were doing and according to your requirement that you only need to print the numbers in the array that arent dupes, I guess what Im getting at is how I would do it is create a "clean array" that had only the numbers that wernt dupes in it and print that one.
Link to comment
Share on other sites

Guest bengalrick

[quote name='Jamie_B' post='455955' date='Mar 13 2007, 02:24 PM']Yeah I followed that that was what you were doing and according to your requirement that you only need to print the numbers in the array that arent dupes, I guess what Im getting at is how I would do it is create a "clean array" that had only the numbers that wernt dupes in it and print that one.[/quote]

this shit is pissing me off <_<

i think i was doing some extra steps now that i look back over it...

Link to comment
Share on other sites

[quote name='bengalrick' post='455957' date='Mar 13 2007, 02:38 PM']this shit is pissing me off <_<

i think i was doing some extra steps now that i look back over it...[/quote]


[img]http://forum.go-bengals.com/public/style_emoticons//24.gif[/img]:rofl:[img]http://forum.go-bengals.com/public/style_emoticons//24.gif[/img]:rofl:[img]http://forum.go-bengals.com/public/style_emoticons//24.gif[/img]

Welcome to my world. Your still green eventually this stuff will become 2nd nature.

Link to comment
Share on other sites

[quote name='Jamie_B' post='455962' date='Mar 13 2007, 01:44 PM'][img]http://forum.go-bengals.com/public/style_emoticons/<#EMO_DIR#>/24.gif[/img]:rofl:[img]http://forum.go-bengals.com/public/style_emoticons/<#EMO_DIR#>/24.gif[/img]:rofl:[img]http://forum.go-bengals.com/public/style_emoticons/<#EMO_DIR#>/24.gif[/img]

Welcome to my world. Your still green eventually this stuff will become 2nd nature.[/quote]


Or not.

That's when you find out what really grabs your interest...
Link to comment
Share on other sites

Guest bengalrick
[quote name='Elflocko' post='455975' date='Mar 13 2007, 03:15 PM']Or not.

That's when you find out what really grabs your interest...[/quote]

thats what really sucks... as frustrating as it is, i really like programming... its a great feeling figuring out the problem after all this hard work... this problem just has my brain running in circles, but i will figure it out eventually...
Link to comment
Share on other sites

[quote name='bengalrick' post='455982' date='Mar 13 2007, 03:26 PM']thats what really sucks... as frustrating as it is, i really like programming... its a great feeling figuring out the problem after all this hard work... this problem just has my brain running in circles, but i will figure it out eventually...[/quote]


Thats why I like it as well. We had a issue I was dealing with from the customer for the past few days that I had to investagate to figure out that it wasnt our code, it was bad data that could have been bad for a while because it was part of our app that doesnt get used as much as others, so I had to work with our DBA and the DBA in Tenn (were a nation and terrortry wide app) so we had to track down how from release to releast a paticular table gets updated (meaning does the table get dropped and redone or does it get migrated from release to release with new data updated or added) and get 4. colums for 4 rows in a fixed to fix one persons issue.

Most complex trouble ticket Ive had in a while, most are pretty easy and quick to fix.
Link to comment
Share on other sites

[quote name='Jamie_B' post='456005' date='Mar 13 2007, 03:12 PM']Thats why I like it as well. We had a issue I was dealing with from the customer for the past few days that I had to investagate to figure out that it wasnt our code, it was bad data that could have been bad for a while because it was part of our app that doesnt get used as much as others, so I had to work with our DBA and the DBA in Tenn (were a nation and terrortry wide app) so we had to track down how from release to releast a paticular table gets updated (meaning does the table get dropped and redone or does it get migrated from release to release with new data updated or added) and get 4. colums for 4 rows in a fixed to fix one persons issue.

Most complex trouble ticket Ive had in a while, most are pretty easy and quick to fix.[/quote]

I can ususally figure out what's wrong with a DB in short fashion.


Just don't ask me to go spelunking in 50,000 lines of code... :wacko:

Link to comment
Share on other sites

[quote name='Elflocko' post='456222' date='Mar 13 2007, 09:59 PM']I can ususally figure out what's wrong with a DB in short fashion.
Just don't ask me to go spelunking in 50,000 lines of code... :wacko:[/quote]



It wasnt so much that it was complex from figuring out what the problem was, it was moreso the politics of a programmer having to get a database in Ten updated.

I had to jump through a few hoops, due to the processes involved.

Link to comment
Share on other sites

[quote name='Jamie_B' post='456223' date='Mar 13 2007, 09:01 PM']It wasnt so much that it was complex from figuring out what the problem was, it was moreso the politics of a programmer having to get a database in Ten updated.

I had to jump through a few hoops, due to the processes involved.[/quote]


Well, that and DBA's tend to be such pricks...





:whistle:



:ninja:

Link to comment
Share on other sites

Guest bengalrick

finished last night finally... i appreciate the help jamie... i cleaned up my code and took out some redundancies... finished with a day to spare :)

Link to comment
Share on other sites

[quote name='Elflocko' post='456258' date='Mar 13 2007, 11:27 PM']Well, that and DBA's tend to be such pricks...
:whistle:
:ninja:[/quote]


:lol:

We did have to choose who we called so we could get it done as opposed to going through more hoops.

[quote name='bengalrick' post='456371' date='Mar 14 2007, 10:15 AM']finished last night finally... i appreciate the help jamie... i cleaned up my code and took out some redundancies... finished with a day to spare :)[/quote]


:headbang:

Link to comment
Share on other sites

  • 2 weeks later...
Guest bengalrick
well here we go again... i have been working on this code for literally 2 weeks, and i am finally starting to get it... my damn teacher assigned this shit, but just my luck, the form of input/output text that she gave us an example for is not even mentioned in our book once... and she wants us to use that form of i/o and return a two-dimensional array back to the main method.. I couldn't get anywhere with this until last night, but i didn't get too far then.. then today, the light bulb went off and i think i am pretty close to finishing this code.. but i dont' have access to JCreator here at work so i don't know if it is right or not... i figured though that i could post what i got on here, and w/ the experience some of you have, you might see a mistake or twelve and let me know, which in turn, will save me time and more importantly, my sanity... thanks for any help anyone can give me...

here is the assignment: [code]☯ INF 260-003 Spring 2007 Programming Assignment 5
Your program helps maintain daily inventory at a grocery store. It asks the user to
enter the data file name containing customer receipts, processes the data file, and
then prints out the information about the sales of the day in the output file, “sales.txt”.
The example data file ‘data.txt’ and the output file ‘sales.txt’, after your program runs,
should look like the followings:


<data.txt - input file>[
4.20
8.50
1.99
4.99
3.88
3.25
0
3.99
2.45
0
5.99
23.55
7.89
6.34
6.99
2.53
0
:
:
first receipt
second receipt
many more receipts
third receipts




<sales.txt - output file>
The List of Today's Sales
Customer 0 : 4.20 8.50 1.99 4.99 3.88 3.25
Customer 1 : 3.99 2.45
Customer 2 : 5.99 23.55 7.89 6.34 6.99 2.53
Customer 3 : 1.99 4.99 3.22 3.25
Customer 4 : 3.99 2.45
Customer 5 : 5.99 13.55 6.89
: :
(more customers)
There are 145 receipts in the list.
The total of today's sales is $ 7345.78.
The average of today's sales is $ 50.66.
The highest receipt is $ 354.56.
The lowest receipt is $ 2.45.
Wed Mar 28 13:14:26 EDT 2007




Note :
1. Use a two-dimensional array to store the data from the data file.
2. Use at least three non-void methods (with parameters) that return an array.
3. To access the data file, a user should enter the correct password. The password is “INF260”. The user is
allowed to enter the password not more than three times. If the user fails to enter the correct password
after three trials, the program displays a message dialog box and stops running.
4. The data file is a set of receipts from various customers. Each line shows a dollar amount of a grocery
item or a single 0. Each receipt is separated by the single 0. There is no limit to the number of receipts
possible. The last line of the file should be 0. You should create several data files to test your program.
5. The maximum number of the grocery items in each receipt is 10.
6. The date shown is the day you run the program.
7. Make the comments in your program clear and concise (worth 10% of the points assigned to this HW
project).
DUE: Email the program as an attachment to me by the start of class on 3/28 (W).[/code]

<edit> due date got pushed back to 3/30 (F)...

here is my code:

[code]import java.io.*;
import javax.swing.*;

public class assignment5
{
public static void main(String[] args) throws IOException
{
int countNum = 0;
double totalAmount = 0;
double min = 0;
double max = 0;
double average = 0;
int missedPassword = 0;

fileName = JOptionPane.showInputDialog (null, "Enter the file name to use (data.txt)")
// asks user to enter the file name
if (fileName != "data.txt")
{
JOptionPane.showMessageDialog ("File not found");
System.exit (0); // Stops system if right file name is not entered
}
else
{
password = JOptionPane.showInputDialog (null, "Enter the password");
if (password != "INF260")
{
missedPassword++;
if (missedPassword = 3)
{
JOptionPane.showMessageDialog (null, "Too many tries");
System.exit (0);
}
}

FileReader inputData = new FileReader ("data.txt");
BufferedReader findNumber = new BufferedReader (inputData);

FileWriter writeFile = new FileWriter ("sales.txt");
PrintWriter printFile = new PrintWriter (writeFile);

String str = findNumber.readLine ();

while (str != null)
{
double num = Double.parseDouble (str);

if (num == 0)
{
countNum++; // Number of Reciepts to use

}

double [] entry = new double [countNum][10];

totalAmount = getTotalAmount(entry); // gets the total sales
min = getCurrentMin (entry); // minimum value
max = getCurrentMax (entry); // Maximum value

average = (totalAmount / countNum); // Get average

str = findNumber.readLine();
}

printFile.println ("The List of Today's Sales");

for (int row = 0; row < entry.length; row++) // prints to output file
{
printFile.println ();
printFile.println ("Customer " + row + "\t");
for (int column = 0; column < entry [row].length; column++)
{
if (entry [row].length < 10)
{

printFile.print (entry[row][column] + "\t");
str = findNumber.readLine();


}
else
{
System.out.println ("Too many receipts for one Customer\n");
System.exit (0);


printFile.println ("There are " + countNum + "receipts in the list."); // prints the number of recipts
printFile.println ("The total of today's sales is $" + totalAmount); // prints total sales
printFile.println ("The average of today's sales is $" + average); // prints average sales of day
printFile.println ("The highest receipt is $" + max); // prints highest sales of the day
printFile.println ("The lowest receipt is $" + min); // prints lowest sales of the day
printFile.println ("\n" + date.toStrin()); // prints current date

findNumber.close();
printFile.close();


}


public static double getTotalAmount (double [] entry)
{
double totalAmount = 0;

for (int row = 0; row < entry.length; row++)
{
for (int column = 0; column < entry [row].length; column++)
{
totalAmount += entry [row][column];
}
}
return totalAmount;
}

public static double getCurrentMin (double [] entry)
{
double currentMin = entry[0][0]; // gives currentMin the value of the first number
for (int row = 0; row < entry.length; row++)
{
for (int column = 0; column < entry [row].length; column++)
{
if (currentMin > entry[row][column])
// checks if this is lower than the currently stored currentMin
{
currentMin = entry[row][column];
}
}
}
return currentMin;
}

public static double getCurrentMax (double [] entry)
{
double currentMax = entry[0][0];
for (int row = 0; row < entry.length; row++) // prints to output file
{
for (int column = 0; column < entry [row].length; column++)
{
if (currentMax < entry[row][column]
{
currentMax = entry[row][column];
}
}
}
return currentMax;
}
}[/code]
Link to comment
Share on other sites

Guest bengalrick

[quote name='Jamie_B' post='463719' date='Mar 28 2007, 01:18 PM']What is the issue? Where are you stuck? Are you getting errors? (Havent looked through the code yet)[/quote]

:)

i don't really know... i did most of this on notepad here at work... i am sort of throwing it against the wall and seeing if you (or anyone) can spot any mistakes...

no hard feelings if you don't have time, or don't feel like messing w/ it...

Link to comment
Share on other sites

[quote name='bengalrick' post='463720' date='Mar 28 2007, 01:22 PM']:)

i don't really know... i did most of this on notepad here at work... i am sort of throwing it against the wall and seeing if you (or anyone) can spot any mistakes...

no hard feelings if you don't have time, or don't feel like messing w/ it...[/quote]


Compile it when you get home and see if you got problems then, if so Ill look at it then. I got church band practice tonight but ill be able to look at it after some.

Link to comment
Share on other sites

Guest bengalrick
[quote name='Jamie_B' post='463721' date='Mar 28 2007, 01:27 PM']Compile it when you get home and see if you got problems then, if so Ill look at it then. I got church band practice tonight but ill be able to look at it after some.[/quote]

cool, thanks man...
Link to comment
Share on other sites

Guest bengalrick
[code]import java.io.*;
import javax.swing.*;
import java.util.*;

public class assignment5
{
public static void main(String[] args) throws IOException
{
int countNum = 0;
double totalAmount = 0;
double min = 0;
double max = 0;
double average = 0;
int missedPassword = 0;
String fileName = null;

fileName = JOptionPane.showInputDialog (null, "Enter the file name to use (data.txt)");
// asks user to enter the file name
if (fileName != "data.txt")
{
JOptionPane.showMessageDialog (null, "File not found");
System.exit(0); // Stops system if right file name is not entered
}
else
{
String password = JOptionPane.showInputDialog (null, "Enter the password");
while (password != "INF260")
{
missedPassword++;
if (missedPassword == 3)
{
JOptionPane.showMessageDialog (null, "Too many tries");
System.exit(0);
}
}



FileReader inputData = new FileReader ("data.txt");
BufferedReader findNumber = new BufferedReader (inputData);

FileWriter writeFile = new FileWriter ("sales.txt");
PrintWriter printFile = new PrintWriter (writeFile);

String str = findNumber.readLine ();

while (str != null)
{

double num = Double.parseDouble (str);

if (num == 0)
{
countNum++; // Number of Reciepts to use

}
str = findNumber.readLine();
}

double [][] entry = new double [countNum][10];

totalAmount = getTotalAmount(entry); // gets the total sales
min = getCurrentMin (entry); // minimum value
max = getCurrentMax (entry); // Maximum value

average = (totalAmount / countNum); // Get average




printFile.println ("The List of Today's Sales");

for (int row = 0; row < entry.length; row++) // prints to output file
{
printFile.println ();
printFile.println ("Customer " + row + "\t");
for (int column = 0; column < entry[row].length; column++)
{
if (entry [row].length < 10)
{
printFile.print (entry[row][column] + "\t");
str = findNumber.readLine();
}
else
{
System.out.println ("Too many receipts for one Customer\n");
System.exit (0);
}
}

}





printFile.println ("There are " + countNum + "receipts in the list."); // prints the number of recipts
printFile.println ("The total of today's sales is $" + totalAmount); // prints total sales
printFile.println ("The average of today's sales is $" + average); // prints average sales of day
printFile.println ("The highest receipt is $" + max); // prints highest sales of the day
printFile.println ("The lowest receipt is $" + min); // prints lowest sales of the day
Date date = new Date();
printFile.println ("\n" + date.toString()); // prints current date

findNumber.close();
printFile.close();

}
}


public static double getTotalAmount (double [][] entry)
{
double totalAmount = 0;

for (int row = 0; row < entry.length; row++)
{
for (int column = 0; column < entry [row].length; column++)
{
totalAmount += entry [row][column];
}
}
return totalAmount;
}

public static double getCurrentMin (double [][] entry)
{
double currentMin = entry[0][0]; // gives currentMin the value of the first number
for (int row = 0; row < entry.length; row++)
{
for (int column = 0; column < entry [row].length; column++)
{
if (currentMin > entry[row][column])
// checks if this is lower than the currently stored currentMin
{
currentMin = entry[row][column];
}
}
}
return currentMin;
}

public static double getCurrentMax (double [][] entry)
{
double currentMax = entry[0][0];
for (int row = 0; row < entry.length; row++) // prints to output file
{
for (int column = 0; column < entry [row].length; column++)
{
if (currentMax < entry[row][column])
{
currentMax = entry[row][column];
}
}
}
return currentMax;
}
}[/code]

much improved now that i can check my work, but still not getting the right results... it is compiling but i am getting hung up at entering the data name and the password while the program is running... i think i don't have the brackets right around the if else statements or something... got to go to class... see ya later tonight
Link to comment
Share on other sites

[quote name='bengalrick' post='463883' date='Mar 28 2007, 06:08 PM']much improved now that i can check my work, but still not getting the right results... it is compiling but i am getting hung up at entering the data name and the password while the program is running... i think i don't have the brackets right around the if else statements or something... got to go to class... see ya later tonight[/quote]


And I'm curious; what are you writing this in?

Are you using Netbeans by any chance or another IDE\text editor?
Link to comment
Share on other sites

Guest bengalrick
[quote name='Elflocko' post='464020' date='Mar 29 2007, 12:38 AM']And I'm curious; what are you writing this in?

Are you using Netbeans by any chance or another IDE\text editor?[/quote]

JCreator
Link to comment
Share on other sites

Guest bengalrick
[quote name='Jamie_B' post='463977' date='Mar 28 2007, 10:33 PM']Ok so what exactly are you getting hung up on? Meaning what exactly are you trying to do?[/quote]

i'll start w/ an easy problem... what is wrong w/ this code?:

declared in main method: [i]checkInfo();[/i]

[code] public static void checkInfo ()
{
int missedPassword = 0;

String fileName = JOptionPane.showInputDialog (null, "Enter the file name to use (data.txt)");
// asks user to enter the file name
if (fileName == "data.txt")
{

String password = JOptionPane.showInputDialog (null, "Enter the password");
while (password != "INF260")
{
missedPassword++;
if (missedPassword == 3)
{
JOptionPane.showMessageDialog (null, "Too many tries");
System.exit(0);
}
}


}
else if (fileName != "data.txt")
{
JOptionPane.showMessageDialog (null, "File not found");
System.exit(0); // Stops system if right file name is not entered
}

}[/code]

The code should ask the user to enter the text file name (data.txt) and if he does, it continues. If it doesn't match, it should say "file not found" and stop right there. As far as the password, after three tries it should say "too many tries" and then shut down.
Link to comment
Share on other sites

Guest bengalrick
[quote name='Jamie_B' post='464198' date='Mar 29 2007, 11:59 AM']And what [i]is[/i] it doing?[/quote]

i have been testing w/ it alot so i will explain everything i am doing and what happens...

with the code the same as i posted it, it doesn't matter if i put in the right or wrong file name, it allows it to go the first if statements... just to test it, i changed the code to: <line 8> [i]if (fileName != "data.txt")[/i] to see if that changed it at all, and obvioulsy just the opposite happened... with this, it automatically said "file not found" and then closed down...

then with the password, no matter if i put the right or wrong password in, it goes automatically to "too many tries" and closes down...

for some reason, my "if" and "else if" statements are not working properly... i have a feeling this is an easy mistake i am making, but i am not sure what it is....
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...