Welcome to the Java Programming Forums


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


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


>> REGISTER NOW TO START POSTING


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

Results 1 to 4 of 4

Thread: Need help with my code T.T newbie

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with my code T.T newbie

    Hi everyone!

    If anyone knows how to solve this, please help me... I'm currently a newbie in java.

    I want to add a remarks to the student grade, i want the remarks to display in the Jtextfield that i added.. thank you

    1.0 98-100 Outstanding
    1.25 95-97 Very Satisfactory
    1.5 92-94 Very Satisfactory
    1.75 89-91 Satisfactory
    2.0 86-88 Satisfactory
    2.25 83-85 Satisfactory
    2.5 80-82 Satisfactory
    2.75 77-79 Passing
    3.0 75-76 Passing
    below 3.0 <=74 failed








    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class StudentPerformance extends JFrame
    {
    private static final int width = 400;
    private static final int height = 300;

    private JLabel studentnameL, courseL, yearL, quizgradeL, attendancegradeL, projectgradeL, examgradeL, finalgradeL, equivalentgradeL, remarksL;

    private JTextField studentnameTF, courseTF, yearTF, quizgradeTF, attendancegradeTF, projectgradeTF, examgradeTF, finalgradeTF, equivalentgradeTF, remarksTF;

    private JButton ExitB, CalculateB;

    private CalculateButtonHandler cbHandler;
    private ExitButtonHandler ebHandler;

    public StudentPerformance()
    {

    setTitle("StudentPerformance");

    studentnameL = new JLabel("Enter Student Name", SwingConstants.LEFT);

    courseL = new JLabel("Enter Student Course", SwingConstants.LEFT);

    yearL = new JLabel("Enter Student Year", SwingConstants.LEFT);

    quizgradeL = new JLabel("Enter Quiz Grade", SwingConstants.LEFT);

    attendancegradeL = new JLabel("Enter Attendance Grade", SwingConstants.LEFT);

    projectgradeL = new JLabel("Enter Project Grade", SwingConstants.LEFT);

    examgradeL = new JLabel("Enter Exam Grade", SwingConstants.LEFT);

    finalgradeL = new JLabel("Final Grade is", SwingConstants.LEFT);

    equivalentgradeL = new JLabel("Equivalent grade is", SwingConstants.LEFT);

    remarksL = new JLabel("remarks is", SwingConstants.LEFT);

    studentnameTF = new JTextField(10);
    courseTF = new JTextField(10);
    yearTF = new JTextField(10);
    quizgradeTF = new JTextField(10);
    attendancegradeTF= new JTextField(10);
    projectgradeTF = new JTextField(10);
    examgradeTF = new JTextField(10);
    finalgradeTF = new JTextField(10);
    finalgradeTF.setEditable(false);
    equivalentgradeTF = new JTextField(10);
    remarksTF = new JTextField(10);



    CalculateB = new JButton("CALCULATE");
    cbHandler = new CalculateButtonHandler();
    CalculateB.addActionListener(cbHandler);

    ExitB = new JButton("Exit");
    ebHandler = new ExitButtonHandler();
    ExitB.addActionListener(ebHandler);

    Container pane = getContentPane();
    pane.setLayout(new GridLayout(15, 2));

    pane.add(studentnameL);
    pane.add(studentnameTF);
    pane.add(courseL);
    pane.add(courseTF);
    pane.add(yearL);
    pane.add(yearTF);
    pane.add(quizgradeL);
    pane.add(quizgradeTF);
    pane.add(attendancegradeL);
    pane.add(attendancegradeTF);
    pane.add(projectgradeL);
    pane.add(projectgradeTF);
    pane.add(examgradeL);
    pane.add(examgradeTF);
    pane.add(finalgradeL);
    pane.add(finalgradeTF);
    pane.add(equivalentgradeL);
    pane.add(equivalentgradeTF);
    pane.add(remarksL);
    pane.add(remarksTF);
    pane.add(CalculateB);
    pane.add(ExitB);

    setSize(width, height);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private class CalculateButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    String studentname, course, remarks;
    double quizgrade, attendancegrade, projectgrade, examgrade, finalgrade, equivalentgrade;

    quizgrade = Double.parseDouble(quizgradeTF.getText());
    attendancegrade = Double.parseDouble(attendancegradeTF.getText());
    projectgrade = Double.parseDouble(projectgradeTF.getText());
    examgrade = Double.parseDouble(examgradeTF.getText());


    quizgrade = quizgrade * .10;
    attendancegrade = attendancegrade* .10;
    projectgrade = projectgrade * .30;
    examgrade = examgrade * .60;
    finalgrade = (quizgrade + attendancegrade + projectgrade + examgrade) / 4;
    finalgradeTF.setText("" + finalgrade);
    equivalentgrade = Double.parseDouble(equivalentgradeTF.getText());


    if (finalgrade >= 98)
    equivalentgrade = 1.0;
    else if (finalgrade >= 95)
    equivalentgrade = 1.25;
    else if (finalgrade >= 92)
    equivalentgrade = 1.5;
    else if (finalgrade >= 89)
    equivalentgrade = 1.75;
    else if (finalgrade >= 86)
    equivalentgrade = 2.0;
    else if (finalgrade >= 83)
    equivalentgrade = 2.25;
    else if (finalgrade >= 80)
    equivalentgrade = 2.5;
    else if (finalgrade >= 77)
    equivalentgrade = 2.75;
    else if (finalgrade >= 75)
    equivalentgrade = 3.0;

    finalgradeTF.setText("" + finalgrade);




    }
    }

    private class ExitButtonHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    System.exit(0);
    }
    }
    public static void main(String[] args)
    {
    StudentPerformance rect = new StudentPerformance();
    }
    }


  2. #2
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Need help with my code T.T newbie

    Hello.
    You can compute remarks field value simultaneously while computing equivalent grade.

    Syed.

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with my code T.T newbie

    clarify it please, what codes do i need to add? thank you.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,312
    My Mood
    Mellow
    Thanks
    194
    Thanked 669 Times in 656 Posts

    Default Re: Need help with my code T.T newbie

    Please post your code in code tags.

    a partial, untried example:
    String comment = null;
    if (finalgrade >= 98)
    {
        equivalentgrade = 1.0;
        comment = "Outstanding";
    }
     
    // . . . . . the rest, then:
     
    finalgradeTF.setText("" + finalgrade);
    remarksTF.setText( comment );

Similar Threads

  1. How to print each letter of string in reverse order in separate line?
    By Razzle in forum Loops & Control Statements
    Replies: 3
    Last Post: October 31st, 2012, 05:32 PM
  2. Re: Java Newbie Code Problem
    By maxruas in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 26th, 2012, 04:36 AM
  3. Newbie Question on a Code - I don't know if this is Java
    By fresca in forum Java Theory & Questions
    Replies: 4
    Last Post: April 7th, 2011, 08:39 PM
  4. Re: Java Newbie Code Problem
    By erinbasim in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 01:05 AM
  5. [SOLVED] Java Newbie Code Problem
    By lee in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 16th, 2010, 02:05 PM