Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Java2D Array Help :(

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Java2D Array Help :(

    Hi, I'm new here and I really need help for my assignment. It's about to be submitted tomorrow but I still can't find the solution. So here's the question :
    Define an executable Java class that will ask user to input three students’ names and the names are kept in an array. The subjects taken by each of these students are English, Mathematics, and History, and these subjects are kept in another array. Allow the user to enter the marks of al the three subjects for each of these three students and these marks will be kept in a multidimensional array. Prompt the user to choose the output format by entering either “By Name” or “By Subject”. If the user entered “By Name”, the program will display the output as shown in the example below:
    English Mathematics History
    Khatijah 83 72 65
    Maniam 86 80 76
    Chong 81 75 70
    If the user entered “By Subject”, the program will display the output as shown in the example below:


    Khatijah Maniam Chong
    English 83 86 81
    Mathematics 72 78 75
    History 65 76 70

    Use the method in JOptionPane class to get the all input from user. You are required to get and display these information using loops. You may use either the equals() or compareTo() methods for the Strings comparison to check the user’s input for the display format.
    Attached Images Attached Images


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java2D Array Help :(

    What have you tried? What do you have so far? Where exactly are you stuck? Where is your MCVE?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java2D Array Help :(

    Quote Originally Posted by KevinWorkman View Post
    What have you tried? What do you have so far? Where exactly are you stuck? Where is your MCVE?

    So far i have done C++ coding and I'm currently try to convert into java coding. What I'm stuck in is the array because I have little knowledge in java array especially. So here's the coding. Could you please help me with this ?

    import javax.swing.JOptionPane;
    public class student
    {
    public static void main(String [] args)
    {
    String[] name= new String [3];
    String [] subject ={"English","Math","History"};
    int [] mark=new int [3][3];
    char option=JOptionPane.showInputDialog("Enter <Name> <English> <Math> <History> :"
    +"\n eg. Najihah 100 100 100");

    for(int i=0;i<3;i++){
    System.out.print(i+1 +" : ");
    name[i];

    for(int j=0;j<3;j++)
    mark[i][j];
    }

    System.out.println("Display by Subject or Name <S/N> : ");


    if((option=='s')||(option=='S')){

    System.out.print("\t\t");
    for(int i=0;i<3;i++){
    System.out.print(name[i] +"\t");
    }
    System.out.println();

    for(int i=0;i<3;i++){
    System.out.print(subject[i] +"\t");

    int temp=i,j=0;
    while(j<3){
    System.out.print("\t"+ mark[temp][j]);
    j++;
    }
    System.out.println();

    }
    }else if((option=='n')||(option=='N')){

    System.out.print("\t\t");
    for(int i=0;i<3;i++){
    System.out.print(subject[i]+"\t");
    }
    System.out.println();


    for(int i=0;i<3;i++){
    System.out.print(name[i]+"\t");

    for(int j=0;j<3;j++){
    System.out.print("\t"+ mark[i][j]);
    }
    System.out.println();

    }
    }

    System.out.println();

    }
    }

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Java2D Array Help :(

    Please post your code using code or highlight tags as explained near the top of this topic.

  5. #5
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Java2D Array Help :(

    Hi there and welcome to the forum

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  6. The Following User Says Thank You to Ada Lovelace For This Useful Post:

    najihah ahmad (September 10th, 2014)

  7. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java2D Array Help :(

    import javax.swing.JOptionPane;
    public class student
    { 
    public static void main(String [] args)
    {
    String[] name= new String [3];
    String [] subject ={"English","Math","History"};
    int [] mark=new int [3][3];
    char option=JOptionPane.showInputDialog("Enter <Name> <English> <Math> <History> :" 
    +"\n eg. Najihah 100 100 100");
     
    for(int i=0;i<3;i++){
    System.out.print(i+1 +" : ");
    name[i];
     
    for(int j=0;j<3;j++)
    mark[i][j];
    }
     
    System.out.println("Display by Subject or Name <S/N> : ");
     
     
    if((option=='s')||(option=='S')){
     
    System.out.print("\t\t");
    for(int i=0;i<3;i++){
    System.out.print(name[i] +"\t");
    }
    System.out.println();
     
    for(int i=0;i<3;i++){
    System.out.print(subject[i] +"\t");
     
    int temp=i,j=0;
    while(j<3){
    System.out.print("\t"+ mark[temp][j]);
    j++;
    }
    System.out.println();
     
    }
    }else if((option=='n')||(option=='N')){
     
    System.out.print("\t\t");
    for(int i=0;i<3;i++){
    System.out.print(subject[i]+"\t");
    }
    System.out.println();
     
     
    for(int i=0;i<3;i++){
    System.out.print(name[i]+"\t");
     
    for(int j=0;j<3;j++){
    System.out.print("\t"+ mark[i][j]);
    }
    System.out.println();
     
    }
    }
     
    System.out.println();
     
    }
    }

  8. #7
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Java2D Array Help :(

    Are you getting any errors? If so post them or explain what about
    the array logic you are struggling with. Btw: class names should start with
    an upper case character.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. compile errors when creating a 2nd array the same size as 1st array
    By javaiscool in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 26th, 2013, 09:35 PM
  2. Replies: 2
    Last Post: January 14th, 2013, 02:22 PM
  3. blending in java2d
    By deepthought in forum Java Theory & Questions
    Replies: 1
    Last Post: June 11th, 2010, 01:45 PM
  4. big problems bounding() in Java2d with LineBreakMeasurer.
    By fenderman in forum AWT / Java Swing
    Replies: 0
    Last Post: July 27th, 2009, 01:15 PM
  5. Replies: 0
    Last Post: October 14th, 2008, 06:40 PM

Tags for this Thread