Matrix Program - First time using multiple classes

I'm writing a program right now that takes matrices from an input file specified by the user. The file is in this format.
#rows #columns
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
So in place of #rows I would have a 3, and #columns would be a 6. They are seperated by a space, as are the elements.
I have two classes, one entitled Proj6 (Yes, it's a school assignment) and one called Matrix. Proj6 chooses the name of the file to use. After the Matrix class creates the two matrices, using loops, Proj6 then asks what I would like to do to these matrices. I must be able to:
Print the two Matrices
Add
Subtract (just in the order of Matrix 1 - Matrix 2)
Transpose Matrix one.
Quit the program.
Here is my Proj6 Class:
public class Proj6 {
     public static Scanner s;
     public static Scanner f;
     public static void main(String[]args) throws FileNotFoundException {
          System.out.print("Please Enter the filename, complete with extension: ");
          s = new Scanner(System.in);
          f = new Scanner(new File(s.nextLine()));
          String fline = (f.nextLine());
          StringTokenizer st = new StringTokenizer(fline ," ");
          String r = st.nextToken();
          int row = Integer.parseInt(r);
          String c = st.nextToken();
          int col = Integer.parseInt(c);
          Matrix m1 = new Matrix(row,col);
          for (int i = 0; i < row; i++){
               fline = (f.nextLine());
               for (int j = 0; j < col; j++){
                    while (st.hasMoreTokens()){
                    String x = st.nextToken();
                    int value = Integer.parseInt(x);                              
                    m1.setElem(i,j,value);     
          f.nextLine();
          fline = (f.nextLine());
          r = st.nextToken();
          row = Integer.parseInt(r);
          c = st.nextToken();
          col = Integer.parseInt(c);
          Matrix m2 = new Matrix(row,col);
          for (int o = 0; o < row; o++){
               fline = (f.nextLine());
               for (int j = 0; j < col; j++){
                    while (st.hasMoreTokens()){
                    String x = st.nextToken();
                    int value = Integer.parseInt(x);                              
                    m2.setElem(o,j,value);                    
          System.out.println("Enter (p)rint, (a)dd, (t)ranspose, or (q)uit");
          String a = s.nextLine();
          char action = a.charAt(0);
          if (action == 'p') {
                    String print1 = Matrix.toString(m1);
                    System.out.println("First");
                    System.out.println();
                    System.out.print(print1);
                    String print2 = Matrix.toString(m2);
                    System.out.println("Second");
                    System.out.println();
                    System.out.print(print2);
          else if (action == 'a') {
          else if (action == 't') {
                    Matrix m1t = new Matrix(transpose(m1));
                    Matrix m2t = new Matrix(transpose(m2));
                    String print1 = Matrix.toString(m1t);
          else {
                    System.exit(-1);
}Here is my "Matrix" class
import java.util.*;
public class Matrix {
     public int row;
     public int col;
     public int[][] arr = new int[row][col];
     Matrix (int row, int col) {
          arr = new int[row][col];          
     public void setElem(int row, int col, int value) {
          arr[row][col] = value;
     public String toString (Matrix m){
          return null;
     public Matrix plusMatrix (Matrix m) {
          if (m1.length != m2.length || m1.length[0] != m2.length[0]) {
               return null;
          Matrix x = new Matrix(m1.length,m1.length[0]);
          int number;
          for (int i = 0; i<m1.length; i ++) {
               for (int j = 0; j<m1[0].length; j ++) {
                    number = (Integer.parseInt(m1[i][j]) + Integer.parseInt(m2[i][j]));
                    x.setElem(i,j,number);
          return x;
     public Matrix minusMatrix(Matrix m) {
          Matrix x = new Matrix(m1.length, m1.length[0]);
          return x;
     public Matrix transpose (Matrix m) {
          int number;
          Matrix x = new Matrix(m1.length[0],m1.length);
          for (int i = 0; i< m1.length[0]; i ++) {
               for (int j = 0; j<m1.length; j ++) {
                    number = Integer.parseInt(m1[i][j]);
                    x.setElem(i,j,number);                    
          return x;
}I'm having two main problems:
First, my references to "m1" and "m2" in the Matrix class get the cannot be resolved errors. Once I've created the matrices correctly (in theory) why can't I refer to them in Matrix?
Second, I don't think that I'm creating the matrix quite correctly. I know that Tokenizer is technically obsolete, but I'm more familiar with it than the split method.
I'm required to use a toString method in Matrix to "Print" the matrices from each function, but I'm not allowed to send it any parameters, or use any print statements in the Matrix class.
Can you guys catch any errors that I can rectify without necessarily changing my techniques? Or at least provide a thorough explanation for any technique changes?

My new, updated code is having trouble getting the Matrices inputted correctly
public class Proj6 {
     public static Scanner s;
     public static Scanner f;
     public static void main(String[]args) throws FileNotFoundException {
          System.out.print("Please Enter the filename, complete with extension: ");
          s = new Scanner(System.in);
          f = new Scanner(new File(s.nextLine()));
          String fline = (f.nextLine());
          StringTokenizer st = new StringTokenizer(fline ," ");
          int row = Integer.parseInt(st.nextToken());
          int col = Integer.parseInt(st.nextToken());
          Matrix m1 = new Matrix(row,col);
          System.out.println(row + "  " + col);
          System.out.print(fline);
          f.nextLine();
          f.nextLine();
          fline = f.nextLine();
          for (int i = 0; i < row; i++){               
               while (st.hasMoreTokens()) {
                    int value = Integer.parseInt(st.nextToken());
                    System.out.println(value);
                    for (int j = 0; j < col; j++){
                         m1.setElem(i,j,value);     
               fline = (f.nextLine());
          //System.out.println(toString());
          System.out.println(fline);
          System.out.println("Here begins the second matrix");
          int row2 = Integer.parseInt(st.nextToken());
          int col2 = Integer.parseInt(st.nextToken());
          System.out.print(row2 + "  " + col2);
          Matrix m2 = new Matrix(row2,col2);
          for (int o = 0; o < row2; o++){
               f.nextLine();
               while (st.hasMoreTokens()) {
                    int value = Integer.parseInt(st.nextToken());
                    for (int j = 0; j < col2; j++){
                         m2.setElem(o,j,value);                    
          }When I run this code with this matrix file:
3 5
8 19 7 15 4
21 42 9 0 26
13 7 2 1 16
4 5
2 12 6 9 0
40 22 8 4 17
3 13 8 29 10
1 1 1 1 1 I get:
3 5
3 52 12 6 9 0
Here begins the second matrix
it's not moving through correctly. The f.nextLine()operator, and its relation to the string fline is confusing me.
Edited by: Ryanman on Apr 7, 2010 9:31 PM

Similar Messages

  • First time using multiple users - how do I share addy books, etc?

    Hello, We just got the new iMac and for the first time I am setting it up for multiple users. Can anyone guide me to a tutorial or guide on sharing different things between users?
    Specifically, I'd like to share iTunes and iPhoto libraries and also Entourage address books with the new users that have been set up. Probably some other stuff to that I'm not thinking of. I browsed around without any luck.
    Many thanks.

    You're welcome!
    I've been on these discussion boards with various logins I always seem to forget since the iMac first came out, 8 years or so ago.
    LOL Yeah, I have to drop the Welcome... bit. It's bitten me two or three times already since the forums software was changed....
    I'd at least like to import my current address book into my wife's address book...
    Open your Address Book and choose the Directory, 'All.' Select an entry and then do Command-A so that all of the entries are highlighted. Go to the File menu and choose Export vCard. Export it to your Desktop, and then put it in the Shared folder. Log in to your wife's account, open Address Book, and then from the File menu, choose Import > vCards, point to the vCard in the Shared folder, and you're set....

  • First time using imovie

    hi, its my first time using imovie and i'm very impressed by this prog. i'm able to figure out how to insert music.... fonts...etc...etc.... but i just cant figure out how to insert photos!!!! horrible!!!
    Currently i'm creating my movie using one of the themes in the program. Everything's done except inserting picture's in those grey boxes.
    How do i do that?
    Please help!!!
    A million Thanks!!!
    Message was edited by: sistawen

    It took me some time to spot the link to where the instruction manuals were for imovie, take a look it might help you and any other users (including myself) in using the software.
    Here's the link http://www.apple.com/support/manuals/imovie/

  • X230 - Setup Is Preparing Your Computer For First Time Use

    Dear all, 
    I just received my X230 bought on Ebay and as I first turned on the computer, Windows was frozen and showed "Setup Is Preparing Your Computer For First Time Use" for hours (I guess its a whole day). Since I do not have any recovery media provided, does anyone has alternative solution? 
    Thanks in advance!

    Thanks! It took me a whole day to figure out what happened and I ended up format the whole drive and reinstall the windows. Yes, you are right, X230 is a good machine and acutally I was thinking to puchase X240 since there is kind of back to school program that you can purchase X240 at a deep discount price. After so many bad comments I chose X230 instead for: 
    1. Physical Trackpad button (which is extremely important as I ONLY use trackpoint) 
    2. 2 ram slots 
    3. normal voltage CPU
    I am surfing the net with X230 and I am so happy I bought this.

  • First time using "Nokia N8 Ovi Map"

    hello,
    im first time using my n8 ovi map, and i wonder why it took hours for checking for my position,
    after 2-3 hours of waiting, it still searching for my position. instead of keep waiting, i switch to walking mode, and set a destination, now it shows "waiting for GPS". i have been waiting for more than 1 hour, sadly it still showing "waiting for GPS". Anyone experiences this problem before? please provide me some solutions. thanks.

    @NokiN8Silver
    Welcome to the forum!
    You might try as a temporary measure going to Menu > Settings > Application settings > Positioning > Positioning methods - only enable Integrated GPS then go outside away from tall buildings and it should lock on to satellites within 20 -30 minutes; once position established subsequent satellite lock on will be much more rapid.
    Happy to have helped forum with a Support Ratio = 42.5

  • How to use multiple classes for each form

    Hi,
    I have created two forms using screen painter and now i want to use different classes for these two forms .
    I have declared the Sbo Connection in main class i.e. Set Application ,Connection Context() but while connecting to other classes
    for executing the code for that form SAP is not connected to that class.How to use multiple classes functionality i don't able to
    do that.Please provide some sample codes for that as it will be more helpful for me to understand.
    Thanks & Regards,
    Amit

    Hi Amit,
    In fact, its more advisable to use separate classes for every form that you use.  Have one common class, say, for eg., clsMain.cs which has all the connection and connectivity to other classes, wherein, the menu event and item event of this main class, will just be calling the menu / item event of other classes.
    The individual functionality of the child classes will be called from the item / menu event of the respective classes.
    Item event in clsMain.cs will be as below.
    private void oApplication_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
                SAPbouiCOM.Form oForm;
                BubbleEvent = true;
                try
                    if ((pVal.FormTypeEx == "My_Form1Type") && (pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD))
                        oForm = oApplication.Forms.GetForm("My_FormType", pVal.FormTypeCount);
                        NameSpace.Repots.ClsForm1.ClsForm1_ItemEvent(oApplication, oCompany, oForm, ref pVal, ref BubbleEvent);
                    if ((pVal.FormTypeEx == "My_Form2Type") && (pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD))
                        oForm = oApplication.Forms.GetForm("My_FormType", pVal.FormTypeCount);
                        NameSpace.Repots.ClsForm1.ClsForm2_ItemEvent(oApplication, oCompany, oForm, ref pVal, ref BubbleEvent);
    Now, in the individual classes, you can have their respective item events, which will be called from the main class, and the respective functionalities will occur.
    Hope this helps.
    Regards,
    Satish.

  • Qosmio F60 - Each time it starts up, says it is first-time use

    My notebook has just come back from being repaired (they replaced the hard-drive). Now every time I turn it on or it restarts, it says that Windows is configuring the computer for first-time use. Once on, the control panel pops up with 'How to customise your computer'. Plus, a small window pops up with "System Preparation Tool 3.14" and even if I click OK, it doesn't work.
    Otherwise my computer works normally.
    How do I stop my notebook from thinking it's starting for the first time?

    Hi buddy,
    > a small window pops up with "System Preparation Tool 3.14" and even if I click OK, it doesn't work.
    And what happens if you dont click on this tool?
    Maybe the notebook was reinstalled from authorized service provider and so the installation must be finished.
    Otherwise I would recommend reinstalling Windows from Toshiba recovery disk again. Maybe something went wrong during installation and so it would be necessary to reinstall Windows again.
    Check this!!!

  • Help.. First Time Using DVD Studio Pro!!

    OK .. this is my first time using DVD Studio Pro. Before this I have always used IDVD for my Final Cut Projects, but I now need to branch out!
    I've hit a bit of a brick wall. I've watched the video tutorials and tried to read the instruction manual, but it's heavy going!!!.. can someone help me get over the hump?
    Here's where I've got to:
    - In my Assets tab I have my two file - Test.mov QT Video File and Test.mov QT Audio file. Both are yellow uncompressed video. I also have a templates folder.
    - I chose the template called brush cover which I can see under the menu tab on a window. If I go to that same window and select the graphical tab I can see a menu 1 and track 1.
    - In my timeline I have dragged my Video and adui assets over and can see them and actually play the movie.
    - What is also worth mentioning is that I can also see the 18 chapter markers that I created in FCP.
    - Now I hit the brick wall!!.
    - Back in my menu I see 8 buttons. In my timeline I have 18 chapters. How do I transfer my 18 chapters over to my menu so that I have 18 buttons each one representing a chapter?
    - I'm sure that it's obvious and a silly question.. but for a rookie like me who's trying to figure this out from scratch it's not easy!
    Thanks for any advise!!.. also if anyone has a good 'idiot's guide' for ex iDVD people moving to DVD Pro then I'd really appreciate it!
    Many Thanks!
    Steve.
    -

    Steve
    Back in my menu I see 8 buttons. In my timeline I have 18 chapters. How do I transfer my 18 chapters over to my menu so that I have 18 buttons each one representing a chapter?
    You can duplicate your 8 buttons menu so many time as you need to include your 18 chapters, creating a simple new button to navigate through Chapter Menu1, Chapter Menu2, etc.
    Or you can duplicte&resize buttons to fit more of them in a single menu, but 18 button chapters could be too much for a comfortable navigation.
    Thanks for any advise!!.. also if anyone has a good 'idiot's guide' for ex iDVD people moving to DVD Pro then I'd really appreciate it!
    You can use the Search feature in this forum and almost for sure you'll find any answer you need, in particular for basic stuff.
    You can visit Drew13's site [DVD Step by Step|http://www.dvdstepbystep.com] for some good tutorials, and Drew13 uses to stay tuned here to help you too!
    And sometimes Google helps too !
    Hope that helps !
      Alberto

  • Computer keeps Configuring and setting up for first time use

    I have a toshiba A505-S6980 that has been working fine for a couple years.  Recently I had performance issues and suspected virus, spyware so I did a recovery with the original discs I made when I first got the computer.  Four of the six discs reloaded fine.  It did not ask for the last two discs "Environment 64 bit and Applications and Drives.  I also have a System Repair disc.  After loading the four recovery discs the computer now keeps recycling between preparing for first time use, configuring system, reboot and then back to preparing for first time use,etc.  I think I'm close to getting this, but need a last bit of help.
    Thanks

    It's been a couple days since you posted this problem. Did you get anywhere, or are you still stuck in that loop? If it's still stuck, you may just want to perform the recovery again.
    - Peter

  • SQL Server Management Studio - Configuring the environment for first time use

    Hi
    I have recently switched my local 'My Documents' folder location to a network drive that I 'make available off line' to allow on-line/off-line work and synchronisation when I am working in and out of the office.
    When I load my SQL Server Management Studio 2005 I frequently get 'Microsoft SQL Server Management Studio is configuring the environment for first time use'.
    Management Studio  them loads and I can continue without problem.
    I am guessing it is trying to make reference to some settings file. Any ideas? I wonder if I can change/move these settings elsewhere to a local drive?
    Thanks

    Hi,
    There is bug report of this issue:
    http://connect.microsoft.com/SQLServer/feedback/details/126364/configuring-enviroment-for-the-first-time-every-time-in-ms-sql-server-management-express
    "SQL Server Management Studio Express saves the settings for the user in ...\Documents and Settings\<User Profile>\Local Settings\Application Data\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM
    and in ...\Documents and Settings\<user profile>\Application Data\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM
    if any of these files are not available or unusable, SSMSE will generate new ones."
    Hope this helps.
    BR,
    JoukoK

  • Hi I have put money on my apple account and since it's my first time using it I have to answer my security question but I don't remember the answer and when I go forgot answer they send you a code to your email but I have also forgotten my email password

    Hi I have put money on my apple account and since it's my first time using it I have to answer my security question but I don't remember the answer and when I go forgot answer they send you a code to your email but I have also forgotten my email password.

    Reset Security Questions
    http://support.apple.com/kb/HT5312
    If you can't solve problem, call Apple to help reset your Security Question.
    http://support.apple.com/kb/HT5699

  • First time using don't know how to insert the video to start editing

    first time using don't know how to insert the video to start editing

    First thing you should know is that After Effects is not a video editor. Premiere is for putting shots together to tell stories (which is editing), After Effects is for creating those shots (compositing and visual effects) and creating motion graphics.
    To use AE, start here: Getting started with After Effects

  • First time using external hard drive for backup of computer....

    First time using external hard drive for backup of computer....it asks "Do do you want to erase disk?" In order to proceed, I have to say "yes" ... is that what I want to do? ...Seems like I'm skipping a step...

    To use Disk Utilities, attach the drive, open Finder > Applications > Utilities > Disk Utilities and then highlight the LaCie drive in the left panel of the DU window.  In the right panel, choose the Partition button top center of the pane.  Then decide how many partitions you want on the drive, one is just fine.
    Then choose the format, the default is Mac OS Extended (Journaled) which is prefered.
    Then name the partition or drive.
    Then choose the partition table, the default is GUID which is prefered.
    Then Apply and you will get to confirm that you want to erase and format the drive.
    Quit DU and you are ready to go.

  • First time using ical.  Adding an invitee and ical does not accept address

    First time using ical.  adding invitee and ical does not accept address

    CHRIS A123,
    Welcome to Apple Discussions.
    1. Quit iCal, and open System Preferences...>Language & Text>Formats>Region:>reset/choose the appropriate region...also check what you have set in Dates/Times
    2. If that is unsuccessful, I also recommend using the Mac OS X v10.6.2 Update (Combo).
    ;~)

  • First time using iphone~~

    first time using iphone~~
    hello there~~
    i need to know how to activate iphone 4..
    do i need to register itunes for activate phone 4..??
    or not..?? and i don't have credit card...
    can i activate iphone 4 without register itunes and without using credit card ...??
    im sorry~ i just new with iphone 4... pls help me...

    to activate iphone, you should connect your iphone to your computer which should have itunes via your usb cable provided with your iphone problem. and you don't need to register an account to activate the iphone. but you need to register to download apps for iphone.
    it have to be unlocked to work with other country's normal sim card. you should have a malaysian mini sim card to make a normal at&t iphone work in malaysia and other countries.
    if you want to know about unloked phones, go to this webpage-> http://www.tgdaily.com/mobility-opinion/33600-unlocking-the-iphone-what-does-it- mean definition for unlocking--->
    Unlocked is the term used to describe mobile phones that are not tied to a particular service provider in order to be used. Many cell phones are tied to a single cellular provider at their introduction, but are later unlocked for use on many networks.

Maybe you are looking for

  • CS4 Problem getting text from Illustrator over to Photoshop.

    What a mess and why is  this so difficult. I finally figured out how to create my text on a curve and leave the letters going straight up and down. So I am trying to paste or drag and drop over to my bottle in Photoshop but what happens is that the t

  • Problem with displaying Date field in the table.

    Hi All, I am trying to display data into a table UI Element.  In that data, i have one DATE type field. While displaying data in DATE field, it will display like this "01.02.2009". Now my requirement is if i want to modify that DATE field, it will al

  • Selection screen modification based on various buttons in selection screen

    Hi, I have 1 query related with Selection screen modification. In my Report Program,I have created GUI Status for my selection screen Now 2 buttons in application toolbar are coming on selection sceen. For this i used,'At selection screen output' eve

  • Mapping ANSI 856

    Hi Folks, I really wish for your help in mapping the following scenario: Idoc Segment (SOURCE) E1EDL24      MATNR E1EDL24      MATNR 856 Segment (TARGET) G_SHL      S_HL Would it be possible that if the source has 2 entries of E1EDL24 or MATNR it wou

  • Want to learn XML - Please advice

    Dear ALl, So far I am using SQL,PLSQL, Forms/Reports. What XML - is it like SQL- I searched Google, but unable to identify the correct resource. I have installed Oracle 10g on my laptop - is this is enough to practice XML. Please adive