Kevin Blakely
asked on
Simple Java Methods question (Edited)
Hello
I'm new to coding (total novice) and i am having trouble with the following program. (see below and question attached)
How do I print out my assignGrade method??? I had to initialise it in Main manually. The rest of the program works fine?
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
package Lab8;
import java.util.Scanner;
public class ClassTest2Retry {
static Scanner input = new Scanner(System.in);
//method enterName()
public static String enterName(){
System.out.println("Enter name");
return input.nextLine();
}
//method enterMark()
public static int enterMark(String value){
System.out.println(value);
return input.nextInt();
}
//method calculateAverage()
public static int calculateaverage(int solo, int prose, int poem){
return ((solo + prose + poem) /3);
}
// method assignGrade
public static String assignGrade(int overall){
if (overall <40){
return "Fail";
}else if (overall >40) {
return "Pass";
}
else{
return "Distinction";
}
}
//method output results
public static void outputResults (String name, int solo, int prose, int poem, int average, String grade){
System.out.println("Name\t \t\t\t Solo\t\t\t\t Prose\t\t\t\t Poem\t\t\t\t Avg\t\t\t\t Grade");
System.out.println(name + "\t\t" + solo+ "\t\t\t\t\t"+ prose+"\t\t\t\t\t" + poem + "\t\t\t\t\t"+ average);
}
public static void main(String[] args) {
String nameMain, gradeMain;
int soloMarkMain, proseMarkMain, poemMarkMain, averageMain, overallMain = 70;
nameMain = enterName();
soloMarkMain = enterMark("Enter Solo Mark");
proseMarkMain = enterMark("Enter Prose Mark");
poemMarkMain = enterMark("Enter Poem Mark");
averageMain = calculateaverage(soloMarkM ain, proseMarkMain,poemMarkMain );
gradeMain = assignGrade(overallMain);
outputResults(nameMain, soloMarkMain, proseMarkMain, poemMarkMain, averageMain, gradeMain);
}//end main
}//end class
Class-Test-2-SpeechDrama.docx
I'm new to coding (total novice) and i am having trouble with the following program. (see below and question attached)
How do I print out my assignGrade method??? I had to initialise it in Main manually. The rest of the program works fine?
--------------------------
package Lab8;
import java.util.Scanner;
public class ClassTest2Retry {
static Scanner input = new Scanner(System.in);
//method enterName()
public static String enterName(){
System.out.println("Enter name");
return input.nextLine();
}
//method enterMark()
public static int enterMark(String value){
System.out.println(value);
return input.nextInt();
}
//method calculateAverage()
public static int calculateaverage(int solo, int prose, int poem){
return ((solo + prose + poem) /3);
}
// method assignGrade
public static String assignGrade(int overall){
if (overall <40){
return "Fail";
}else if (overall >40) {
return "Pass";
}
else{
return "Distinction";
}
}
//method output results
public static void outputResults (String name, int solo, int prose, int poem, int average, String grade){
System.out.println("Name\t
System.out.println(name + "\t\t" + solo+ "\t\t\t\t\t"+ prose+"\t\t\t\t\t" + poem + "\t\t\t\t\t"+ average);
}
public static void main(String[] args) {
String nameMain, gradeMain;
int soloMarkMain, proseMarkMain, poemMarkMain, averageMain, overallMain = 70;
nameMain = enterName();
soloMarkMain = enterMark("Enter Solo Mark");
proseMarkMain = enterMark("Enter Prose Mark");
poemMarkMain = enterMark("Enter Poem Mark");
averageMain = calculateaverage(soloMarkM
gradeMain = assignGrade(overallMain);
outputResults(nameMain, soloMarkMain, proseMarkMain, poemMarkMain, averageMain, gradeMain);
}//end main
}//end class
Class-Test-2-SpeechDrama.docx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.