Solved

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

Posted on 2004-11-10
Medium Priority
297 Views
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

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

Can use the GUI screen which contains all the buttons, textfields and any other relevant components.
0
Question by:watermelonhahaha778
• 32
• 18
• 15
• +1

LVL 37

Expert Comment

ID: 12542450
We're not allowed to write code for you.
0

LVL 30

Expert Comment

ID: 12542712
>> 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.
0

LVL 3

Expert Comment

ID: 12543568
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.
0

Author Comment

ID: 12544509
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());
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?
0

LVL 3

Expert Comment

ID: 12544574
Ok so you have a start but nothing regarding the marks and such.....

You will need something dynamic like a table or such.
0

Author Comment

ID: 12544856
But how to do that? I can't run it because having error.
0

Author Comment

ID: 12550509
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());
setSize(300,300);
setVisible(true);
}
public static void main(String args[]){
LabelFrame If=new LabelFrame();
}
}
0

Author Comment

ID: 12551451
I will check for every one hour to look for the response.
0

Author Comment

ID: 12551879
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.setSize(300,300);
f.setVisible(true);
}
public static void main(String args[]){
LabelFrame If=new LabelFrame();
}
}

I am stuck at here ..........
0

LVL 30

Expert Comment

ID: 12552111
>> 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.

0

LVL 3

Expert Comment

ID: 12552405
>> 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
0

Author Comment

ID: 12552533
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.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..........
0

LVL 3

Expert Comment

ID: 12552595
Yeah well you kinda have to add
import the java.awt.event.*;
at the top. Then after
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.
0

Author Comment

ID: 12552715
but now it shows 1 error in here.

switch (CS214Field.getText().toUpperCase()) {
0

LVL 3

Expert Comment

ID: 12552729
What is the error???
0

Author Comment

ID: 12552844
imcompatible types
0

Author Comment

ID: 12553014
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.setSize(300,350);
f.setVisible(true);
}
public static void main(String args[]){
LabelFrame If=new LabelFrame();
}
}

you can try and run it............
0

LVL 3

Expert Comment

ID: 12553258
I think I will do that quickly and check it out. brb
0

LVL 3

Expert Comment

ID: 12553326
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
0

LVL 30

Expert Comment

ID: 12553805
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 ) ) {
0

LVL 3

Expert Comment

ID: 12553880
Or check out my prevoius post which is a much more robust way that does not replicate code.
0

Author Comment

ID: 12554084
.toUpperCase ().charAt ( 0 )

What is the use of toUpperCase( ) and charAt(0) ????
0

LVL 3

Expert Comment

ID: 12554108
toUpperCase() converts the string to an upper case representation of itself and charAt(0) returns the first character in that string.
0

Author Comment

ID: 12554404
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.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 ????
0

LVL 30

Expert Comment

ID: 12554573
String sStudentId = IdField.getText () ;
0

LVL 30

Expert Comment

ID: 12554582
Also better to trim () all Strings when you get them from the text-field.
0

Author Comment

ID: 12555379
I need to bed. Have a sweet dream you guys ......
0

LVL 30

Expert Comment

ID: 12555913
Did that getText () work?
0

Author Comment

ID: 12562472

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 ???
0

LVL 30

Expert Comment

ID: 12562562
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.
0

Author Comment

ID: 12562640
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);
}
0

LVL 30

Expert Comment

ID: 12562839
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

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

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

lblGpa.setText ( lblGpa.getText () + GPA ) ;
0

LVL 30

Expert Comment

ID: 12562846

If you want to stick with your current approach, use: f.add ( lblGpa ) ;
0

Author Comment

ID: 12563024
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.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.............
0

LVL 3

Expert Comment

ID: 12563351
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.
0

Author Comment

ID: 12563745
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.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();
}
}
0

LVL 3

Expert Comment

ID: 12563972
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.
0

LVL 30

Expert Comment

ID: 12564016
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.
0

LVL 3

Expert Comment

ID: 12564140
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.
0

Author Comment

ID: 12564293
I just want to set my output screen look nicely, any suggestion with shortest way ?????
0

LVL 3

Expert Comment

ID: 12564855
As I have said before.
> you could use a grid layout and it should fix most of

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.
0

LVL 30

Expert Comment

ID: 12564960
>> 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.
0

Author Comment

ID: 12565212
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 ???
0

LVL 3

Expert Comment

ID: 12565252
Just chagne the following:
to

and change
f.setLayout(new GridLayout(12,2,5,5));
to
f.setLayout(new GridLayout(13,2,5,5));
0

Author Comment

ID: 12565491

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

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

lblStudentId.setText ( "Student Id: " + (int)StudentId  ) ;
0

LVL 30

Expert Comment

ID: 12566823
>> 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 () ) ;
0

Author Comment

ID: 12571977
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));
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();
}
}

0

Author Comment

ID: 12571982
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));
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();
}
}
0

Author Comment

ID: 12574033
oh my god........ both of them are having their holidays on Saturday & Sunday............ any person can help me ???
0

LVL 30

Expert Comment

ID: 12574151
>> 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 ( .... )
....
0

Author Comment

ID: 12577008
ooo............ You stay in India ........ Is it India is your home town ????? Or you are from other countries ?????
0

Author Comment

ID: 12577086
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  ??????
0

LVL 30

Expert Comment

ID: 12577147
>> 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 :)
0

Author Comment

ID: 12577239
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)
0

Author Comment

ID: 12577252
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.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 ????
0

LVL 30

Accepted Solution

Mayank S earned 500 total points
ID: 12577275
>> what is the chess website you always went to

WorldChessNetwork.com

What is that class supposed to do?
0

Author Comment

ID: 12577456
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" ???
0

Author Comment

ID: 12580782
I'm stuck ..............
0

LVL 3

Expert Comment

ID: 12581374
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
}
0

Author Comment

ID: 12581645
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:          " ) ;

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.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();
}
}

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) {
}
else
}

But it show 2 errors in here....... illegal start of type if...else
& identifier expected......
0

LVL 3

Expert Comment

ID: 12581709
ok now take your code out of a class and place it in a method like

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) {
}
else
}

Then call the method from your actionPerformed method.
0

Author Comment

ID: 12582573
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:          " ) ;

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.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;
}

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) {
}
else
}

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

LVL 3

Assisted Solution

ID: 12582634
Ok then do something like:

private String admission(int StudentScore, float GPA) {
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) {
return "Accept";
}
else
return "Reject";
}

and where you call the method simply pass it the StudentScore and GPA values.
0

Author Comment

ID: 12583232
Thanks for you guys............ oh, yeah....... any suggestion of the website that like EE even the website not good enough as in EE ?????
0

LVL 3

Expert Comment

ID: 12583343
Thanks.... Hope it helps you in the future.
0

Author Comment

ID: 12592786
Well........... never mind ........... Good luck to you guys ......
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a clâ€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationâ€¦
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompaâ€¦
###### Suggested Courses
Course of the Month14 days, 17 hours left to enroll