just started programing with java, did microsoft visual basic last semester, but java seems more case sensitive, how can i write a program called CheckPassFail, which prints "pass" if the int variable "mark" is more than or equal to 50; or prints "fail" otherwise.please help

Recommended Answers

All 16 Replies

this is about eight lines of code, and that includes lines with only a bracket. what have you got so far?

Code is not provided just like that to you. If you show that you have made SOME effort by yourself, we will help you further.

public final String CheckPassFail(final int mark) {
    return (mark >= 50) ? "pass" : "fail";
}

thanatos: don't provide code, the point is to help them write it themselves.

if you've not written that, you've not programmed it so you've not started to program in Java, have you?
Do your own homework, don't expect to ever learn anything just sitting back and hoping that others will do it all for you.

commented: Most people at in my semestre need this advice. +2

i didnt ask 4 codes, ya'll misinterpreted my question. i was asking 4 guidelines,thanx IIM,i went through oracle n was able to write the program. N ofcourse i didnt expect to get my homework done via the net just like that, cos some things provided may be wrong. just that our lecturer is somewhat very based on learner centered, doesnt explain much n expects us to learn everyting from scratch on our own, like we are pros at this when we actualy just started.

..you can try to visit basic java tutorials...or you you simply study..my simple code..

import javax.swing.JOptionPane;

public class NewGProblem {

    public static void main(String[] args) {


       //my sinple code
        int mark = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter value for variable mark ?"));
        if (mark >= 50) {
            JOptionPane.showMessageDialog(null, "pass");
        } else {
            JOptionPane.showMessageDialog(null, "pass");
        }




    }
}

you can
try my simple code...so that you can get some idea on how to make your own code ..

commented: He's studying if-else and you give him GUI code. Wow. -_- +0

mtangpos16: first of all, don't provide code. when you do provide code, provide code that makes actual sense. what you wrote above is exactly the same as:

import javax.swing.JOptionPane;
public class NewGProblem {
    public static void main(String[] args) {
       //my sinple code
        int mark = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter value for variable mark ?"));
            JOptionPane.showMessageDialog(null, "pass");
    }
}

only less efficiënt

he actually did better than you, but can do even better.
The best thing to do with homework kiddos is to give them code that's utterly incomprehensible to them (and likely their teachers) and does something completely different from what they want to achieve, but seems to do just about what they want, so they spend a lot of time banging their head on it trying to get it to work (or better yet, turn it in as is and get a failing grade for it).

JWenting ... in what way is having both the if- and else block performing the exact same task "better" then dropping the if and else and running that task without checking?

read... It's much better as it punishes the homework kiddo for his laziness.

import javax.swing.JOptionPane;

public class CheckPassFail {

    public static void main(String[] args) {

        int mark = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter value for variable mark: "));
        if (mark >= 50) {
            JOptionPane.showMessageDialog(null, "PASS");
        } else {
            JOptionPane.showMessageDialog(null, "FAIL");
        }
    }
}

jgesapine: try not to spoon-feed them code. the point is to help them improve their skills, not to do their homework for them.

jgesapine: try not to spoon-feed them code. the point is to help them improve their skills, not to do their homework for them.

That unfortunately is something a lot of people don't understand... you don't just simply give everything away, you assist them to an extent where they can do this on their own... I mean, just like the old saying goes, "You fish the man a fish, he has dinner for a night. You teach him how to fish, he has food for life"... (probably not the best saying)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.