Page 1 of 4 123 ... LastLast
Results 1 to 20 of 64
  1. #1
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default Class Calculator Help

    Im making a simple calculator in java and i have two things that i am stuck on but can't quite figure out the math part of it. I have to : Create an input for Attendance 25% of your overall grade - (1.2 points each day) and also create an input box for Labs 25% of your overall grade. - 1.4 points each Lab total of 18 Labs. The other 50% i already figured out which was entering in 4 test grades and it works fine. Any help would be much appreciated. Thanks
    Last edited by Ryan10; 03-01-2011 at 07:06 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I see partial program requirements posted above but no actual specific question. So in that vein, what is your specific question? Also, you're far better off using a thread title here that has some bearing on your problem. All new threads here are questions, and I see nothing "quick" about yours. If it were mine, I'd change it to "How to implement class calculator" or something along those lines.

  3. #3
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Color.*;
    
    public class task2 extends Applet implements ActionListener{
    
    
    
    	Double num1, num2, num3, num4, num5, answer, answer2, total, total2, average;
    	char grade;
    
    		Label titleLabel = new Label("Enter your grades for each of your assignments below: \n");
    		Label number1Label = new Label ("Enter First Task Grade: \n");
    			TextField number1Field = new TextField (3);
    		Label number2Label = new Label ("Enter Second Task Grade: \n");
    			TextField number2Field = new TextField (3);
    		Label number3Label = new Label ("\nEnter Third Task Grade: \n");
    			TextField number3Field = new TextField (3);
    		Label number4Label = new Label ("\nEnter Forth Task Grade: \n");
    			TextField number4Field = new TextField (3);
    		Label number5Label = new Label ("\nHow many Days did you miss: \n");
    			TextField number5Field = new TextField (3);
    		Button goButton = new Button("GO \n");
    		Label outputLabel = new Label ("\nYour Grade.      \n");
    		Label outputLabel2 = new Label ("\nNumber Grade is   \n");
    		Label outputLabel3 = new Label ("\nParticipation   \n");
    		Label outputLabel4 = new Label ("\nAverage      \n");
    
    
    
    		public void init() {
    			setForeground(Color.blue);
    			add(titleLabel);
    			add(number1Label);
    			add(number1Field);
    			add(number2Label);
    			add(number2Field);
    			add(number3Label);
    			add(number3Field);
    			add(number4Label);
    			add(number4Field);
    			add(number5Label);
    			add(number5Field);
    			add(goButton);
    			goButton.addActionListener(this);
    			add(outputLabel);
    			add(outputLabel2);
    			add(outputLabel3);
    			add(outputLabel4);
    	}
    
    	public void actionPerformed(ActionEvent e){
    
    	num1 = Double.parseDouble(number1Field.getText());
    	num2 = Double.parseDouble(number2Field.getText());
    	num3 = Double.parseDouble(number3Field.getText());
    	num4 = Double.parseDouble(number4Field.getText());
    	num5 = Double.parseDouble(number5Field.getText());
    
    	answer= num1 + num2 + num3 + num4;
    	total= answer /4 * 1/2;
    
    	answer2= num5 * 12/10;
    	total2= answer * 1/4;
    
    
    	average = total +total2;
    
    
    	outputLabel.setText("total" + Math.round(total));
    
    
    
    
    		if (total >= 90) {
    			grade = 'A';
    		} else if (total >= 80) {
    			grade = 'B';
    		} else if (total >= 70) {
    			grade = 'C';
    		} else if (total >= 60) {
    			grade = 'D';
    		} else {
    			grade = 'F';
    		}
    		outputLabel.setText("Grade:\n"   + grade);
    		outputLabel2.setText("Numeric Grade \n"  + total);
    		outputLabel3.setText ("Participation: \n" + total2);
    		outputLabel4.setText ("Final Grade \n" + average);
    
    
    	}
    
    }

    I have the 50% grade part all figured out now i just have to figure out the assignment and lab part out. The math part i put in my first post. The math part is what i need help on. Thanks
    Last edited by Ryan10; 03-01-2011 at 07:04 PM.

  4. #4
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    can anyone here help me out with this?

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    I agree with Fubarable that "Really Quick question" is a very poor title for this thread. Names are important, and choosing good names is a skill you should try to acquire early. Your class should not be called task2. I wouldn't complain about Task2 (notice the capital letter), but something like GradeCalculator is better. Your other variables have similarly vague names.

    You should use arrays rather than discrete variables for things that are similar, such as your TextFields, your test scores, and your lab scores. I don't see anything in your program yet to keep track of the 18 labs that are supposed to be worth 1.4 points each. It's not clear whether the labs are to be graded or simply full points awarded for each lab completed. I can guess that attendance is 21 days (18 * 1.4 = 21 * 1.2). That means that labs and attendance together can earn a total of 50.4 points, which is supposed to represent 50% of the grade, which implies that the other 50%, average test score, is also worth 50.4 points.

    Anyway, it seems like the math is essentially this:
    Java Code:
            finalGrade = 50.4 * (testAverage/100) + 1.2 * (21 - daysMissed) + 1.4 * labsCompleted; //  or maybe 1.4 * (totalLabScore / 1800) assuming each lab is scored 0-100
    Don't take my word for it though. It's not me getting graded on this.

    -Gary-

  6. #6
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    Quote Originally Posted by gcalvin View Post
    I agree with Fubarable that "Really Quick question" is a very poor title for this thread. Names are important, and choosing good names is a skill you should try to acquire early. Your class should not be called task2. I wouldn't complain about Task2 (notice the capital letter), but something like GradeCalculator is better. Your other variables have similarly vague names.
    Came here to say this. And really, average = total + total2? No wonder the OP is confused.

    Quote Originally Posted by gcalvin View Post
    You should use arrays rather than discrete variables for things that are similar, such as your TextFields, your test scores, and your lab scores.
    I don't see how that would gain him anything.

    Quote Originally Posted by gcalvin View Post
    I don't see anything in your program yet to keep track of the 18 labs that are supposed to be worth 1.4 points each. It's not clear whether the labs are to be graded or simply full points awarded for each lab completed. I can guess that attendance is 21 days (18 * 1.4 = 21 * 1.2). That means that labs and attendance together can earn a total of 50.4 points, which is supposed to represent 50% of the grade, which implies that the other 50%, average test score, is also worth 50.4 points.

    Anyway, it seems like the math is essentially this:
    Java Code:
            finalGrade = 50.4 * (testAverage/100) + 1.2 * (21 - daysMissed) + 1.4 * labsCompleted; //  or maybe 1.4 * (totalLabScore / 1800) assuming each lab is scored 0-100
    This.

  7. #7
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    so your saying daysMissed and labsCompleted should be set as integers aswell as testAverage

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Ryan10 View Post
    so your saying daysMissed and labsCompleted should be set as integers aswell as testAverage
    I didn't say anything like that. That's your call. Is it possible to miss part of a day (and be so credited)? Is it possible to complete a fraction of a lab?

    -Gary-

  9. #9
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    Here's an example that someone else did and we can use it as a guide maybe it will give you a clearer picture of what im trying to do.

    http://plourde.smccme.edu/GPAapplet.html

  10. #10
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    Quote Originally Posted by Ryan10 View Post
    Here's an example that someone else did and we can use it as a guide maybe it will give you a clearer picture of what im trying to do.

    http://plourde.smccme.edu/GPAapplet.html
    I'm pretty sure you know exactly what you're trying to do. The question is, do you?

  11. #11
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Ryan10 View Post
    Here's an example that someone else did and we can use it as a guide maybe it will give you a clearer picture of what im trying to do.

    http://plourde.smccme.edu/GPAapplet.html
    That does clarify that (at least in the other developer's judgment) labs need only be completed, and not scored. Did you have another question?

    -Gary-

  12. #12
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    I still havent figured out what the math part is for those two examples..i know the other 50% if we start changing things around i have to change the integers because thats how i set it up.

  13. #13
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Ryan10 View Post
    I still havent figured out what the math part is for those two examples..i know the other 50% if we start changing things around i have to change the integers because thats how i set it up.
    Did you?
    Java Code:
    	Double num1, num2, num3, num4, num5, answer, answer2, total, total2, average;
    I don't see any ints or Integers here. (Mind you, I don't know why you chose Double instead of double.)

    -Gary-

  14. #14
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    I changed that..didn't really know it made a difference. Instead of making it all one string for the final grade i was trying to do them separate then add all of them up at the end to get the final grade. Do you know what i mean. Lets take it one by one if i were to do the math for the attendance/participation grade how would i go about doing so?
    Last edited by Ryan10; 03-01-2011 at 09:36 PM.

  15. #15
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Ryan10 View Post
    I changed that..didn't really know it made a difference.
    Yes, Double and double are quite different. Double is an Object, and double is a primitive. You'll want to study up on that.
    Quote Originally Posted by Ryan10 View Post
    Instead of making it all one string for the final grade i was trying to do them separate then add all of them up at the end to get the final grade. Do you know what i mean.
    Then do that. I don't mind. I was illustrating the math involved, not writing your code for you.

    -Gary-

  16. #16
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Ryan10 View Post
    Lets take it one by one if i were to do the math for the attendance/participation grade how would i go about doing so?
    You haven't told us what "attendance/participation" is. I see
    Create an input for Attendance 25% of your overall grade - (1.2 points each day)
    You should be able to pull that part out of the math I already gave you.

    -Gary-

  17. #17
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    Thats why im asking for help on here because what math am i supposed to use for attendance if its 1.2 points each day missed and 25% of my overall grade? I know that the 1.2 has to deduct of the grade i just need a push in the right direction. Remember im a noob at this stuff sorry.

  18. #18
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Ryan10 View Post
    Thats why im asking for help on here because what math am i supposed to use for attendance if its 1.2 points each day missed and 25% of my overall grade? I know that the 1.2 has to deduct of the grade i just need a push in the right direction. Remember im a noob at this stuff sorry.
    I don't read it as 1.2 points each day missed, but 1.2 points each day attended.

    Look at it this way: there are 18 Labs, right? Each one is worth 1.4 points, right? That means if you complete all 18, you get 25.2 points, right? And Labs are worth 25% of your grade, right?

    Attendance is also worth 25%, same as labs, right? That means Attendance must also be worth 25.2 points, just as Labs are. 25.2 divided by 1.2 points per day means 21 total days, right?

    So 25.2 points for Labs and 25.2 points for Attendance makes 50.4 points. And that's 50% of your grade, right? So test scores must also be 50.4 points.

    So you'll compute a score for attendance (max 25.2) a score for labs (max 25.2) and a score for test average (max 50.4), and then add them all together (max 100.8), right?

    Tell me if you understand that much, and then go from there.

    -Gary-

  19. #19
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    so 1.2* (21-daysMissed meaning what the user types in) the thing i don't understand is what are we supposed to put for days missed. Is it just a variable and yes i see how you get the math its correct. This is what i have so far daysMissed= 1.2*(21-num5) ... finalDays= daysMissed * 1/4 (meaning for 25%) so if i type in 0 days missed i should get 25 points. I get 6.3 for an answer clearly something is wrong.
    Last edited by Ryan10; 03-01-2011 at 10:00 PM.

  20. #20
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Ryan10 View Post
    so 1.2* (21-daysMissed meaning what the user types in) the thing i don't understand is what are we supposed to put for days missed. Is it just a variable and yes i see how you get the math its correct.
    Of course it's a variable. You seem to have it as num5, but as you can see, that's not a very helpful name, as you've already lost track of what it's supposed to be.

    -Gary-

Page 1 of 4 123 ... LastLast

Similar Threads

  1. Quick question
    By Thumper in forum New To Java
    Replies: 10
    Last Post: 11-07-2010, 11:06 PM
  2. Quick Question...
    By FatalSylence in forum New To Java
    Replies: 4
    Last Post: 10-15-2010, 03:38 PM
  3. quick question
    By vouslavous in forum Java Applets
    Replies: 4
    Last Post: 04-24-2009, 09:35 PM
  4. One last quick question
    By jigglywiggly in forum New To Java
    Replies: 7
    Last Post: 01-26-2009, 09:53 AM
  5. Quick Question
    By Graeme in forum New To Java
    Replies: 4
    Last Post: 01-08-2009, 09:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •