Skip to main content

Posts

Showing posts with the label homework

Array lists and string splitting(Java) [closed]

I am trying to read a text file, and read its contends. Easy enough, right? But the files contents read: Part1:Part2 Part1:Part2 I am trying to add the string(s) to a to an array list, with the following protocol: Add "Part1" to an arraylist called p1, then add "Part2" to an arraylist called p2. I need to go through the whole text file with multiple lines. How would I do so?

Socket communication between server and client using threads [closed]

I am busy with a project where the client Gui sends user and password details to a server where the details needs to be verified Sever side against the data in the database on the server. We are required to use Threads(from what I understand is that the Server needs to be able to handle multiple requests). Where I get stuck is when the server is started it is set so that is can listen to requests from clients. However the Server gets stuck listening to client requests until it received a request from the client. Furthermore on the client side if I send wrong username and password I struggle to re-submit the info for verification. This is the code that I have used. Would just like to know if I am on the right track? Firstly I start the server. private void butStartUpServerActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName(driverName); connection = DriverManager.getConnection(SourceURL);

Extending an abstract class [closed]

The following code for RectangleNode extends an abstract class called GraphElement, this is needed for my program to draw rectangles where necessary. My question is regarding the abstract method in GraphElement. Rectangle Node: import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.awt.Color; public class RectangleNode extends GraphElement { private double width = 20; private double length = 40; private Rectangle2D.Double rect; public RectangleNode(int x, int y) { super(x,y); rect = new Rectangle2D.Double(getXPos(), getYPos(), length, width); } public RectangleNode() { super(); rect = null; } public boolean isSelected(double x, double y) { return super(x,y); } public void draw(Graphics2D g2) { if (rect != null) g2.draw(rect); } } Graph Element: import java.awt.Graphics2D; abstract public class GraphElement { private double xPos; private double yPos; protected String label; public GraphElement() {

Multithreading in Java Help Needed

Before I go any further, this IS apart of my homework.The part that I am having trouble with however, is not the main point of the assignment. For the assignment we are just storing numbers in an array, and am adding up the elements of the array via multithreading. The user enters how many threads that they would like to run, and what the upper bound should be. For example: Upper Bound: 12 Threads: 2 The application should add up elements 1-6, then 7-12. In this case the lower bound starts out at 1 and the upper bound starts out at 6. Then the second time the loop should itterate the upper bound should be 7 and the upper bound should be 12. I am having trouble trying to devide the upper bound by the number of threads to create the increments in wich the lower and upper bounds are based off of. It is fairly simple if the number of threads devides evenly into the starting upper bound. But when It doesn't is when I am having the problem. Thank You!

data validation

I am writing a loan calculate with data validation. My maximum loan amount is 1,000,000 and I am using the method below to validate. When I enter 1,000,000 into the program it comes back with my error method. I thought (d >= max) would allow me to go up to and including my max. Can anyone see a problem with this method or is it possible I should be looking elsewhere in my code for a problem. Any help is appreciated. public static double getDoubleWithinRange(Scanner sc, String prompt, double min, double max) { double d = 0.0; boolean isValid = false; while (isValid == false) { d = getDouble (sc, prompt); if (d <= min) { System.out.println( "Error! Number must be greater than " + min + "." ); } else if (d >= max) { System.out.println("Error! Number must be less than " + max + "." ); } else isValid = tr

Clarify what is asked for in java Exceptions assignment

It does not appear evident to me what is asked in a java assignment I have received. Does anyone understand what is needed: In the previous assignment, you implemented a stack and a list that both inherited from the abstract class ArrayIntCollection. In this task you are supposed to extend that implementation by make it throw exceptions if you try to perform operations that are not allowed (for example, if you try to call pop or peek on an empty stack or if you try to remove an element from a non existing position). You shall create and use the exception class CollectionException, of the type UncheckedException. Also write a test program ExceptionMain.java that generates and catches exceptions from your modified methods. The way I understand it, I need to create a exception class called CollectionException , and it needs to extend UncheckedException . (this itself is not working, as I cannot find a class called UncheckedException ). Also, it is obvious if I am to use t

Creating 9 subarrays from a 9x9 2d array java

Hello I need help creating 9 sub arrays of 3x3 dimensions from a 9x9 array. I've seen that stackOverflow had a similar question already asked but unfortunately it was in c++. Can anyone point me in the right direction of how to create a a sub array. Edit: had aa similar changed to had a similar public static void Validate(final int[][] sudokuBoard) { int width = sudokuBoard[0].length; int height = sudokuBoard.length; for(int i = 0; i < width; i++) if(!IsValidRow(sudokuBoard, i, width)) { System.out.print("(Row)" + i + " Error Detected \n"); //Do something - The row has repetitions } for(int j = 0; j < height; j++) if(!IsValidColumn(sudokuBoard, j, height)) { System.out.print(" (Column)" + j + " Error Detected \n"); //Do something - The columns has repetitions } // for(int i=0; i<3; i++) // if(!isBlock1Valid(sudokuB

How to manipulate a rowset data from sql to php

I have asked a question about how to retrieve data from different tables in sql How to get data from 4 tables in 1 sql query? When I run the query for my sample data I get 3 rows, anyway being many-to-many relationship between courses and categories I will always get more rows for same course. My question is how do I handle this data in PHP? I get an array and what I want would be something like: Array ( [0] => stdClass Object ( [name] => course name [tutor] => tutor name [categories] => Array ( categories here ) ); Should I just fetch the data from the categories in a foreach loop after I fetch a course? That would mean bad performance for large amount of data.

how get Image icon in JTable

i have created JTable. i get the value from DB to JTable . i am having problem while click on row it show the image icon path. cannot show the image. how i can set the image. one more thing i am having two images 1. Pointer image 2. Blank Image At the run time Pointer image in a first row by defaulty, After that i clicked in the 5th row, the first row should set with Blank Image, and the 5th rows should be set pointer image. and i don't know its possible in DefaultCellRender. package ex10012012; import java.awt.*; import javax.swing.*; import javax.swing.table.*; import java.sql.*; public class frame10012012 extends javax.swing.JFrame { private DefaultTableModel TmpFlxMdl; private TableColumn TmpFlxColumn; private int TmpRow,TmpFlxDRow; private TableColumn TmpFlxCol; private Statement TmpFlxSt=null; private ResultSet TmpFlxDRs=null; GENLMODL TmpGenModl= new GENLMODL(); FrmM01011 TmpFrmM0101 = new FrmM01011(); public frame10012012() { initCompo