hey guys. OK so, I've been wondering this for a while now. my code is always so unnecessarily cluttered because I don't know how to do this, lol. say I have a set of private class variables: [code=java] private ArrayList row0 = new ArrayList<String>(); private ArrayList row1 = new ArrayList<String>(); // etc. all the way to 7 in this case [/code] Now i have a loop where i want to assign (for example), 8 periods or something to each array list as separate elements. I don't want to do this same code and repeat it 8 times for each list, …

Member Avatar
Member Avatar
+0 forum 9

So we have to implement Bresenhams line drawing algorithm as well as Cohen-Sutherland line clipping algorithm. For some reason my whole program (9 classes, but only will include Line.java here) runs fine, but the output .xpm file contains a picture that is not what it's supposed to look like from the input .ps file. Some lines aren't appearing, some appear but are clipped wrong. I'm assuming it's a problem with my algorithms so I was wondering if I could get some feedback. If you guys need to see more of my code let me know as I have it all. …

Member Avatar
+0 forum 0

So one of the problems I have been having with my programs is the length of time it takes to print out a pixel map into the XPM file. I tested it with like : 500 rows and 2 columns -- 1 second 500 rows and 10 columns -- a few seconds 500 rows and 200 columns -- about 20 seconds When I try and output the full 500x500 grid after about 4 minutes it's still not done. Here is the only method I have been using to do this, maybe there is a more efficient way of doing it …

Member Avatar
Member Avatar
+0 forum 1

So I have a lot of code so I guess I'll just post the couple classes that seem to be giving me problems and where the problem is occuring. [CODE=java]// line class to store lines from .ps file class line { // for outcodes private int RIGHT = 2; private int TOP = 8; private int LEFT = 1; private int BOTTOM = 4; // two points signify each line private point point0; private point point1; public line(point _point1, point _point2) { point0 = _point1; point1 = _point2; } public void setPoint1(point _new) { point0 = _new; } public void …

Member Avatar
Member Avatar
+0 forum 1

So I have a JComboBox, which contains recipe names. I want, when the recipe name is changed, for the label that is an icon of the rating (1 to 5) stars, based on my recipe object, to change as well. My code seems like it should work perfect but it doesn't. Any help please? [code=java] import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.BoxLayout; import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.WindowConstants; // GUI Class // Will contain all the code that will display my GUI // Will use the recipe class. public …

Member Avatar
Member Avatar
+0 forum 12

ok so i want to read a .txt file line by line. I have the code for that BUT i want to keep track of what line im on, i might be completely braindead from working on this whole project forever but heres the line by line code i am using. [code=java] // all the code for reading and parsing .txt file and setting up survey (loading) File file = new File(txtFile + ".txt"); FileInputStream fis = null; BufferedInputStream bis = null; DataInputStream dis = null; try { fis = new FileInputStream(file); // Here BufferedInputStream is added for fast reading. …

Member Avatar
Member Avatar
+0 forum 4

So I have my text files saving perfectly from my program in the exact way I want them to. Here is a copy of the text file that my program saves that I am now trying to load back in, parse, and set up internally as another object: [CODE]scott-survey m/c mctext a.b.c.d. essay write about me [/CODE] This is just one of the samples. Here is the code that is supposed to take in this text file and set it all up internally. When I run the code, it recognizes that the text file exists and the directory it is …

Member Avatar
+0 forum 0

So I have this function that is supposed to output an object (save an object) to a .txt file. It doesn't output anything when the program comes to the point where it runs this function. I am 99% sure this is where the program hangs. [code=java] public void saveSurvey(String txtFile) throws SecurityException, IOException { // creates a .txt file of a survey // .txt file will have name on first line // then from then on it will have type of question, followed by question text and then choices (if any) // then the answer // have to have type …

Member Avatar
Member Avatar
+0 forum 2

[code=python] #!/usr/bin/python import os.path n = 10 allPositions = [] state = [] blackPairCap = 0 whitePairCap = 0 blackInaRow = 0 whiteInaRow = 0 row0 = [] row1 = [] row2 = [] row3 = [] row4 = [] row5 = [] row6 = [] row7 = [] row8 = [] row9 = [] allDirections = [[-1, 0],[1, 0],[0, -1],[0, 1],[-1, -1],[-1, 1],[1, -1],[1, 1]] def displayBoard(playersTurn): print "" print " 0 1 2 3 4 5 6 7 8 9 " print " +--+--+--+--+--+--+--+--+--+--+--+" #------------------------------------------------# print "0" + " | " + str(row0[0]) + " " + str(row0[1]) …

Member Avatar
Member Avatar
+0 forum 3

It keeps giving me this elif syntax error in line 103 and I have NO idea where it's coming from. UGH!!! [code=python] #!/usr/bin/python import os.path #nxn board, in this case n = 10 n = 10 #will hold the positions similar to n-queens allPositions = [] #current state of board used for comparisons state = [] #defining captured and inaRow blackPairCap = 0 whitePairCap = 0 blackInaRow = 0 whiteInaRow = 0 #the initial state of the board is all blank #im storing each row of the board as a list #this is pretty much only for displaying the board …

Member Avatar
Member Avatar
+0 forum 5

It keeps giving me this exception when it [I]seems[/I] like I am adding a choice to my choices vector, and I don't know why. Here is that snippet of code. If you need more I can provide it. Thanks ahead of time. [CODE=java]import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Vector; public class multipleChoice extends question { public Vector<String> choices; public multipleChoice() { System.out.println("Please enter the text of your question: "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { String textIn = br.readLine(); text = textIn; System.out.println("Please enter the answer of your question: "); BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in)); try …

Member Avatar
Member Avatar
+0 forum 1

So here is my program: [code=python]#!/usr/local/bin/python #Scott Landau #CS 380 #Assignment 1 Programming Portion in Python #Created - 4/6/09 #Last Edited - 4/22/09 import pdb #n is going to be equal to 4 for this queens problem. n = 4 #Assigning the empty list to initialState. initialState = [] #Making an allDirections list. allDirections = [[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]] #declare the list 'state' which represents the number of non threatening #queens that have been placed on the board. state = [] def goal(state): if ((len(state)) == n): return True else: return False #defining allRules list which the contents of which will be created …

Member Avatar
Member Avatar
+0 forum 2

How come this just hangs, after debugging I found it never returns True for precondition even though it should on the very first go around....ugh!!! [code=python]#!/usr/local/bin/python #Scott Landau #CS 380 #Assignment 1 Programming Portion in Python #Created - 4/6/09 #Last Edited - 4/8/09 import pdb #n is going to be equal to 4 for this queens problem. n = 4 #Assigning the empty list to initialState. initialState = [] #Making an allDirections list. allDirections = [[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]] #declare the list 'state' which represents the number of non threatening #queens that have been placed on the board. state = [] def goal(state): …

Member Avatar
Member Avatar
+0 forum 13

[code]backTrack ( stateList ) ====================== state = first element of stateList if state is a member of the rest of stateList, return 'FAILED-l if deadEnd?(state) return 'FAILED-2 if goal(state), return NULL if length(stateList) > depthBound, return 'FAILED-3 ruleSet = applicableRules(state) if ruleSet == NULL, return 'FAILED-4 for each rule r in ruleSet, newState = applyRule(r,state) newStateList = addToFront(newState,stateList) path = backTrack(newStateList) if path != 'FAILED return append(path,r) return 'FAILED-5[/code] So this is the backTrack algorithm I am working with. I need some help modifying it. I want it, instead of returning a solution path when found, to just print that …

Member Avatar
+0 forum 0

[code=python]#!/usr/local/bin/python #Scott Landau #CS 380 #Assignment 1 Programming Portion in Python #Created - 4/6/09 #Last Edited - 4/7/09 #n is going to be equal to 4 for this queens problem. n = 4 #Assigning the empty list to initialState. initialState = [] #Making an allDirections list. allDirections = [[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]] #declare the list 'state' which represents the number of non threatening #queens that have been placed on the board. state = [] def goal(state): if (len(state) == n): return True else: return False #defining allRules list which the contents of which will be created in next function. allRules = [] #defining …

Member Avatar
Member Avatar
+0 forum 3

[code=python]#!/usr/local/bin/python #Scott Landau #CS 380 #Assignment 1 Programming Portion in Python #Created - 4/6/09 #Last Edited - 4/7/09 #n is going to be equal to 4 for this queens problem. n = 4 #Assigning the empty list to initialState. initialState = [] #Making an allDirections list. allDirections = [[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]] #declare the list 'state' which represents the number of non threatening #queens that have been placed on the board. state = [] def goal(state): if ((len(state)) == n): print "true" return True else: print "false" return False #defining allRules list which the contents of which will be created in next function. …

Member Avatar
Member Avatar
+0 forum 5

[CODE=C++]#include <iostream> #include <fstream> #include <vector> #include <string> #include <sstream> #include <stdio.h> #include <time.h> using namespace std; bool StringToInt(const string &s, int &i); int main() { // opening up and setting up the input file stream so we can read it // to perform the "account info" and the "history" parts of the program. // the inserting part will be done later. ifstream logFileIn; logFileIn.open("logfile.txt"); // store each line of the logfile into an array where each element // of the array is each line of the text file. vector<string> each_Line; ifstream ifs( "logfile.txt" ); string temp; while( getline( ifs, …

Member Avatar
Member Avatar
+0 forum 3

I want to convert two C++ programs into MIPS assembly. Both programs compute if a given integer is prime or not. They both contain the same main() pretty much, but one uses an iterative function while one uses a recursive function. I am not too good with MIPS so I wanted to know if anyone here could offer any help. I want to use the MIPS command "syscall" for the C++ "cout" and "cin" statements. I also want to use the "rem" MIPS instruction for the C++ mod operation. I will paste the two C++ programs below: Iterative: [code=cplusplus] #include …

Member Avatar
Member Avatar
+0 forum 5

i am completely stumped at how to create this program. can anyone help out? here are the guidelines. Introduction Perhaps in no other sport does statistics play as major a role as in the game of Baseball. In fact, certain numbers, such as 56 (length of Joe DiMaggio's hitting streak), 73 (Barry Bonds' single season home run record) and 755 (Hank Aaron's career home run record) are part of American sports culture. You will write a Python program that reads in Baseball statistics for players on various teams from a CSV (comma separated value) file and display statistical information for …

Member Avatar
Member Avatar
+0 forum 2

The End.