using an if statement to determine whether a number is greater than one then directing output to a separate...
I'm writing a program for a grading System. I have got the program practically finished bar one thing. I have to determine the mark in one method and then print the mark and grade awarded using a separate method but how do i get the output from the if statements into the method to print the grade.
here is my code:
/*
Author:
Title: Odds and Evens
Date created: 13/11/18
Version :1.0
*/
import java.util.Scanner;
public class GradeClassifier
{
public static void main (Stringargs)
{
displayTitle();
int mark = getMark();
determineGrade(mark);
}
public static void displayTitle ()// prints title
{
System.out.println ("Grade Classifier");
System.out.println ("****************");
}
public static int getMark()// getting the mark from user
{
Scanner in = new Scanner (System.in);
System.out.print ("Enter a mark :> ");
return in.nextInt();
}
public static int determineGrade(int n1)
{
Scanner in = new Scanner (System.in);
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
in.nextInt();
}
if (n1 < 100 && n1 > 70)
System.out.print("Grade A");
if (n1 < 69 && n1 > 60)
System.out.print("Grade B");
if (n1 < 59 && n1 > 50)
System.out.println("Grade C");
if (n1 < 49 && n1 > 40)
System.out.println("Grade D");
if (n1 < 40)
System.out.println ("Grade F - Fail");
return n1;
}
}
below the last method, I have that is where I need the printResult method
any help is appreciated
thanks.
Also, I do know that using the print statements below the if statements prints out the grade but this is not how I want the program structured
java
add a comment |
I'm writing a program for a grading System. I have got the program practically finished bar one thing. I have to determine the mark in one method and then print the mark and grade awarded using a separate method but how do i get the output from the if statements into the method to print the grade.
here is my code:
/*
Author:
Title: Odds and Evens
Date created: 13/11/18
Version :1.0
*/
import java.util.Scanner;
public class GradeClassifier
{
public static void main (Stringargs)
{
displayTitle();
int mark = getMark();
determineGrade(mark);
}
public static void displayTitle ()// prints title
{
System.out.println ("Grade Classifier");
System.out.println ("****************");
}
public static int getMark()// getting the mark from user
{
Scanner in = new Scanner (System.in);
System.out.print ("Enter a mark :> ");
return in.nextInt();
}
public static int determineGrade(int n1)
{
Scanner in = new Scanner (System.in);
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
in.nextInt();
}
if (n1 < 100 && n1 > 70)
System.out.print("Grade A");
if (n1 < 69 && n1 > 60)
System.out.print("Grade B");
if (n1 < 59 && n1 > 50)
System.out.println("Grade C");
if (n1 < 49 && n1 > 40)
System.out.println("Grade D");
if (n1 < 40)
System.out.println ("Grade F - Fail");
return n1;
}
}
below the last method, I have that is where I need the printResult method
any help is appreciated
thanks.
Also, I do know that using the print statements below the if statements prints out the grade but this is not how I want the program structured
java
4
Side note, the marks of 40, 50, 60, and 70 have no grade attached. Might want to use>=
in theif
statements.
– AntonH
Nov 21 '18 at 17:14
You should also consider the case for 100 along with 40,50,60 and 70
– suvojit_007
Nov 21 '18 at 17:22
add a comment |
I'm writing a program for a grading System. I have got the program practically finished bar one thing. I have to determine the mark in one method and then print the mark and grade awarded using a separate method but how do i get the output from the if statements into the method to print the grade.
here is my code:
/*
Author:
Title: Odds and Evens
Date created: 13/11/18
Version :1.0
*/
import java.util.Scanner;
public class GradeClassifier
{
public static void main (Stringargs)
{
displayTitle();
int mark = getMark();
determineGrade(mark);
}
public static void displayTitle ()// prints title
{
System.out.println ("Grade Classifier");
System.out.println ("****************");
}
public static int getMark()// getting the mark from user
{
Scanner in = new Scanner (System.in);
System.out.print ("Enter a mark :> ");
return in.nextInt();
}
public static int determineGrade(int n1)
{
Scanner in = new Scanner (System.in);
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
in.nextInt();
}
if (n1 < 100 && n1 > 70)
System.out.print("Grade A");
if (n1 < 69 && n1 > 60)
System.out.print("Grade B");
if (n1 < 59 && n1 > 50)
System.out.println("Grade C");
if (n1 < 49 && n1 > 40)
System.out.println("Grade D");
if (n1 < 40)
System.out.println ("Grade F - Fail");
return n1;
}
}
below the last method, I have that is where I need the printResult method
any help is appreciated
thanks.
Also, I do know that using the print statements below the if statements prints out the grade but this is not how I want the program structured
java
I'm writing a program for a grading System. I have got the program practically finished bar one thing. I have to determine the mark in one method and then print the mark and grade awarded using a separate method but how do i get the output from the if statements into the method to print the grade.
here is my code:
/*
Author:
Title: Odds and Evens
Date created: 13/11/18
Version :1.0
*/
import java.util.Scanner;
public class GradeClassifier
{
public static void main (Stringargs)
{
displayTitle();
int mark = getMark();
determineGrade(mark);
}
public static void displayTitle ()// prints title
{
System.out.println ("Grade Classifier");
System.out.println ("****************");
}
public static int getMark()// getting the mark from user
{
Scanner in = new Scanner (System.in);
System.out.print ("Enter a mark :> ");
return in.nextInt();
}
public static int determineGrade(int n1)
{
Scanner in = new Scanner (System.in);
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
in.nextInt();
}
if (n1 < 100 && n1 > 70)
System.out.print("Grade A");
if (n1 < 69 && n1 > 60)
System.out.print("Grade B");
if (n1 < 59 && n1 > 50)
System.out.println("Grade C");
if (n1 < 49 && n1 > 40)
System.out.println("Grade D");
if (n1 < 40)
System.out.println ("Grade F - Fail");
return n1;
}
}
below the last method, I have that is where I need the printResult method
any help is appreciated
thanks.
Also, I do know that using the print statements below the if statements prints out the grade but this is not how I want the program structured
java
java
edited Nov 21 '18 at 17:14


suvojit_007
1,3241517
1,3241517
asked Nov 21 '18 at 17:07
kian5749kian5749
84
84
4
Side note, the marks of 40, 50, 60, and 70 have no grade attached. Might want to use>=
in theif
statements.
– AntonH
Nov 21 '18 at 17:14
You should also consider the case for 100 along with 40,50,60 and 70
– suvojit_007
Nov 21 '18 at 17:22
add a comment |
4
Side note, the marks of 40, 50, 60, and 70 have no grade attached. Might want to use>=
in theif
statements.
– AntonH
Nov 21 '18 at 17:14
You should also consider the case for 100 along with 40,50,60 and 70
– suvojit_007
Nov 21 '18 at 17:22
4
4
Side note, the marks of 40, 50, 60, and 70 have no grade attached. Might want to use
>=
in the if
statements.– AntonH
Nov 21 '18 at 17:14
Side note, the marks of 40, 50, 60, and 70 have no grade attached. Might want to use
>=
in the if
statements.– AntonH
Nov 21 '18 at 17:14
You should also consider the case for 100 along with 40,50,60 and 70
– suvojit_007
Nov 21 '18 at 17:22
You should also consider the case for 100 along with 40,50,60 and 70
– suvojit_007
Nov 21 '18 at 17:22
add a comment |
2 Answers
2
active
oldest
votes
Right now you're just returning the input parameter.
This modified code will return a String, which contains the grade:
public static String determineGrade(int n1)
{
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
Scanner in = new Scanner (System.in);
int newInput = in.nextInt();
determineGrade(newInput);
}
if (n1 <= 100 && n1 >= 70)
return "Grade A";
if (n1 < 69 && n1 >= 60)
return "Grade B";
if (n1 < 59 && n1 >= 50)
return "Grade C";
if (n1 < 49 && n1 >= 40)
return "Grade D";
if (n1 < 40)
return "Grade F - Fail";
return "";
}
You could also use System.out.println(determineGrade(input));
to directly print the grade.
add a comment |
You could set the grade string as the value of a class property, then you can have a method that simply prints whatever value is in the class property at the time it's called
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417242%2fusing-an-if-statement-to-determine-whether-a-number-is-greater-than-one-then-dir%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Right now you're just returning the input parameter.
This modified code will return a String, which contains the grade:
public static String determineGrade(int n1)
{
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
Scanner in = new Scanner (System.in);
int newInput = in.nextInt();
determineGrade(newInput);
}
if (n1 <= 100 && n1 >= 70)
return "Grade A";
if (n1 < 69 && n1 >= 60)
return "Grade B";
if (n1 < 59 && n1 >= 50)
return "Grade C";
if (n1 < 49 && n1 >= 40)
return "Grade D";
if (n1 < 40)
return "Grade F - Fail";
return "";
}
You could also use System.out.println(determineGrade(input));
to directly print the grade.
add a comment |
Right now you're just returning the input parameter.
This modified code will return a String, which contains the grade:
public static String determineGrade(int n1)
{
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
Scanner in = new Scanner (System.in);
int newInput = in.nextInt();
determineGrade(newInput);
}
if (n1 <= 100 && n1 >= 70)
return "Grade A";
if (n1 < 69 && n1 >= 60)
return "Grade B";
if (n1 < 59 && n1 >= 50)
return "Grade C";
if (n1 < 49 && n1 >= 40)
return "Grade D";
if (n1 < 40)
return "Grade F - Fail";
return "";
}
You could also use System.out.println(determineGrade(input));
to directly print the grade.
add a comment |
Right now you're just returning the input parameter.
This modified code will return a String, which contains the grade:
public static String determineGrade(int n1)
{
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
Scanner in = new Scanner (System.in);
int newInput = in.nextInt();
determineGrade(newInput);
}
if (n1 <= 100 && n1 >= 70)
return "Grade A";
if (n1 < 69 && n1 >= 60)
return "Grade B";
if (n1 < 59 && n1 >= 50)
return "Grade C";
if (n1 < 49 && n1 >= 40)
return "Grade D";
if (n1 < 40)
return "Grade F - Fail";
return "";
}
You could also use System.out.println(determineGrade(input));
to directly print the grade.
Right now you're just returning the input parameter.
This modified code will return a String, which contains the grade:
public static String determineGrade(int n1)
{
if (n1 > 100){
System.out.println ("INVALID MARK PLEASE TRY AGAIN");
Scanner in = new Scanner (System.in);
int newInput = in.nextInt();
determineGrade(newInput);
}
if (n1 <= 100 && n1 >= 70)
return "Grade A";
if (n1 < 69 && n1 >= 60)
return "Grade B";
if (n1 < 59 && n1 >= 50)
return "Grade C";
if (n1 < 49 && n1 >= 40)
return "Grade D";
if (n1 < 40)
return "Grade F - Fail";
return "";
}
You could also use System.out.println(determineGrade(input));
to directly print the grade.
edited Nov 21 '18 at 17:30
answered Nov 21 '18 at 17:14
dnsivdnsiv
322116
322116
add a comment |
add a comment |
You could set the grade string as the value of a class property, then you can have a method that simply prints whatever value is in the class property at the time it's called
add a comment |
You could set the grade string as the value of a class property, then you can have a method that simply prints whatever value is in the class property at the time it's called
add a comment |
You could set the grade string as the value of a class property, then you can have a method that simply prints whatever value is in the class property at the time it's called
You could set the grade string as the value of a class property, then you can have a method that simply prints whatever value is in the class property at the time it's called
answered Nov 21 '18 at 17:18
JmJJmJ
4951633
4951633
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417242%2fusing-an-if-statement-to-determine-whether-a-number-is-greater-than-one-then-dir%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Side note, the marks of 40, 50, 60, and 70 have no grade attached. Might want to use
>=
in theif
statements.– AntonH
Nov 21 '18 at 17:14
You should also consider the case for 100 along with 40,50,60 and 70
– suvojit_007
Nov 21 '18 at 17:22