Link to home
Start Free TrialLog in
Avatar of watermelonhahaha778
watermelonhahaha778

asked on

Can anyone help me to solve this question given by the lecture? Quite tough to solve for a junior like me.

Write a Java application for a college's admissions office. Prompt a professor to input grades for five different subjects in order to calculate the grade point average(GPA) for five students. A student receives four grade points for an A, three grade points for a B, two grade points for a C, one grade point for a D, and zero grade points for an F.

Create variables that store the grade point average and an admission test score. Print the message "Accept" if the students has any of the following:

1) A grade point average of 3.6 or above and an admission test score of at least 60.
2) A grade point average of 3.0 or above and an admission test score of at least 70.
3) A grade point average of 2.6 or above and an admission test score of at least 80.
4) A grade point average of 2.0 or above and an admission test score of at least 90.

If the student does not meet any of the qualification, print "Reject". This class name is Admission.

Output Screen:
Enter student id: 9999-9999-9999
Enter student name: ABC
Enter grade for CS211: A
Enter grade for CS212: B
Enter grade for CS213: C
Enter grade for CS214: D
Enter grade for CS215: F
Enter admission test score: 50

Student Id: 9999-9999-9999
Student Name: ABC
CS211: A
CS212: B
CS213: C
CS214: D
CS215: F
GPA: 2.0 and Admission test score:50
Admission: REJECT

Can use the GUI screen which contains all the buttons, textfields and any other relevant components.
Avatar of zzynx
zzynx
Flag of Belgium image

We're not allowed to write code for you.
We're here to help you with the code you already have.
What do you have already?
>> Can use the GUI screen which contains all the buttons, textfields and any other relevant components.

Learn something from: http://java.sun.com/docs/books/tutorial/uiswing/learn/index.html

Plenty of examples at: http://www.javaalmanac.com

Once you have some code of you own, get back to us.
Avatar of RuadRauFlessa
RuadRauFlessa

You could use a GUI bit doing it efficiently might not be as straight forward as you might think. The problem is that you have an unknown number of marks that has to be entered. Then you need some kind of checking to convert the symbol to the actual wheighting that is specified. You need to calculate an aggrigate of the marks/weighting and an average thereof. You would then also need to do some checking to see wether the student qualifies depending on the given criteria.

So there you have it all in a nutshell.
Avatar of watermelonhahaha778

ASKER

import java.awt.*;
public class LabelFrame extends Frame{
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(50);
public LabelFrame(){
      setLayout(new FlowLayout());
      add(Id);
      add(IdField);
      add(Name);
      add(NameField);
      setSize(300,200);
      setVisible(true);
      }
public static void main(String args[]){
      LabelFrame If=new LabelFrame();
      }
}

How to use <BR> like in HTML at here? How to store the value input by the user? Is it using get( ) method?
Ok so you have a start but nothing regarding the marks and such.....

You will need something dynamic like a table or such.
But how to do that? I can't run it because having error.
Can anyone help me please........... :-(

import java.awt.*;
public class LabelFrame extends Frame{
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
public LabelFrame(){
      setLayout(new FlowLayout());
      add(Id);
      add(IdField);
      add(Name);
      add(NameField);
      add(CS211);
      add(CS211Field);
      add(CS212);
      add(CS212Field);
      add(CS213);
      add(CS213Field);
      add(CS214);
      add(CS214Field);
      add(CS215);
      add(CS215Field);
      setSize(300,300);
      setVisible(true);
      }
public static void main(String args[]){
      LabelFrame If=new LabelFrame();
      }
}
I will check for every one hour to look for the response.
import java.awt.*;
public class LabelFrame extends Frame{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
public LabelFrame(){
      f.setLayout(new FlowLayout());
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.setSize(300,300);
      f.setVisible(true);
      }
public static void main(String args[]){
      LabelFrame If=new LabelFrame();
      }
}

I am stuck at here ..........
>> How to use <BR> like in HTML at here?

Not so easy in FlowLayout. Try setting a null layout and use the setBounds ) method for every component to set the width, height and position of the component.

>> How to store the value input by the user? Is it using get( ) method?

The getText () method of the TextArea.

Post your updated code.
>> But how to do that? I can't run it because having error.

The question is what error????

>> Enter grade for CS211: A
>> Enter grade for CS212: B
>> Enter grade for CS213: C
>> Enter grade for CS214: D
>> Enter grade for CS215: F

Will you always have these courses only????

Looks like you have your interface kinda sorted. Now you would also need a calculate button with a submit/calculate button which will trigger an event and then when you receive that event you will have to do all your calculations.

So change  
public class LabelFrame extends Frame{
to
public class LabelFrame extends Frame implements ActionListiner {
and add a method that looks like
public void actionEvent(ActionEvent evt) {
//your calculations will be done here
}

Then you would need to change the symbol to the weighting by means of a switch statement or a series of if statements:
int accumulativeMark = 0;
switch (CS214Field.getText().toUpperCase()) {
case "A" : accumulativeMark += 4;
.
.
.
.
.
.
}

and such
import java.awt.*;
public class LabelFrame extends Frame implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("submit/calculate");

      int accumulativeMark = 0;
      switch (CS214Field.getText().toUpperCase()) {
      case "A" : accumulativeMark += 4;
               break;
      case "B" : accumulativeMark += 3;
               break;
      case "C" : accumulativeMark += 2;
               break;
      case "D" : accumulativeMark += 1;
               break;
      case "F" : accumulativeMark += 0;
               break;
      }

public void actionPerformed(ActionEvent evt) {
      

}

public LabelFrame(){
      f.setLayout(new FlowLayout());
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      f.setSize(300,350);
      f.setVisible(true);
      }
public static void main(String args[]){
      LabelFrame If=new LabelFrame();
      }
}

Am i place it in the correct location ???? But it show two errors..........
Yeah well you kinda have to add
import the java.awt.event.*;
at the top. Then after
     f.add(ScoreField);
     f.add(B1);
add
     B1.addActionListener(this);
also
int accumulativeMark = 0;
     switch (CS214Field.getText().toUpperCase()) {
     case "A" : accumulativeMark += 4;
             break;
     case "B" : accumulativeMark += 3;
             break;
     case "C" : accumulativeMark += 2;
             break;
     case "D" : accumulativeMark += 1;
             break;
     case "F" : accumulativeMark += 0;
             break;
     }

is supposed to be within the event callback method
public void actionPerformed(ActionEvent evt) {
     
}

like
public void actionPerformed(ActionEvent evt) {
     int accumulativeMark = 0;
     switch (CS214Field.getText().toUpperCase()) {
     case "A" : accumulativeMark += 4;
             break;
     case "B" : accumulativeMark += 3;
             break;
     case "C" : accumulativeMark += 2;
             break;
     case "D" : accumulativeMark += 1;
             break;
     case "F" : accumulativeMark += 0;
             break;
     }
}

but then you still need to calculate average and wether there student may be granted admission.
but now it shows 1 error in here.
 
switch (CS214Field.getText().toUpperCase()) {
What is the error???
imcompatible types
import java.awt.*;
import java.awt.event.*;
public class LabelFrame extends Frame implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("submit/calculate");

public void actionPerformed(ActionEvent evt) {
      int accumulativeMark = 0;
      switch (CS214Field.getText().toUpperCase()) {
      case 'A' : accumulativeMark += 4;
               break;
      case 'B' : accumulativeMark += 3;
               break;
      case 'C' : accumulativeMark += 2;
               break;
      case 'D' : accumulativeMark += 1;
               break;
      case 'F' : accumulativeMark += 0;
               break;
      }

}

public LabelFrame(){
      f.setLayout(new FlowLayout());
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.setSize(300,350);
      f.setVisible(true);
      }
public static void main(String args[]){
      LabelFrame If=new LabelFrame();
      }
}

you can try and run it............
I think I will do that quickly and check it out. brb
change the actionPerformed method to something like

   public void actionPerformed(ActionEvent evt) {
        int accumulativeMark = 0;
        accumulativeMark += getAccIncrease(CS211Field.getText());
        accumulativeMark += getAccIncrease(CS212Field.getText());
        accumulativeMark += getAccIncrease(CS213Field.getText());
        accumulativeMark += getAccIncrease(CS214Field.getText());
        accumulativeMark += getAccIncrease(CS215Field.getText());
        // do your average calculation here
    }

and add the following method somewhere

   private int getAccIncrease(String mark) {
        if (mark.equalsIgnoreCase("A")) {return 4;}
        else if (mark.equalsIgnoreCase("B")) {return 3;}
        else if (mark.equalsIgnoreCase("C")) {return 2;}
        else if (mark.equalsIgnoreCase("D")) {return 1;}
        return 0;        
    }

you do not have to check for F since if it is not A,B,C or D it has to be F
Not sure if you can have switch-case over Strings. The value you've placed as an argument to the switch is a String whereas the cases contain characters. Try this:

switch ( CS214Field.getText ().toUpperCase ().charAt ( 0 ) ) {
Or check out my prevoius post which is a much more robust way that does not replicate code.
.toUpperCase ().charAt ( 0 )

What is the use of toUpperCase( ) and charAt(0) ????
toUpperCase() converts the string to an upper case representation of itself and charAt(0) returns the first character in that string.
import java.awt.*;
import java.awt.event.*;
public class LabelFrame extends Frame implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("submit/calculate");
      
public void actionPerformed(ActionEvent evt) {

      int accumulativeMarkCS211 = 0;
      switch (CS211Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS211 += 4;
               break;
      case 'B' : accumulativeMarkCS211 += 3;
               break;
      case 'C' : accumulativeMarkCS211 += 2;
               break;
      case 'D' : accumulativeMarkCS211 += 1;
               break;
      case 'F' : accumulativeMarkCS211 += 0;
               break;
      }

      int accumulativeMarkCS212 = 0;
      switch (CS212Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS212 += 4;
               break;
      case 'B' : accumulativeMarkCS212 += 3;
               break;
      case 'C' : accumulativeMarkCS212 += 2;
               break;
      case 'D' : accumulativeMarkCS212 += 1;
               break;
      case 'F' : accumulativeMarkCS212 += 0;
               break;
      }

      int accumulativeMarkCS213 = 0;
      switch (CS213Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS213 += 4;
               break;
      case 'B' : accumulativeMarkCS213 += 3;
               break;
      case 'C' : accumulativeMarkCS213 += 2;
               break;
      case 'D' : accumulativeMarkCS213 += 1;
               break;
      case 'F' : accumulativeMarkCS213 += 0;
               break;
      }

      int accumulativeMarkCS214 = 0;
      switch (CS214Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS214 += 4;
               break;
      case 'B' : accumulativeMarkCS214 += 3;
               break;
      case 'C' : accumulativeMarkCS214 += 2;
               break;
      case 'D' : accumulativeMarkCS214 += 1;
               break;
      case 'F' : accumulativeMarkCS214 += 0;
               break;
      }

      int accumulativeMarkCS215 = 0;
      switch (CS215Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS215 += 4;
               break;
      case 'B' : accumulativeMarkCS215 += 3;
               break;
      case 'C' : accumulativeMarkCS215 += 2;
               break;
      case 'D' : accumulativeMarkCS215 += 1;
               break;
      case 'F' : accumulativeMarkCS215 += 0;
               break;
      }
}

public LabelFrame(){
      f.setLayout(new FlowLayout());
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.setSize(300,350);
      f.setVisible(true);
      }
public static void main(String args[]){
      LabelFrame If=new LabelFrame();
      }
}

Can I change to this ???? How to use getText( ) to store the student Id ????
String sStudentId = IdField.getText () ;
Also better to trim () all Strings when you get them from the text-field.
I need to bed. Have a sweet dream you guys ......
Did that getText () work?
I just add this :

String StudentId = IdField.getText () ;
String StudentName = NameField.getText();
String StudentScore = ScoreField.getText () ;

why we use String to store numbers ??? Got error when use int. Can it stores with numbers ???
If the IdField contains only a numeric value, you can parse it to an 'int':

int iStudentId = Integer.parseInt ( IdField.getText ().trim () ) ;

To be on the safe side, catch a NumberFormatException which might be thrown there.
Is it like this ???? The GPA show on MSDOS only, how to make it show on output screen ????


public void actionPerformed(ActionEvent evt) {
      try{
      int StudentId = Integer.parseInt ( IdField.getText ().trim () ) ;
      } catch(NumberFormatException NFE){}
      String StudentName = NameField.getText();
      
      int accumulativeMarkCS211 = 0;
      switch (CS211Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS211 += 4;
               break;
      case 'B' : accumulativeMarkCS211 += 3;
               break;
      case 'C' : accumulativeMarkCS211 += 2;
               break;
      case 'D' : accumulativeMarkCS211 += 1;
               break;
      case 'F' : accumulativeMarkCS211 += 0;
               break;
      }

      int accumulativeMarkCS212 = 0;
      switch (CS212Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS212 += 4;
               break;
      case 'B' : accumulativeMarkCS212 += 3;
               break;
      case 'C' : accumulativeMarkCS212 += 2;
               break;
      case 'D' : accumulativeMarkCS212 += 1;
               break;
      case 'F' : accumulativeMarkCS212 += 0;
               break;
      }

      int accumulativeMarkCS213 = 0;
      switch (CS213Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS213 += 4;
               break;
      case 'B' : accumulativeMarkCS213 += 3;
               break;
      case 'C' : accumulativeMarkCS213 += 2;
               break;
      case 'D' : accumulativeMarkCS213 += 1;
               break;
      case 'F' : accumulativeMarkCS213 += 0;
               break;
      }

      int accumulativeMarkCS214 = 0;
      switch (CS214Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS214 += 4;
               break;
      case 'B' : accumulativeMarkCS214 += 3;
               break;
      case 'C' : accumulativeMarkCS214 += 2;
               break;
      case 'D' : accumulativeMarkCS214 += 1;
               break;
      case 'F' : accumulativeMarkCS214 += 0;
               break;
      }

      int accumulativeMarkCS215 = 0;
      switch (CS215Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS215 += 4;
               break;
      case 'B' : accumulativeMarkCS215 += 3;
               break;
      case 'C' : accumulativeMarkCS215 += 2;
               break;
      case 'D' : accumulativeMarkCS215 += 1;
               break;
      case 'F' : accumulativeMarkCS215 += 0;
               break;
      }
      
      String StudentScore = ScoreField.getText () ;

      int GPA=(accumulativeMarkCS211 + accumulativeMarkCS212 + accumulativeMarkCS213 + accumulativeMarkCS214 + accumulativeMarkCS215)/5;
      System.out.println("GPA: " +GPA);
}
That's because of the System.out.println (). If you want to show it on your Frame, add a Component to show it. Maybe a disabled text-area or a label.

Label lblGpa = new Label ( "GPA: " ) ; // after you declare all the other labels/ text-fields
add ( lblGpa ) ;

By the way, since your class already extends Frame, you don't need the 'f' Frame. You can directly use:

add ( Id ) ;

- instead of f.add ( Id ) ;

After doing your computations in the actionPerformed () method, set the GPA as the text for the label:

lblGpa.setText ( lblGpa.getText () + GPA ) ;
>> - instead of f.add ( Id ) ;

If you want to stick with your current approach, use: f.add ( lblGpa ) ;
import java.awt.*;
import java.awt.event.*;
public class LabelFrame implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("submit/calculate");
      Label lblGpa = new Label ( "GPA: " ) ;
      
      
public void actionPerformed(ActionEvent evt) {
      try{
      int StudentId = Integer.parseInt ( IdField.getText ().trim () ) ;
      } catch(NumberFormatException NFE){}

      String StudentName = NameField.getText();
      
      int accumulativeMarkCS211 = 0;
      switch (CS211Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS211 += 4;
               break;
      case 'B' : accumulativeMarkCS211 += 3;
               break;
      case 'C' : accumulativeMarkCS211 += 2;
               break;
      case 'D' : accumulativeMarkCS211 += 1;
               break;
      case 'F' : accumulativeMarkCS211 += 0;
               break;
      }

      int accumulativeMarkCS212 = 0;
      switch (CS212Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS212 += 4;
               break;
      case 'B' : accumulativeMarkCS212 += 3;
               break;
      case 'C' : accumulativeMarkCS212 += 2;
               break;
      case 'D' : accumulativeMarkCS212 += 1;
               break;
      case 'F' : accumulativeMarkCS212 += 0;
               break;
      }

      int accumulativeMarkCS213 = 0;
      switch (CS213Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS213 += 4;
               break;
      case 'B' : accumulativeMarkCS213 += 3;
               break;
      case 'C' : accumulativeMarkCS213 += 2;
               break;
      case 'D' : accumulativeMarkCS213 += 1;
               break;
      case 'F' : accumulativeMarkCS213 += 0;
               break;
      }

      int accumulativeMarkCS214 = 0;
      switch (CS214Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS214 += 4;
               break;
      case 'B' : accumulativeMarkCS214 += 3;
               break;
      case 'C' : accumulativeMarkCS214 += 2;
               break;
      case 'D' : accumulativeMarkCS214 += 1;
               break;
      case 'F' : accumulativeMarkCS214 += 0;
               break;
      }

      int accumulativeMarkCS215 = 0;
      switch (CS215Field.getText ().toUpperCase ().charAt ( 0 ) ) {
      case 'A' : accumulativeMarkCS215 += 4;
               break;
      case 'B' : accumulativeMarkCS215 += 3;
               break;
      case 'C' : accumulativeMarkCS215 += 2;
               break;
      case 'D' : accumulativeMarkCS215 += 1;
               break;
      case 'F' : accumulativeMarkCS215 += 0;
               break;
      }
      
      try{
      int StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
      } catch(NumberFormatException NFE){}
      
      float GPA=(float)(accumulativeMarkCS211 + accumulativeMarkCS212 + accumulativeMarkCS213 + accumulativeMarkCS214 + accumulativeMarkCS215)/5;
      lblGpa.setText ( lblGpa.getText () + GPA ) ;
}

public LabelFrame(){
      f.setLayout(new FlowLayout());
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.add(lblGpa);
      f.setSize(300,350);
      f.setVisible(true);
      }
public static void main(String args[]){
      LabelFrame If=new LabelFrame();
      }
}

but something wrong with the output screen, can't see the float number.............
Instead of
lblGpa.setText ( lblGpa.getText () + GPA ) ;

use
lblGpa.setText ( "GPA: " + (float)GPA ) ;

if you use the top one you will have a problem if the user presses the calculate button more than once.

Also have you taken a look at my previous posts
>change the actionPerformed method to something like
>
>   public void actionPerformed(ActionEvent evt) {
>        int accumulativeMark = 0;
>        accumulativeMark += getAccIncrease(CS211Field.getText());
>        accumulativeMark += getAccIncrease(CS212Field.getText());
>        accumulativeMark += getAccIncrease(CS213Field.getText());
>        accumulativeMark += getAccIncrease(CS214Field.getText());
>        accumulativeMark += getAccIncrease(CS215Field.getText());
>        // do your average calculation here
>    }
>
>and add the following method somewhere
>
>   private int getAccIncrease(String mark) {
>        if (mark.equalsIgnoreCase("A")) {return 4;}
>        else if (mark.equalsIgnoreCase("B")) {return 3;}
>        else if (mark.equalsIgnoreCase("C")) {return 2;}
>        else if (mark.equalsIgnoreCase("D")) {return 1;}
>        return 0;        
>    }
>
>you do not have to check for F since if it is not A,B,C or D it has to be F

I am referring to the above one. It will make your life sooo much easier especially if you have to find an error. It will also make it much easier to read and understand.
ok........ I changed to this one & name it as LabelFrame1...
If I set the Layout as null, every things will gone, what should I add or modify ???

import java.awt.*;
import java.awt.event.*;
public class LabelFrame1 implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("submit/calculate");
      Label lblGpa = new Label ( "GPA: " ) ;
      
      
public void actionPerformed(ActionEvent evt) {
      try{
      int StudentId = Integer.parseInt ( IdField.getText ().trim () ) ;
      } catch(NumberFormatException NFE){}

      String StudentName = NameField.getText();

        int accumulativeMark = 0;
        accumulativeMark += getAccIncrease(CS211Field.getText());
        accumulativeMark += getAccIncrease(CS212Field.getText());
        accumulativeMark += getAccIncrease(CS213Field.getText());
        accumulativeMark += getAccIncrease(CS214Field.getText());
        accumulativeMark += getAccIncrease(CS215Field.getText());
      
      try{
      int StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
      } catch(NumberFormatException NFE){}
      
      float GPA=(float)accumulativeMark/5;
      lblGpa.setText ( "GPA: " + (float)GPA  ) ;
}

public LabelFrame1(){
      f.setLayout(new FlowLayout());
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.add(lblGpa);
      f.setSize(300,350);
      f.setVisible(true);
      }

 private int getAccIncrease(String mark) {
        if (mark.equalsIgnoreCase("A")) {return 4;}
        else if (mark.equalsIgnoreCase("B")) {return 3;}
        else if (mark.equalsIgnoreCase("C")) {return 2;}
        else if (mark.equalsIgnoreCase("D")) {return 1;}
        return 0;        
    }

public static void main(String args[]){
      LabelFrame1 If=new LabelFrame1();
      }
}
firstly you will have a problem with
     try{
         int StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
     } catch(NumberFormatException NFE){}

since you are doing it twice but at the moment it does not moan about it since you also have a scope issue there and the StudentScore variable will not be available to you outside of the try....catch block. So firstly move the decleration of the variable outside of the try catch like this

     int StudentScore
     try{
         StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
     } catch(NumberFormatException NFE){}

and delete the second occurance thereof

Then to solve your display issue you have been asking about you could use a grid layout and it should fix most of your problems.
If you're facing too many display problems, better to use a null layout instead of a grid-layout and use the setBounds () method of all Components to set the size and positions. Some more on layout managers here:

http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

I think you're GPA computation is already resolved.
Problem with a null loayout manager is that if someone resizes the screen smaller than what you have taken into account for you sit with a problem. Also you would have to impliment a WindowListener and within its callbacks replace all of the components.
I just want to set my output screen look nicely, any suggestion with shortest way ?????
As I have said before.
> Then to solve your display issue you have been asking about
> you could use a grid layout and it should fix most of
> your problems.

Change
f.setLayout(new FlowLayout());
to
f.setLayout(new GridLayout(9,2,5,5));

The defenition of the GridLayout constructor is
java.awt.GridLayout()
java.awt.GridLayout(int rows, int cols)
java.awt.GridLayout(int rows, int cols, int hgap, int vgap)

I used the one with the rows cols hgap and vgap so that the components aren't ontop of each other.
>> Problem with a null loayout manager is that if someone resizes the screen smaller than what you have taken into account

Yes, 'coz the components are fixed. You can either choose to disable resizing of the frame (bad approach in case the screen-resolution changes across different systems) or use a better layout-manager. Its a short and dirty solution if you're ready to accept that the window-size will not change.

>> any suggestion with shortest way ?????

Yes, visit the link I posted. It'll tell you about all layout managers.
I set it as:

f.setLayout(new GridLayout(12,2,5,5));

but the word "GPA" still leave behind the button...... I want to make it in a new line........ how to make it ???
Just chagne the following:
     f.add(B1);
     B1.addActionListener(this);
     f.add(lblGpa);
to
     f.add(B1);
     B1.addActionListener(this);
     f.add(new JPanel());
     f.add(lblGpa);


and change
     f.setLayout(new GridLayout(12,2,5,5));
to
     f.setLayout(new GridLayout(13,2,5,5));
I just add :

Label lblStudentId = new Label ( "Student Id: " ) ;
lblStudentId.setText ( "Student Id: " + (int)StudentId  ) ;
f.add(lblStudentId);

I want to show the StudentId automatic but it shows 1 error at here:

lblStudentId.setText ( "Student Id: " + (int)StudentId  ) ;
>> but it shows 1 error at here:

It would be more helpful if you could state what the error-message is.

>> "Student Id: " + (int)StudentId  

I thought StudentId was already an 'int'? Did you try:

"Student Id: " + StudentId

Best is:

StringBuffer sbTemp = new StringBuffer ( "Student Id: " ) ;
sbTemp.append ( StudentId ) ;
lblStudentId.setText ( sbTemp.toString () ) ;
Yes..... I tried that before it shows cannot resolve symbol error.........now I try your suggestion but it also having the same error(2 errors).......which are:

i)  sbTemp.append ( StudentId ) ;
ii) lblStudentId.setText ( sbTemp.toString () ) ;


public void actionPerformed(ActionEvent evt) {
      try{
       int StudentId = Integer.parseInt ( IdField.getText ().trim () ) ;
      } catch(NumberFormatException NFE){}

      String StudentName = NameField.getText();

        int accumulativeMark = 0;
        accumulativeMark += getAccIncrease(CS211Field.getText());
        accumulativeMark += getAccIncrease(CS212Field.getText());
        accumulativeMark += getAccIncrease(CS213Field.getText());
        accumulativeMark += getAccIncrease(CS214Field.getText());
        accumulativeMark += getAccIncrease(CS215Field.getText());
      
      try{
       int StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
      } catch(NumberFormatException NFE){}
      
      float GPA=(float)accumulativeMark/5;
      lblStudentId.setText ( sbTemp.toString () ) ;
      lblGpa.setText ( "GPA: " + (float)GPA  ) ;
}

public LabelFrame1(){
      f.setLayout(new GridLayout(13,2,5,5));
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.add(new Panel());
      f.add(lblGpa);
      sbTemp.append ( StudentId ) ;
      f.setSize(320,350);
      f.setVisible(true);
      }

 private int getAccIncrease(String mark) {
        if (mark.equalsIgnoreCase("A")) {return 4;}
        else if (mark.equalsIgnoreCase("B")) {return 3;}
        else if (mark.equalsIgnoreCase("C")) {return 2;}
        else if (mark.equalsIgnoreCase("D")) {return 1;}
        return 0;        
    }

public static void main(String args[]){
      LabelFrame1 If=new LabelFrame1();
      }
}

 
import java.awt.*;
import java.awt.event.*;
public class LabelFrame1 implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("Submit/Calculate");
      Label lblGpa = new Label ( "GPA: " ) ;
      StringBuffer sbTemp = new StringBuffer ( "Student Id: " ) ;


public void actionPerformed(ActionEvent evt) {
      try{
       int StudentId = Integer.parseInt ( IdField.getText ().trim () ) ;
      } catch(NumberFormatException NFE){}

      String StudentName = NameField.getText();

        int accumulativeMark = 0;
        accumulativeMark += getAccIncrease(CS211Field.getText());
        accumulativeMark += getAccIncrease(CS212Field.getText());
        accumulativeMark += getAccIncrease(CS213Field.getText());
        accumulativeMark += getAccIncrease(CS214Field.getText());
        accumulativeMark += getAccIncrease(CS215Field.getText());
      
      try{
       int StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
      } catch(NumberFormatException NFE){}
      
      float GPA=(float)accumulativeMark/5;
      lblStudentId.setText ( sbTemp.toString () ) ;
      lblGpa.setText ( "GPA: " + (float)GPA  ) ;
}

public LabelFrame1(){
      f.setLayout(new GridLayout(13,2,5,5));
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.add(new Panel());
      f.add(lblGpa);
      sbTemp.append ( StudentId ) ;
      f.setSize(320,350);
      f.setVisible(true);
      }

 private int getAccIncrease(String mark) {
        if (mark.equalsIgnoreCase("A")) {return 4;}
        else if (mark.equalsIgnoreCase("B")) {return 3;}
        else if (mark.equalsIgnoreCase("C")) {return 2;}
        else if (mark.equalsIgnoreCase("D")) {return 1;}
        return 0;        
    }

public static void main(String args[]){
      LabelFrame1 If=new LabelFrame1();
      }
}
oh my god........ both of them are having their holidays on Saturday & Sunday............ any person can help me ???
>> cannot resolve symbol error

That means that the variable has not been declared. Make sure the scope of the variable is fine.

>> holidays on Saturday & Sunday

Diwali festival in India (the biggest festival here) and moreover the cricket match between India and Pakistan ;-)

>> int StudentId = Integer.parseInt ( IdField.getText ().trim () ) ;

This is inside the try block. Declare it outside.

int StudentId = 0 ;

try
{
  int StudentId = Integer.parseInt ( IdField.getText ().trim () ) ;

}

catch ( .... )
....
ooo............ You stay in India ........ Is it India is your home town ????? Or you are from other countries ?????
Now i'm having problem when the professor enter Student Id 9999-9999-9999........ the output screen only show Student Id: 0 .............. Is that means we need to store in a String  ??????
>> 9999-9999-9999.

If the Student-ID is like that, then you cannot parse it into an 'int' or a 'long'. You'll need to store it as a String, which is still ok because you don't need to perform any mathematical computations on it.

>> Is it India is your home town ????? Or you are from other countries ?????

See the profiles :)
ooo...... you like to play chess...... me too........ what is the chess website you always went to ???? I always went to www.miniclip.com and log in as jasonck........(if I'm free)
import java.awt.*;
import java.awt.event.*;
public class LabelFrame1 implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("Submit/Calculate");
      Label lblStudentId = new Label ( "Student Id: " ) ;
      Label lblStudentName = new Label ( "Student Name: " ) ;
      Label lblCS211 = new Label ( "CS211: " ) ;
      Label lblCS212 = new Label ( "CS212: " ) ;
      Label lblCS213 = new Label ( "CS213: " ) ;
      Label lblCS214 = new Label ( "CS214: " ) ;
      Label lblCS215 = new Label ( "CS215: " ) ;
      Label lblGpa = new Label ( "GPA:         and Admission test score:          " ) ;

public void actionPerformed(ActionEvent evt) {

      String StudentId = IdField.getText () ;
      String StudentName = NameField.getText();

        int accumulativeMark = 0;
        accumulativeMark += getAccIncrease(CS211Field.getText());
        accumulativeMark += getAccIncrease(CS212Field.getText());
        accumulativeMark += getAccIncrease(CS213Field.getText());
        accumulativeMark += getAccIncrease(CS214Field.getText());
        accumulativeMark += getAccIncrease(CS215Field.getText());
      
      int StudentScore =0;
      try{
       StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
      } catch(NumberFormatException NFE){}
      
      float GPA=(float)accumulativeMark/5;
      lblStudentId.setText ( "Student Id: " + StudentId  ) ;
      lblStudentName.setText ( "Student Name: " + StudentName  ) ;
      lblCS211.setText ( "CS211: " + CS211Field.getText()  ) ;
      lblCS212.setText ( "CS212: " + CS212Field.getText()  ) ;
      lblCS213.setText ( "CS213: " + CS213Field.getText()  ) ;
      lblCS214.setText ( "CS214: " + CS214Field.getText()  ) ;
      lblCS215.setText ( "CS215: " + CS215Field.getText()  ) ;
      lblGpa.setText ( "GPA: " + GPA + "  and Admission test score:  " + StudentScore) ;

}
public LabelFrame1(){
      f.setLayout(new GridLayout(20,2,5,5));
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.add(new Panel());
      f.add(lblStudentId);
      f.add(new Panel());
      f.add(lblStudentName);
      f.add(new Panel());
      f.add(lblCS211);
      f.add(new Panel());
      f.add(lblCS212);
      f.add(new Panel());
      f.add(lblCS213);
      f.add(new Panel());
      f.add(lblCS214);
      f.add(new Panel());
      f.add(lblCS215);
      f.add(new Panel());
      f.add(lblGpa);
      f.setSize(465,550);
      f.setVisible(true);
      }

private int getAccIncrease(String mark) {
        if (mark.equalsIgnoreCase("A")) {return 4;}
        else if (mark.equalsIgnoreCase("B")) {return 3;}
        else if (mark.equalsIgnoreCase("C")) {return 2;}
        else if (mark.equalsIgnoreCase("D")) {return 1;}
        return 0;        
    }

public static void main(String args[]){
      LabelFrame1 If=new LabelFrame1();
      }
}

Every things is almost ok......... now need to start with the class Admission ...... I know need to use coding if...else but how to start ????
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the question want :

Create variables that store the grade point average and an admission test score. Print the message "Accept" if the students has any of the following:

1) A grade point average of 3.6 or above and an admission test score of at least 60.
2) A grade point average of 3.0 or above and an admission test score of at least 70.
3) A grade point average of 2.6 or above and an admission test score of at least 80.
4) A grade point average of 2.0 or above and an admission test score of at least 90.

If the student does not meet any of the qualification, print "Reject". This class name is Admission.

Is that mean we need to create a class Admission to calculate the Admission either "Accept" or "Reject" ???
I'm stuck ..............
Hi me back... You would need a series of if statements to handle that one properly.

something like

  boolean accept = false;
  if ((admission >= 90) && (average >= 2.0)) {
    accept = true;
  }
  else if ((admission >= 80) && (average >= 2.6)) {
    accept = true;
  }
  .
  .//for the other 2
  .
  .
  .
  if (accept) {
    //show the message that the student has been accepted
  }
import java.awt.*;
import java.awt.event.*;
public class LabelFrame1 extends admission implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("Submit/Calculate");
      Label lblStudentId = new Label ( "Student Id: " ) ;
      Label lblStudentName = new Label ( "Student Name: " ) ;
      Label lblCS211 = new Label ( "CS211: " ) ;
      Label lblCS212 = new Label ( "CS212: " ) ;
      Label lblCS213 = new Label ( "CS213: " ) ;
      Label lblCS214 = new Label ( "CS214: " ) ;
      Label lblCS215 = new Label ( "CS215: " ) ;
      Label lblGpa = new Label ( "GPA:         and Admission test score:          " ) ;
      Label lblAdmission = new Label ( "Admission: " ) ;

public void actionPerformed(ActionEvent evt) {

      String StudentId = IdField.getText () ;
      String StudentName = NameField.getText();

        int accumulativeMark = 0;
        accumulativeMark += getAccIncrease(CS211Field.getText());
        accumulativeMark += getAccIncrease(CS212Field.getText());
        accumulativeMark += getAccIncrease(CS213Field.getText());
        accumulativeMark += getAccIncrease(CS214Field.getText());
        accumulativeMark += getAccIncrease(CS215Field.getText());
      
      int StudentScore =0;
      try{
       StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
      } catch(NumberFormatException NFE){}
      
      float GPA=(float)accumulativeMark/5;
      lblStudentId.setText ( "Student Id: " + StudentId  ) ;
      lblStudentName.setText ( "Student Name: " + StudentName  ) ;
      lblCS211.setText ( "CS211: " + CS211Field.getText()  ) ;
      lblCS212.setText ( "CS212: " + CS212Field.getText()  ) ;
      lblCS213.setText ( "CS213: " + CS213Field.getText()  ) ;
      lblCS214.setText ( "CS214: " + CS214Field.getText()  ) ;
      lblCS215.setText ( "CS215: " + CS215Field.getText()  ) ;
      lblGpa.setText ( "GPA: " + GPA + "  and Admission test score:  " + StudentScore) ;
      lblAdmission.setText ( "Admission: " + admission.getText() ) ;

}
public LabelFrame1(){
      f.setLayout(new GridLayout(20,2,5,5));
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.add(new Panel());
      f.add(lblStudentId);
      f.add(new Panel());
      f.add(lblStudentName);
      f.add(new Panel());
      f.add(lblCS211);
      f.add(new Panel());
      f.add(lblCS212);
      f.add(new Panel());
      f.add(lblCS213);
      f.add(new Panel());
      f.add(lblCS214);
      f.add(new Panel());
      f.add(lblCS215);
      f.add(new Panel());
      f.add(lblGpa);
      f.add(new Panel());
      f.add(lblAdmission);
      f.setSize(465,550);
      f.setVisible(true);
      }

private int getAccIncrease(String mark) {
        if (mark.equalsIgnoreCase("A")) {return 4;}
        else if (mark.equalsIgnoreCase("B")) {return 3;}
        else if (mark.equalsIgnoreCase("C")) {return 2;}
        else if (mark.equalsIgnoreCase("D")) {return 1;}
        return 0;        
    }

public static void main(String args[]){
      LabelFrame1 If=new LabelFrame1();
      }
}

public class admission{
  boolean accept = false;
  if ((admission >= 90) && (average >= 2.0)) {
    accept = true;
  }
  else if ((admission >= 80) && (average >= 2.6)) {
    accept = true;
  }
  else if ((admission >= 70) && (average >= 3.0)) {
    accept = true;
  }
  else if ((admission >= 60) && (average >= 3.6)) {
    accept = true;
  }
  if (accept) {
    admission="Accept";
  }
  else
    admission="Reject";      
}

But it show 2 errors in here....... illegal start of type if...else
& identifier expected......
ok now take your code out of a class and place it in a method like

private void admission() {
  boolean accept = false;
  if ((admission >= 90) && (average >= 2.0)) {
    accept = true;
  }
  else if ((admission >= 80) && (average >= 2.6)) {
    accept = true;
  }
  else if ((admission >= 70) && (average >= 3.0)) {
    accept = true;
  }
  else if ((admission >= 60) && (average >= 3.6)) {
    accept = true;
  }
  if (accept) {
    lblAdmission.setText("Admission: Accept");
  }
  else
    lblAdmission.setText("Admission: Reject");
}

Then call the method from your actionPerformed method.
Can I change like this ????? But still having cannot resolve symbol error........... & how to call it ?????

import java.awt.*;
import java.awt.event.*;
public class LabelFrame1 implements ActionListener{
      Frame f=new Frame("Output Screen");
      Panel p=new Panel();
      Label Id=new Label("Enter student id: ",Label.LEFT);
      TextField IdField=new TextField(15);
      Label Name=new Label("Enter student name: ",Label.LEFT);
      TextField NameField=new TextField(30);
      Label CS211=new Label("Enter grade for CS211: ",Label.LEFT);
      TextField CS211Field=new TextField(1);
      Label CS212=new Label("Enter grade for CS212: ",Label.LEFT);
      TextField CS212Field=new TextField(1);
      Label CS213=new Label("Enter grade for CS213: ",Label.LEFT);
      TextField CS213Field=new TextField(1);
      Label CS214=new Label("Enter grade for CS214: ",Label.LEFT);
      TextField CS214Field=new TextField(1);
      Label CS215=new Label("Enter grade for CS215: ",Label.LEFT);
      TextField CS215Field=new TextField(1);
      Label Score=new Label("Enter admission test score: ",Label.LEFT);
      TextField ScoreField=new TextField(1);
      Button B1 = new Button("Submit/Calculate");
      Label lblStudentId = new Label ( "Student Id: " ) ;
      Label lblStudentName = new Label ( "Student Name: " ) ;
      Label lblCS211 = new Label ( "CS211: " ) ;
      Label lblCS212 = new Label ( "CS212: " ) ;
      Label lblCS213 = new Label ( "CS213: " ) ;
      Label lblCS214 = new Label ( "CS214: " ) ;
      Label lblCS215 = new Label ( "CS215: " ) ;
      Label lblGpa = new Label ( "GPA:         and Admission test score:          " ) ;
      Label lblAdmission = new Label ( "Admission: " ) ;

public void actionPerformed(ActionEvent evt) {

      String StudentId = IdField.getText () ;
      String StudentName = NameField.getText();

        int accumulativeMark = 0;
        accumulativeMark += getAccIncrease(CS211Field.getText());
        accumulativeMark += getAccIncrease(CS212Field.getText());
        accumulativeMark += getAccIncrease(CS213Field.getText());
        accumulativeMark += getAccIncrease(CS214Field.getText());
        accumulativeMark += getAccIncrease(CS215Field.getText());
      
      int StudentScore =0;
      try{
       StudentScore =Integer.parseInt ( ScoreField.getText ().trim() ) ;
      } catch(NumberFormatException NFE){}
      
      float GPA=(float)accumulativeMark/5;
      lblStudentId.setText ( "Student Id: " + StudentId  ) ;
      lblStudentName.setText ( "Student Name: " + StudentName  ) ;
      lblCS211.setText ( "CS211: " + CS211Field.getText()  ) ;
      lblCS212.setText ( "CS212: " + CS212Field.getText()  ) ;
      lblCS213.setText ( "CS213: " + CS213Field.getText()  ) ;
      lblCS214.setText ( "CS214: " + CS214Field.getText()  ) ;
      lblCS215.setText ( "CS215: " + CS215Field.getText()  ) ;
      lblGpa.setText ( "GPA: " + GPA + "  and Admission test score:  " + StudentScore) ;
      lblAdmission.setText ( "Admission: " + admission() ) ;

}
public LabelFrame1(){
      f.setLayout(new GridLayout(20,2,5,5));
      f.add(Id);
      f.add(IdField);
      f.add(Name);
      f.add(NameField);
      f.add(CS211);
      f.add(CS211Field);
      f.add(CS212);
      f.add(CS212Field);
      f.add(CS213);
      f.add(CS213Field);
      f.add(CS214);
      f.add(CS214Field);
      f.add(CS215);
      f.add(CS215Field);
      f.add(Score);
      f.add(ScoreField);
      f.add(B1);
      B1.addActionListener(this);
      f.add(new Panel());
      f.add(lblStudentId);
      f.add(new Panel());
      f.add(lblStudentName);
      f.add(new Panel());
      f.add(lblCS211);
      f.add(new Panel());
      f.add(lblCS212);
      f.add(new Panel());
      f.add(lblCS213);
      f.add(new Panel());
      f.add(lblCS214);
      f.add(new Panel());
      f.add(lblCS215);
      f.add(new Panel());
      f.add(lblGpa);
      f.add(new Panel());
      f.add(lblAdmission);
      f.setSize(465,550);
      f.setVisible(true);
      }

private int getAccIncrease(String mark) {
        if (mark.equalsIgnoreCase("A")) {return 4;}
        else if (mark.equalsIgnoreCase("B")) {return 3;}
        else if (mark.equalsIgnoreCase("C")) {return 2;}
        else if (mark.equalsIgnoreCase("D")) {return 1;}
        return 0;        
    }

private void admission() {
  boolean accept = false;
  if ((StudentScore >= 90) && (GPA >= 2.0)) {
    accept = true;
  }
  else if ((StudentScore >= 80) && (GPA >= 2.6)) {
    accept = true;
  }
  else if ((StudentScore >= 70) && (GPA >= 3.0)) {
    accept = true;
  }
  else if ((StudentScore >= 60) && (GPA >= 3.6)) {
    accept = true;
  }
  if (accept) {
    lblAdmission.setText("Admission: Accept");
  }
  else
    lblAdmission.setText("Admission: Reject");
}

public static void main(String args[]){
      LabelFrame1 If=new LabelFrame1();
      }
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for you guys............ oh, yeah....... any suggestion of the website that like EE even the website not good enough as in EE ?????
Thanks.... Hope it helps you in the future.
Well........... never mind ........... Good luck to you guys ......