Create a program that takes in a student first name, the system should the group the students using the first letter in their name modulus 10 [ Remember that characters are considered as numeric values, hence ‘J’%10 is a valid calculation ]. For example if the student name is Cena, then the student belongs to group 7 because ‘C’%10 = 7 and if the name was Jack then the student belongs to group 4. The program should further use the group number to get the group lecturer and class date as follows: [Hint: If the result is 0 then the student belongs to group 10]
Groups
Group Lecturer
Class date
1 , 7, 9
Mr. V. Paduri
Monday
2 , 4, 5
Ms. N. Nashandi
Wednesday
3, 6, 10
Mr. S. Tjiraso
Friday
SOLUTION CODE FOR THE ABOVE PROGRAM
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter student first name: ");
String first_name = sc.next();
//Get the first character of the first name of the student first name
char first_name_first_character = first_name.charAt(0);
//Calculate the group of the student by performing the modulus
int my_modulus = (first_name_first_character % 10);
int student_group;
//if the result for modulus is 0 set group to 10
if(my_modulus==0)
{
student_group = 10;
}
else
{
student_group = my_modulus;
}
//Print the group in which the student was placed in
System.out.println(first_name+", you belong to group "+student_group+".");
//Now find the lecture and class date for the group in which the student belongs
if (student_group == 1 || student_group == 7 || student_group == 9) {
System.out.println("Your group Lecturer will be: Mr. V. Paduri");
System.out.println("Group " + student_group + " classes are on Mondays");
}
else if (student_group == 2 || student_group == 4 || student_group == 5) {
System.out.println("Your group Lecturer will be: Ms. N. Nashandi");
System.out.println("Group " + student_group + " classes are on Wednesdays");
}
else if (student_group == 3 || student_group == 6 || student_group == 10) {
System.out.println("Your group Lecturer will be: Mr. S. Tjiraso");
System.out.println("Group " + student_group + " classes are on Fridays");
}
//this is the case if a student belongs to group 8
else
{
System.out.println("Group lecturer and class date for group "
+student_group+" not assigned");
}
}
}
SAMPLE PROGRAM OUTPUTS
Comments
Leave a comment