hi.. uuhhmm..
i have a problem in how to put an String Buffer method here in my code.. uuhhmm.. i just want to know the easiest way of putting a String buffer .. please help . . thanks..

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
        
      public class Change {
      public static void main (String[]args) {
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
  
      int x, a;
  
      Foo foo = new Foo();
      foo.main(null);
  
      }
     
      static class Foo{
      public static void main (String[]args){
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
  
      int x, a, m13;
  
      String[] m9= new String[10];
      String[] m10= new String[10];
      int[] m11= new int[10];
      int[] m12= new int[10];
  
    do{
  
      m1 = JOptionPane.showInputDialog("Student Name:");
      m2 = JOptionPane.showInputDialog("Student ID:");
      m3 = JOptionPane.showInputDialog("Tuition Fee:");
      m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
      a = Integer.parseInt(m0);
  
      for(x=0; x<a; x++)
  
      {
  
      m5 = JOptionPane.showInputDialog("Course Code:");
      m6 = JOptionPane.showInputDialog("Course Name:");
      m7 = JOptionPane.showInputDialog("Credit Hours:");
      m8 = JOptionPane.showInputDialog("Course GRADE:");
      m13 = Integer.parseInt(m7);
  
      }
      JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
      asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
  
      }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');
  
  
      do{
  
    m1 = JOptionPane.showInputDialog("Student Name:");
    m2 = JOptionPane.showInputDialog("Student ID:");
    m3 = JOptionPane.showInputDialog("Tuition Fee:");
    m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:");
  
      a = Integer.parseInt(m0);
  
      for(x=0; x<a; x++)
  
      {
  
      m5 = JOptionPane.showInputDialog("Course Code:");
      m6 = JOptionPane.showInputDialog("Course Name:");
      m7 = JOptionPane.showInputDialog("Credit Hours:");
      m8 = JOptionPane.showInputDialog("Course GRADE:");
  
      } 
     JOptionPane.showMessageDialog(null,temp,"TITLE",JOptionPane.PLAIN_MESSAGE);
      asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
      }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');
  
      
          }
 
        }

      }

I am a little confused. You don't have any StringBuffer objects in this code, do you? I don't see any. When I saw the thread title, I figured you had a StringBuffer object, but it wasn't working and you needed help debugging the code, but again, you don't have any StringBuffer objects, so I'm not sure what you are trying to do with a StringBuffer and where you are trying to do it.

here.. i tried to put a stringbuffer ... it's running ..
but i thinks there is wrong with this program,,
please check .. thanks..

import java.awt.Graphics;
import java.util.Random;
import javax.swing.*;
import java.io.*;   
      
     
       	
      public class mmm {
      public static void main (String[]args) {
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
      String student, courses, answer, result="";
     
      StringBuffer name = new StringBuffer("");
      name.append(",");
    
      String nameStr1 = name.toString();
      String nameStr2 = new String(name);
      
      int x, a;
  
      Foo foo = new Foo();
      foo.main(null);
  
      }
     
    
      static class Foo{
      public static void main (String[]args){
      String m1, m2, m3, m4, m5, m6, m7, m8, asa, m0, naman, temp="";
      String student,courses,answer,result="";
  
  	  StringBuffer name = new StringBuffer("");
      name.append("");
    
      String nameStr1 = name.toString();
      String nameStr2 = new String(name);
      
  
      int x, a, m13;
  
      String[] m9= new String[10];
      String[] m10= new String[10];
      int[] m11= new int[10];
      int[] m12= new int[10];
  
      
      	
    do{
     
      m1 = JOptionPane.showInputDialog("name:" + name);
      m2 = JOptionPane.showInputDialog("Student ID:" + name);
      m3 = JOptionPane.showInputDialog("Tuition Fee:" + name);
      m0 = JOptionPane.showInputDialog("Numbers of Student Enrolled:" + name);
      a = Integer.parseInt(m0);
  	  
     
      for(x=0; x<a; x++)
  
      {
  
      m5 = JOptionPane.showInputDialog("Course Code:" + name);
      m6 = JOptionPane.showInputDialog("Course Name:" + name);
      m7 = JOptionPane.showInputDialog("Credit Hours:" + name);
      m8 = JOptionPane.showInputDialog("Course GRADE:" + name);
      m13 = Integer.parseInt(m7);
     
     
      }
      	JOptionPane.showMessageDialog(null, "Done", "", JOptionPane.INFORMATION_MESSAGE); 
      
      
      asa = JOptionPane.showInputDialog("try again? [Y/N] ...");
      
      }while (asa.charAt(0)=='Y'|| asa.charAt(0)=='y');
  
  
  	
      }
 
          }
 
        }

What exactly is this program supposed to do? What's the goal?

my goal? uhhmm

here the output result i want to do (but ..it make confuse and dizzy for me): .. if the answers of "try again?" is "y" then see the result.. else or "n" .. then closed the showdialogbox..

total no. of credits hour: 20hours
Student Name: Monica Clare Licaros
Student ID: 08003444200
No. of Courses enrolled: 2

hhmm.. thanks advance for helping me.. :D

my goal? uhhmm

here the output result i want to do (but ..it make confuse and dizzy for me): .. if the answers of "try again?" is "y" then see the result.. else or "n" .. then closed the showdialogbox..

total no. of credits hour: 20hours
Student Name: Monica Clare Licaros
Student ID: 08003444200
No. of Courses enrolled: 2

hhmm.. thanks advance for helping me.. :D

String, StringBuilder, StringBuffer are all kind of the same for something this small. You only have one thread, so StringBuilder is faster than StringBuffer (StringBuffer is normally used when you have multiple threads). String methods use StringBuilder methods internally anyway. Java figures it all out for you, particularly for small programs like this. use whichever one (String, StringBuilder, StringBuffer) you are most comfortable with.

It's just a matter of taking the information you get from the user and actually displaying it:

for(x=0; x<a; x++)
  
      {
  
      m5 = JOptionPane.showInputDialog("Course Code:" + name);
      m6 = JOptionPane.showInputDialog("Course Name:" + name);
      m7 = JOptionPane.showInputDialog("Credit Hours:" + name);
      m8 = JOptionPane.showInputDialog("Course GRADE:" + name);
      m13 = Integer.parseInt(m7);


      System.out.println ("total no. of credit hours:" + m7 +  "hours");
      System.out.println ("Student Name: " + m1);     
      // add the other stuff to display here.
      }

You should use more descriptive variable names. m1 , m6 , m7 , etc, aren't very descriptive. Try name , courseGrade , creditHours , etc.

thanks .. its a big help for me..
uuhhmm.. how can i do to the fix answer?

like when if i answer
student name: monica clare

then it proceed to other question..
but when i answer it ..
student Name: blah blah blah or etch..

JOptionPane.showMessageDialog(null,"Invalid Input","Warning", JOptionPane.ERROR_MESSAGE);

..

thanks ..

thanks .. its a big help for me..
uuhhmm.. how can i do to the fix answer?

like when if i answer
student name: monica clare

then it proceed to other question..
but when i answer it ..
student Name: blah blah blah or etch..

JOptionPane.showMessageDialog(null,"Invalid Input","Warning", JOptionPane.ERROR_MESSAGE);

..

thanks ..

You are referring to data validation? As in, you have a String and you want to check whether it contains a "proper" name? First, define exactly what a "proper" or "legal" name is. I don't know if you have used Regular Expressions, but they can be extremely useful for things like this. You can perhaps write a function (I'm going to assume you have NOT used regular expressions here). Something like this (this example assumes very simple rules. Name is legal if it only contains letters or spaces. Normally the rules are more stringent. Again, regular expressions work wonders here and are preferable to the approach below):

boolean LegalName (String userInput)
// userInput is legal name if and only if it contains only letters, spaces
{
     for (int i = 0; i < userInput.length (); i++)
     {
          char currentChar = charAt (i);
          if (currentChar != ' ')
          {
              if (!Character.isLetter (currentChar))
                 return false;
          }
     }

     return true;
}
String userName;  // contains name input from user

if (LegalName (userName))
{
     // code to deal with/display good input
}
else
{
     // code to deal with/display error message for bad input.
}

when i put the code

boolean LegalName (String userInput);

the ";" expected error is existed.. then i put ";"

boolean LegalName (String userInput);

but same thing.. error exist... what wrong with it?

when i put the code

boolean LegalName (String userInput);

the ";" expected error is existed.. then i put ";"

boolean LegalName (String userInput);

but same thing.. error exist... what wrong with it?

It's definitely not this, under any circumstances:

boolean LegalName (String userInput);

That's not a function and that's not a function call. Look at my code. This is a function:

boolean LegalName (String userInput)
// userInput is legal name if and only if it contains only letters, spaces
{
     for (int i = 0; i < userInput.length (); i++)
     {
          char currentChar = charAt (i);
          if (currentChar != ' ')
          {
              if (!Character.isLetter (currentChar))
                 return false;
          }
     }

     return true;
}

You may need to change the first line to this:

public boolean LegalName (String userInput)

or

public static boolean LegalName (String userInput)

Whether it needs to be static depends on how you're calling it and from where and where the function is located, etc. You can always put the public modifier in front. That's a good thing to check if things don't compile.

can anyone give me any ideas on how to code a student assessment system using java??
i'll attach an ER diagram for any pointers... i hope u cud help me with dis..

Attachments ABedE_System.jpg 41.8 KB
This article has been dead for over six months. Start a new discussion instead.