Need Help in trying to understand class objects
I need help on understanding following problem.I have two files for that, which are as follows:
first file
public class Matrix extends Object {
private int matrixData[][]; // integer array to store integer data
private int rowMatrix; // number of rows
private int colMatrix; // number of columns
public Matrix( int m, int n )
{ /*Constructor: initializes rowMatrix and colMatrix,
and creates a double subscripted integer array matrix
of rowMatrix rows and colMatrixm columns. */
rowMatrix = m;
colMatrix = n;
matrixData = new int[rowMatrix][colMatrix];
public Matrix( int data[][] )
{ /* Constructor: creates a double subscripted integer array
and initilizes the array using values of data[][] array. */
rowMatrix = data.length;
colMatrix = data[0].length;
matrixData = new int [rowMatrix][colMatrix];
for(int i=0; i<rowMatrix; i++)
for(int j=0; j<colMatrix; j++)
matrixData[i][j] = data[i][j];
public int getElement( int i, int j)
{ /* returns the element at the ith row and jth column of
this matrix. */
return matrixData[i][j];
public boolean setElement( int x, int i, int j)
{ /* sets to x the element at the ith row and jth column
of this matrix; this method should also check the
consistency of i and j (i.e., if i and j are in the range
required for subscripts; only in this situation the operation
can succeed); the method should return true if the operation
succeeds, and should return false otherwise.
for(i=0;i<rowMatrix;i++){
for(j=0;j<colMatrix;j++){
x = matrixData[i][j];
if(i<rowMatrix && j<colMatrix){
return true;
else{
return false;
public Matrix transposeMatrix( )
{ /*returns a reference to an object of the class Matrix,
that contains the transpose of this matrix. */
Verify tata;
Matrix trans;
//Matrix var = matrixData[rowMatrix][colMatrix];
for(int row=0;row<rowMatrix;row++){
for(int col=0;col<colMatrix;col++){
matrixData[rowMatrix][colMatrix] = matrixData[colMatrix][rowMatrix];
trans = new Matrix(matrixData);
return trans;
public Matrix multipleMatrix( Matrix m )
/*returns a reference to an object of the class Matrix,
that contains the product of this matrix and matrix m. */
m = new Matrix(matrixData);
//Matrix var = matrixData[rowMatrix][colMatrix];
for(int row=0;row<rowMatrix;row++){
for(int col=0;col<colMatrix;col++){
//trans[row][col] = getElement(row,col);
return m;
public int diffMatrix( Matrix m )
/*returns the sum of the squared element-wise differences
of this matrix and m ( reference to the formula in the description
of assignment 5) */
return 0;
public String toString( )
/* overloads the toString in Object */
String output = " row = " + rowMatrix + " col="+colMatrix + "\n";
for( int i=0; i<rowMatrix; i++)
for( int j=0; j<colMatrix; j++)
output += " " + getElement(i,j) + " ";
output += "\n";
return output;
Second file
public class Verify extends Object {
public static void main( String args[] )
int[][] dataA = {{1,1,1},{2,0,1},{1,2,0},{4,0,0}}; // data of A
int[][] dataB = {{1,2,2,0},{1,0,3,0},{1,0,3,4}}; // data of B
Matrix matrixA = new Matrix(dataA); // matrix A
System.out.println("Matrix A:"+matrixA);
Matrix matrixB = new Matrix(dataB); // matrix B
System.out.println("Matrix B:"+matrixB);
// Calculate the left-hand matrix
Matrix leftFormula = (matrixA.multipleMatrix(matrixB)).transposeMatrix();
System.out.println("Left Side:"+leftFormula);
// Calculate the right-hand matrix
Matrix rightFormula = (matrixB.transposeMatrix()).multipleMatrix(matrixA.transposeMatrix());
System.out.println("Right Side:"+rightFormula);
// Calculate the difference between left-hand matrix and right-hand matrix
// according to the formula in assignment description
double diff = leftFormula.diffMatrix(rightFormula);
if( diff < 1E-6 ) // 1E-6 is a threshold
System.out.println("Formula is TRUE");
else
System.out.println("Formula is FALSE");
}My basic aim is to verify the formula
(A . B)' =B' . A' or {(A*B)tranpose = Btranspose * A transpose}Now My problem is that I have to run the verify class file and verify class file will call the matrix class and its methods when to do certain calculations (for example to find left formula it calls tranposematrix() and multipleMatrix();)
How will I be able to get the matrix which is to be transposed in transposeMatrix method (in Matrix class)becoz in the method call there is no input for transposematrix() and only one input for multipleMatrix(matrix m).
please peeople help me put in this.
thanking in advance
Please don't crosspost.
http://forum.java.sun.com/thread.jspa?threadID=691969
The other one is the crosspost.Okay, whatever. I'm not really concerned with which one is the original. I just view the set of threads overall as being a crosspost, and arbitrarily pick one to point others toward.
But either way
knightofdurham... pick one thread and post only in
the one.Indeed. And indicate such in the other one.
Similar Messages
-
Re: Beginner needs help using a array of class objects, and quick
Dear Cynthiaw,
I just read your Beginner needs help using a array of class objects, and quick of Dec 7, 2006 9:25 PM . I really like your nice example.
I also want to put a question on the forum and display the source code of my classe in a pretty way as you did : with colors, indentation, ... But how ? In html, I assume. How did you generate the html code of your three classes ? By help of your IDE ? NetBeans ? References ?
I already posted my question with six source code classes ... in text mode --> Awful : See "Polymorphism did you say ?"
Is there a way to discard and replace a post (with html source code) in the Sun forum ?
Thanks for your help.
Chavadachavada wrote:
Dear Cynthiaw,
I just read your Beginner needs help using a array of class objects, and quick of Dec 7, 2006 9:25 PM . I really like your nice example.You think she's still around almost a year later?
I also want to put a question on the forum and display the source code of my classe in a pretty way as you did : with colors, indentation, ... But how ?Just use [code] and [/code] around it, or use the CODE button
[code]
public class Foo() {
* This is the bar method
public void bar() {
// do stuff
}[/code] -
How do I reorder songs in a playlist in the new itunes??? I can no longer just click and drag. When I click, it doesn't move!!!! Need help ASAP- trying to prepare for an aerobics class and need songs in a specific order!
Vera,
Use View > View Options, and set 'Sort By" to "Manual Order."
Then you will be able to drag-n-drop songs up and down the list. -
guys, I need help, im trying to the the new software IOS 7.0 and it requires 3.7 GB free space. im using the IPhone4 and it has 6.4 GB capacity. i've deleted so much and it still says I only have 1.4 GB, I dont understand where the 5GB are being used.
has any one experienced that? I cancelled my icloud account coz i tot the 5GB where there. im so confused. please help.
DeeFirst thing to try is to reset your device. Press and hold the Home and Sleep buttons simultaneously ignoring the red slider should one appear until the Apple logo appears. Let go of the buttons and let the device restart. See if that fixes your problem.
-
I need help I tried to use cloud backup on my iPhone 5.0.1 and after all my camera roll pictures are blurry and videos canot be played messege says URL not on this server ! Please help!!
iPhone 4S, iOS 5.0.1Try updating to iOS 6.1.3.
-
I updated the new IOS 4.3.3 on my IPad, since then i Am having trouble accesesing any App. What happens is i cant enter it or other wise it closes as soon as i enter it...i need help solving tris inconvenient.
I have the same problem and I haven't solved it yet. On Friday I plugged in my iPad to my work computer after not having done so for quite a while. Today I went onto the work computer and discovered I had not updated iTunes before plugging in the iPad (and which I cannot do without an administrator password). I guess I will update iTunes and try again when I can get the guy to show up with the password. I hope that works. The reset idea does not work on mine.
Was your iiTunes updated before you tried? Have you found any solution yet? Mail and some internet apps still work but games, notes applications, spreadsheets etc. just begin to open and close immediately.
If anybody has answers I'd love to get some clues. -
Basic actionscript help, tracing properties of my class object
Hi all,I'm just starting to learn about classes in actionscript, I am following along with Moocks book Actionscript for Flash MX and are trying to execute a trace on the properties of my ballclass but all I get is undefined. He is what I have in my actions panel.
function Ball () {
this.radius = 10;
this.color = 0xFF0000;
this.xPosition = 59;
this.yPosition = 15;
var boucyBall = new Ball();
trace (bouncyBall.radius);
trace (bouncyBall.color);
trace (bouncyBall.xPosition);
trace (bouncyBall.yPosition);
Any help would be greatSince you are learning about classes, you might want to use one to help you:
class Util{
public function Util(){
// empty constructor because you don't need one for this kind of class
public static function traceProps(obj:Object,label:String):Void{
if(label != undefined){
trace(Properties for "+label+":");
for(var a in obj){
trace(" "+a+": "+obj[a]);
trace(newline);
Then place that class file somewhere in your class path so it will always be available to you. And then you can always add these lines.
import com.complexity.Utils;
If the file is in your class path you don't really need the above line, but it will help you remember that you are using it. Also I'm just making up what your class path might be based upon your screen name. You would need to use whatever actual path you had. And then...
Utils.traceProps(bouncyBall,"trouble maker here");
Of course don't use it with an 10,000 element array, unless you really like to suffer.....
or just
Utils.traceProps(bouncyBall); -
Need help on how to access session object in javaBean
Hi All,
I am new to JSP. I have writen a java helper class which gets some data
from a Session Bean.
I want to use <jsp:useBean scope="session"> directive in the JSP.
The helper class requires the reference to session Object to initialize
itself.
It looks like I can only pass Strings Or Basic data Type using
<jsp:setProperty> directive. I want the helper class to initialize only
once per session.
I am using weblogic 4.5 and jdk 1.1.7B.
Need help soon.
Thanks in Advance
Regards
Arun
Arun,
You need only create a method on the bean and call it passing the request
object which contains the
session object. You need not scope to session if you don't need to as well
ie
<jsp:useBean id=foo class= myclass.foo scope="session">
<%
foo.init(reqeust);
%>
Harry
Arun Kumar <[email protected]> wrote in message
news:8itp3l$b67$[email protected]..
> Hi All,
> I am new to JSP. I have writen a java helper class which gets some data
> from a Session Bean.
>
> I want to use <jsp:useBean scope="session"> directive in the JSP.
> The helper class requires the reference to session Object to initialize
> itself.
>
> It looks like I can only pass Strings Or Basic data Type using
> <jsp:setProperty> directive. I want the helper class to initialize
only
> once per session.
>
> I am using weblogic 4.5 and jdk 1.1.7B.
>
> Need help soon.
>
> Thanks in Advance
> Regards
> Arun
>
>
>
-
Help with dynamic creation of class object names
Hi all
Wonder if you can help. I have a class player.java. I want to be able to create objects from this class depending on a int counter variable.
So, for example,
int counter = 1;
Player p+counter = new Player ("Sam","Smith");the counter increments by 1 each time the method this sits within is called. The syntax for Player name creation is incorrect. What I am looking to create is Player p1, Player p2, Player p3.... depending on value of i.
Basically I think this is just a question of syntax, but I can't quite get there.
Please help if you can.
Thanks.
Samhere is the method:
//add member
public void addMember() {
String output,firstName,secondName,address1,address2,phoneNumberAsString;
long phoneNumber;
boolean isMember=true;
this.memberCounter++;
Player temp;
//create HashMap
HashMap memberList = new HashMap();
output="Squash Court Booking System \n";
output=output+"Enter Details \n\n";
firstName=askUser("Enter First Name: ");
secondName=askUser("Enter Second Name: ");
address1=askUser("Enter Street Name and Number: ");
address2=askUser("Enter Town: ");
phoneNumberAsString=askUser("Enter Phone Number: ");
phoneNumber=Long.parseLong(phoneNumberAsString);
Player p = new Player(firstName,secondName,address1,address2,phoneNumber,isMember);
//place member into HashMap
memberList.put(new Integer(memberCounter),p);
//JOptionPane.showMessageDialog(null,"Membercounter="+memberCounter,"Test",JOptionPane.INFORMATION_MESSAGE);
//create iterator
Iterator members = memberList.values().iterator();
//create output
output="";
while(members.hasNext()) {
temp = (Player)members.next();
output=output + temp.getFirstName() + " ";
output=output + temp.getSecondName() + "\n";
output=output + temp.getAddress1() + "\n";
output=output + temp.getAddress2() + "\n";
output= output + temp.getPhoneNumber() + "\n";
output= output + temp.getIsMember();
//display message
JOptionPane.showMessageDialog(null,output,"Member Listings",JOptionPane.INFORMATION_MESSAGE);
}//end addMemberOn running this, no matter how many details are input, the HashMap only gives me the first one back....
Any ideas?
Sam -
I need help! Trying to activate Adobe Creative Suite 3! URGENT
I am trying to activate my application and it's telling me to deactivate the application on an old computer. The old computer was cleaned off so I can't "deactivate" anything. I need help for an immediate project. HELP!
I tried contacting Customer Service but couldn't get through to "chat".This is a user to user forum, not Adobe support... nobody here can help
You must talk to Adobe for this problem
Adobe contact information - http://helpx.adobe.com/contact.html
Adobe Knowledgebase http://www.adobe.com/support/
Help for Download & Install & Setup & Activation http://forums.adobe.com/community/download_install_setup
Next link has a "Chat Now" button near the bottom
http://helpx.adobe.com/x-productkb/policy-pricing/activation-deactivation-products.html -
Need Help! Passing an array of objects to a method, dont understand
Hi, i need to make a method called public Server[] getServers() and i need to be able to see if specific server is available for use.
I have this so far:
public abstract class AbstractServer
protected String serverName;
protected String serverLocation;
public AbstractServer(String name,String location)
this.serverName=name;
this.serverLocation=location;
public abstract class Server extends AbstractServer
public Server(String name,String location)
super(name,location);
public class CreateServers
Server server[];
public CreateServers()
public Server create()
for(int i=0; i<10; i++)
server=new Server(" ", " "); //i was going to fill in something here
return server;
OK NOW HERE IS THE PROBLEM
i have another class that is supposed to manage all these servers, and i dont understand how to do the public Server[] getServers(), this is what i have tried so far
public class ServerManager()
public Server[] getServers(Server[] AbstractServer)
Server server=null; //ok im also confused about what to do here
return server;
in the end i need this because i have a thread class that runs the servers that has a call this like:
ServerManager.getServers("serverName", null);
Im just really confused because i need to get a specific server by name but i have to go through AbstractServer class to get it
Any help?thanks for replying...
ok ill remove the Server.java one to be
public class Server extends AbstractServer
public Resource(String name,String locaton)
super(name,location);
ok so inside ServerManager.java i should have something like
ArrayList servers;
public ServerManager()
servers=new ArrayList();
ok but i still dont get how to use that in a method
say if i put it like this
public getServers()
//populate server list in here??????
ok im still lost... -
Need help Sorting an Arraylist of type Object by Name
Hey guys this is my first time posting on this forum so hopefully i do it the right way. My problem is that i am having difficulties sorting an Array list of my type object that i created. My class has fields for Name, ID, Hrs and Hrs worked. I need to sort this Array list in descending order according to name. Name is the last name only. I have used a bubble sort like this:
public static void BubbleSort(TStudent[] x){
TStudent temp = new TStudent();
boolean doMore = true;
while (doMore) {
doMore = false;
for (int i=0; i < x.length-1; i++) {
if (x.stuGetGPA() < x[i+1].stuGetGPA()) {
// exchange elements
temp = x[i]; x[i] = x[i+1];
x[i+1] = temp;
doMore = true;
before many time to sort an array of my class TStudent according to GPA. This time though i tried using an Array list instead of just a simple array and i can't figure out how i would modify that to perform the same task. Then i googled it and read about the Collections.sort function. The only problem there is that i know i have to make my own comparator but i can't figure out how to do that either. All of the examples of writing a comparator i could find were just using either String's or just simple Arrays of strings. I couldn't find a good example of using an Array list of an Object.
Anyways sorry for the long explanation and any help anyone could give me would be greatly appreciated. Thanks guys
Edited by: Brian13 on Oct 19, 2007 10:38 PMok still having problems I have this line of code to try and all Arrays.sort
Arrays.sort(Employee, TEmployee.FirstNameComparator);Then in my class TEmployee i have
public static Comparator FirstNameComparator = new Comparator() {
public int compare(Object employee, Object anotherEmployee) {
String lastName1 = ((TEmployee) employee).getEmpName().toUpperCase();
String lastName2 = ((TEmployee) anotherEmployee).getEmpName().toUpperCase();
return lastName1.compareTo(lastName2);
};Here is the rundown of what i have for this. I have 2 classes. One is called TEmployee and that class holds fields for Name, ID, Hrs Worked, Hourly Rate. Then i have another class called myCompany that holds an ArrayList of type TEmployee. Then i have my main program in a Jframe.
So maybe i am putting them in the wrong spots. The code in TEmployee thats make the comparator is fine. However when i try to call Arrays.sort from class myCompany i get this
cannot find symbol
symbol: method sort (java.util.Array list<TEmployee>.java.util.Comparator
location: class java.util.Arrays
I have to put the comparator in TEmployee right because thats where my fields for Name are? Do i call the arrays.sort from my main program or do i call that from the class myCompany where my ArrayList of TEmployees are stored?
Again guys thanks for any help you could give me and if you need any code to see what else is going on just let me know. -
Need help with AS 2 Tween class
Hi,
I'm using the tween class just fine, but I want my tween to
move on a curve.
I can't seem to figure out how to achievve this.
I get the math to do this sort of thing, and I think I could
manage it with
AS3, but the project requires the use of AS2. I'm having
issues
transitioning what I know to what I need.
Can anyone help??
Thanks,
KByou can use the tween class to update an object property and,
if you have a parametric equation for your curve, you can use your
tween's onMotionChanged event to update your object's _x and _y
properties. -
Need help calling and looping custom classes
Hi, I am writing a code with custom classes in it and another program that calls upon all of the classes in the first program. I can get the second one (L6) to call upon and execute all of the classes of the first (Foreign). However, I need the second one to loop until quit is selected from the menu on Foreign and I can't seem to figure out how to do it. Here are the codes:
L6:
public class lab6
public static void main(String[] args)
Foreign camount = new Foreign();
camount = new Foreign();
camount.get();
camount.print();
camount.intake();
camount.convert();
camount.vertprint();
System.out.println(camount);
Foreign:
import java.util.Scanner;
public class Foreign
private String country;
private int choice;
private float dollars;
private float conversionValue;
private float conversionAmount;
public Foreign()
country = "null";
choice = 0;
dollars = 0;
conversionValue = 0;
conversionAmount = 0;
public void get()
Scanner Keyboard = new Scanner(System.in);
System.out.println("Foreign Exchange\n\n");
System.out.println("1 = U.S. to Canada");
System.out.println("2 = U.S. to Mexico");
System.out.println("3 = U.S. to Japan");
System.out.println("4 = U.S. to Euro");
System.out.println("0 = Quit");
System.out.print("\nEnter your choice: ");
choice = Keyboard.nextInt();
public void print()
System.out.print("\nYou chose " + choice);
public void intake()
Scanner Keyboard = new Scanner(System.in);
if (choice >= 1 && choice <= 4)
switch (choice)
case 1: System.out.println("\nU.S. to Canada");
conversionValue = 1.1225f;
country = ("Canadian Dollars");
break;
case 2: System.out.println("\nU.S. to Mexico");
conversionValue = 10.9685f;
country = ("Mexican Pesos");
break;
case 3: System.out.println("\nU.S. to Japan");
conversionValue = 118.47f;
country = ("Japanese Yen");
break;
case 4: System.out.println("\nU.S. to Euro");
conversionValue = 0.736377f;
country = ("European Union Euros");
break;
System.out.print("\nEnter U.S. dollar amount: ");
dollars = Keyboard.nextFloat();
public void convert()
conversionAmount = conversionValue * dollars;
public void vertprint()
System.out.println("\nCountry = " + country);
System.out.println("Rate = " + conversionValue);
System.out.println("Dollars = " + dollars);
System.out.println("Value = " + conversionAmount);
public String toString()
String line;
line = "\n" + country + " " + conversionValue + " " + dollars + " " + conversionAmount;
return line;
I appreciate any help anyone can give me. This is driving me crazy. Thanks.1. first you need to write method to get choice value from Foreign class.
simply add this method.
public class Foreign {
// ... Add this
public int getChoice() {
return choice;
}2. Then in your main, you can obtain with previos method.
public static void main(String[] args) {
Foreign camount = new Foreign();
// remove this. you alredy create an instance in last statement.
//camount = new Foreign();
int choice = 0;
do {
camount.get();
choice = camount.getChoice();
// your process...
} while (choice != 0);
} -
Need help with returning an array of object
hello, i've been trying to make a method that returns bot ha boolean and a colour for a render for a Jtable and the code for the method is:
public Object[] isHighlightCellsWithColour(int xInternal, int colInternal) {
Object[] returnWithTwoValue;
boolean isHighLight = false;
returnWithTwoValue = new Object[2];
returnWithTwoValue[0] = isHighLight;
returnWithTwoValue[1] = null;
if (colourPassed == true && this.foundDupeInternal > -1) {
for (int c6 = 0; c6 < foundDupeInternal; c6++) {
if (this.rows[c6] == xInternal && this.cols[c6] == colInternal) {
isHighLight = true;
Color colourToSet = errorColourList[c6];
returnWithTwoValue = new Object[2];
returnWithTwoValue[0] = isHighLight;
returnWithTwoValue[2] = colourToSet;
return returnWithTwoValue;
} else {
return returnWithTwoValue;
return null;
}and when i go and try to use it at
check = new Object[2];
check = isHighlightCellsWithColour(xCurrentlyDrawing, colCurrentlyDrawing);
boolean z = false;
try {
z = (Boolean) check[0];
} catch (NullPointerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Color x = Color.white;
try {
x = (Color)check[1];
} catch (NullPointerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
it gives me a nullpointerexception, which i try to catch, but it STILL gives me that error, i have no clue on how to cast from object back to boolean or colour after they are cast into objects
or else is there a way to pass two different types of data back from a method? Other than using static variables that is, since that gave me problems, it only draws the first cell in colum that is in error in the colour specified , not the rest...
thanks for your time
Edited by: TheHolyLancer on Mar 8, 2008 12:42 AMyay that got it working, but the method still only draws the first cell with the colour only, need another way to do this one...
now comes another puzzeling question, it is giving me an null pointer exception again in:
System.out.println("setting colour "+ x.getBlue() + " On cell " + xCurrentlyDrawing + colCurrentlyDrawing);when i add that to the part where i set the colour, and colour is set to x (which is a color that is passed down by the method) and this will only run if it is determined that a colour is already passed, but it still gives me null pointer error?
maybe i'll take this to the swing forum tommrow
Edited by: TheHolyLancer on Mar 8, 2008 2:17 AM
Edited by: TheHolyLancer on Mar 8, 2008 2:19 AM
Maybe you are looking for
-
Basic Q, Routing all the audio tracks to a bus or aux channel strip ?
I'm a little confused on this issue. I've been doing separate tracks for the sax solos and vocals using the best parts of several tracks with automation. I've been adding the same effect in each track separately and I know this is not good. I'd like
-
Recruitment Workflow : How to fetch applicant details.
Hi I am working on recruitment scenario, where the workflow triggers with the creation of applicant no in PB10. Once the applicant no is generated, a mail needs to be sent to the applicant. Please suggest how to get the communication details for a pa
-
Syntax template not displayin in source editor
In source editor, hot keys or syntax templates are not displaying for example if we presss systme.println. if we press s and ctrl+[Enter] then synatax template will display. but that is not displaying. i am typin the entire syntax. I am using jdevelo
-
Cancel auto-load of images?
My dear wife has assigned me to stop her Adobe Photoshop Album Starter Edition 3.0 from automatically opening and displaying images from a device (jump drive, SD card) when inserted/connected to the PC. I've looked around in Preferences, but I canno
-
Lacie drive in a Network?
I have an eMac which is connected to my wireless router via an ethernet cable and I have an iMac that is wirelessly connected to my router. I was wondering how to have my Lacie external hard drive connected to my network so that I could access the dr