Create a program that takes in a student first name and average mark obtained, the system should the group the students using the first vowel in their name. For example if the student name is Jena, then the student belongs to group E and if the name was Jack then the student belongs to group A[HINT: Make use of the indexOf() and contains() methods from the string class]. The program should further categorize the mark is follows:
Marks obtained
Grade Level
Message
80 – 100
1
Magnificent!!
70 – 79
2
Excellent!!
60 – 69
3
Good work!!
50 – 59
4
Good!!
0 – 49
Fail – Try again next Year!!
Greater than 100 or
less than 0
X
Invalid Marks!!, Marks too high. Or Invalid Marks!!, Negative marks not allowed.
Sample run 1:
Enter student full names: Johnathan
Enter average mark obtained: 88
Output: Hi Johnathan, you were placed in group O
Grade Level: 1
Comment: Magnificent!!
import java.lang.*;
import java.util.Scanner;
public class Main
{
public static boolean vowel(char y){
if (y == 'a' || y == 'e' || y == 'i' || y == 'o' || y == 'u')
return true;
else
return false;
}
public static void main(String[] args) {
System.out.println("Enter student full names: ");
Scanner scan = new Scanner(System.in);
String name = scan.nextLine();
System.out.println("Enter average mark obtained: ");
int marks = scan.nextInt();
int size = name.length();
char arr[] = new char[size];
char group ='a';
for(int i=0; i<size; i++){
arr[i] = name.charAt(i);
if(vowel(Character.toLowerCase(arr[i]))){
group =Character.toUpperCase(arr[i]);
break;
}
}
if(marks>=80 && marks<100){
System.out.printf("Hi %s, you were placed in group %c\n", name, group);
System.out.println("Grade Level: 1\nComment: Magnificent!! ");
}
else if(marks>=70 && marks<=79){
System.out.printf("Hi %s, you were placed in group %c\n", name, group);
System.out.println("Grade Level: 2\nComment: Excellent!! ");
}
else if(marks>=60 && marks<=69){
System.out.printf("Hi %s, you were placed in group %c\n", name, group);
System.out.println("Grade Level: 3\nComment: Good Work!! ");
}
else if(marks>=50 && marks<=59){
System.out.printf("Hi %s, you were placed in group %c\n", name, group);
System.out.println("Grade Level: 4\nComment: Good!! ");
}
else if(marks>=0 && marks<=49){
System.out.printf("Hi %s, you were placed in group %c\n", name, group);
System.out.println("Grade Level: 5\nComment: Fail – Try again next Year!! ");
}
else{
System.out.println("Invalid Marks!!, Marks too high. Or Invalid Marks!!, Negative marks not allowed.");
}
}
}
Comments
Leave a comment