• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java program Grade  RSS feed

 
Fatfat Tika
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create a program that accepts grade in prelim,midterm,semi and finals
then compute the overall grade by getting the 20% of prelim, midterm, semi then 40% of finals then displays the rating
grade rating
97-100 1.00
94-98 1.25
91-93 1.5
88-90 1.75
85-87 2.00
82-84 2.25
80-81 2.5
76-79 2.75
75 3.0
70-74 5.0

is there anyone who can help me here?
I really need it
I'm just new in programming java.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please DoYourOwnHomework, ShowSomeEffort.
If you are new to Java, we would suggest you learn the syntax and try out few programs.
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai brother if you are new in java..so try to learn java and solve this question itself...this is the good way of lerning otherwise you lose programming skills.
 
Fatfat Tika
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should I use If then?
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why not...practice more & more...this is the best way of learning.
 
Fatfat Tika
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey!, what should I do in computing the grades using IF THEN? I'm experiencing errors
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
char ch;

if(percent>60)
ch='A';
else if(percent>45)
ch='B';
else if(percent>35)
ch='C';
else
ch='F';

you want this solution.
what you want to say...say clear..
 
Fatfat Tika
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.swing.*;
class CaseGrade{
public static void main(String args[]){

int prelim= Integer.parseInt(JOptionPane.showInputDialog("prelim"));
int midterm= Integer.parseInt(JOptionPane.showInputDialog("midterm"));
int semi= Integer.parseInt(JOptionPane.showInputDialog("semi"));
int finals= Integer.parseInt(JOptionPane.showInputDialog("finals"));

that's the first part, what should I do next? uhmm! what do you think?
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is two way--

first you add all integers part perform operation on it like
[deleted]

char ch;

if [deleted]
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and the other way is to find out percent seperately...this is depend on your requirement.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Come on, people. That is hardly a way to welcome a newcomer

Welcome to JavaRanch

You will have to work out how to add marks with the 20% and 40% formula. Do that on paper, before you try writing any code. The write down, again with paper and pencil something like this:
  • If he gets less than -97% call it a grade 97½
  • Otherwise: If he gets less than -102% call it a grade 99
  • Otherwise, if he gets less than -55% call it a grade 52½
  • Take a pencil and follow the flow of execution through those options for marks like -44%, -99% and -150%. That should allow you to get the if bits in the right order.

    Only after you have done that should you even think or writing any code. And don't just say you "get errors"; that is totally useless for getting any help. You must tell us what errors you are suffering.
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thakur Sachin Singh wrote:char ch;

    if(percent>60)
    ch='A';
    else if(percent>45)
    ch='B';
    else if(percent>35)
    ch='C';
    else
    ch='F';

    you want this solution.
    what you want to say...say clear..
    No, no, no. Don't go giving a solution like that. That doesn't help at all. Look at Beginning Java, where you read
    We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
    Unfortunately I didn't see your response in time to stop you doing any harm. You are depriving other people of the chance to learn by giving a simple answer like that.
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    uhmm! I don't know how to do/combine the percentage,grade and rating.
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have already told you, work out the percentage first.
    Again, don't try any code until you see on paper what you want.
     
    Thakur Sachin Singh
    Ranch Hand
    Posts: 248
    Hibernate Java Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ok campbell...next time i follow these things..thanks for telling me.
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yes I already did it before, but I'm having a hard time doing it in JAVA.
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And what did you write on paper?
     
    Mohamed Sanaulla
    Bartender
    Posts: 3185
    34
    Google App Engine Java Ruby
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And you need not directly jump to a Application with GUI. Start out with taking input from console and the make the core of your code- which does the percentage calculation and grade assignment work. You can take the same code and use it for input from GUI.
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    prelim,midterm,semi * .20 finals *.40
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That is too basic. You have to read each number, multiply as appropriate, and add them. I suggest you divide by 5 when you have the total.
    You are going to have to write a lot more.
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    are you sure I should divide it by 5 not 4?
     
    Mohamed Sanaulla
    Bartender
    Posts: 3185
    34
    Google App Engine Java Ruby
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Fatfat Tika wrote:are you sure I should divide it by 5 not 4?


    I think It should be 4.
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    5
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
  • Mark 1
  • Add Mark 2
  • Add Mark 3
  • Add 2 × Mark 4
  • Divide total by 5
  •  
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    this actually my assignment
    my sample output should be
    prelim:90
    midterm:93
    semi:80
    finals:85
    overall:88.2
    rating:

    but I can't solve the overall..
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That adds up to 86.6, not 88.2
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    tnx what should I do next?
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Fatfat Tika wrote: . . . but I can't solve the overall..
    Don't even try to solve the whole exercise. Get it to print the overall average mark, and forget about the grades.

    Add the grades later, once you have the averages working.
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Fatfat Tika wrote:tnx what should I do next?
    Show us how you are working out the average, on paper, and then show us (in a subsequent post) what it looks like in Java™.

    You already seem to have the reading from the keyboard working.
    Have you been told to use JOptionPane, rather than Scanner; JOptionPane is considered very old-fashioned coding now?
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    prelim:90
    midterm:93
    semi:80
    finals:85

    90*.20=18
    93*.20=18.6
    80*.20=16
    85*.40=34
    _________
    86.6

    I'm not sure what to write in Java
    but I'm thinking of If & Then...
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You can't do it quite like that if using ints. Add or multiply first, and divide (by 5 ) later. That technique will work nicely if you are using doubles, however.
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    90+93+80*.20=52.6
    85*.40=34
    _________
    86.6

    like this??
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Fatfat Tika wrote:prelim:90
    midterm:93
    semi:80
    finals:85

    90*.20=18
    93*.20=18.6
    80*.20=16
    85*.40=34
    _________
    86.6
    That will give the correct answer, but all those values will be doubles. Probably easiest at this stage to use that formula, remembering to declare your average as a double.
    I'm not sure what to write in Java
    but I'm thinking of If & Then...
    Forget about if and then until you have the averages working. One little bit at a time.
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Fatfat Tika wrote:90+93+80*.20=52.6
    85*.40=34
    _________
    86.6

    like this??


    but (90 + 93 + 80) × 0.20 + 85 × 0.40 would be better still, I think. Remember the (). Remember that returns its result as a double.
    (90 + 93 + 80 + 2 * 85) ÷ 5.0 will give the same result, 86.6.

    Remember the () are necessary. Remember × and ÷ are not used in the actual code.
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I earlier wrote:. . . (90 + 93 + 80 + 2 * 85) ÷ 5.0 . . .
    (90 + 93 + 80 + 2 * 85) ÷ 5, however is an int, and will give the result 86. That is still correct under the rules of integer arithmetic.
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    how about the ratings?
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Show us the Java™ for calculating the overall grade, then worry about the 1 1¼, etc. later.
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    double overall=(prelim+midterm+semi+2*finals)/5.0;
     
    Campbell Ritchie
    Marshal
    Posts: 56529
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Looks good. Improve your style by changing it to thisThen you can see it working. You can remove the print instruction later. The only change is that I have added spaces, which improve readability.

    I have got to go now, but you have an application which will run and print the overall mark. Half of it done
     
    Fatfat Tika
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    aww! thanks, I learn a lot thank you for the time and effort
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!