CS1401 – Programming Assignment 4 Lab 4! Activity 2. In this activity, you will
ID: 3671893 • Letter: C
Question
CS1401 – Programming Assignment 4
Lab 4!
Activity 2. In this activity, you will focus on conditionals. You have to implement a solution to the following problem:
You have to design and implement an information system for professors and students (giving more information to professors than to students in general, but also more information to the student who designed the code than to any other student). This system is bilingual and users need to pick a language of choice to interact with your system.
Below is a description of the types of access that your system needs to enforce and the type of experiences that need to be delivered to each type of user:
Access Control and Experience Table.
Professor
Student
Student Designer
How to legally access the system?
Someone who properly enters the correct access code for professors (=codeProf) and has picked the English language
Someone who properly enters the correct access code for students (=codeAnyStudent), regardless of chosen language
Someone who properly enters the correct access code for student designer (=codeStudentDesigner) and has not picked English as a language
What is printed?
Asked (in the requested language) if he/she wants to know the name of the Student Designer (if so, the name should be printed as requested);
Then asked if he/she wants to know the GPA of the Student Designer (if so, the GPACalculator of Activity 1 should be invoked and its result printed);
Told (in the requested language) about CS1401 and your instructor.
Asked (in the requested language) if he/she wants to know his/her grade so far in the class (if so, print the grade so far);
Then asked if he/she wants to compute his/her GPA (if so, the GPA method from Activity 1 should be invoked: GPACalculator).
Important Note: any other type of user trying to illegally access the system (i.e., not following any of the above access modes) will be denied access to the system and warned against trying to break into the system illegally.
Important advice: You should first figure out this problem on the paper and turn in what you wrote in preparation for coding (add it to your docx file with the algorithm you have to write). This should really be done before any coding and it is expected to take you about an hour. Do ask for help and validation from the TAs or instructors before you start coding.
Instructions:
1. Write notes about your understanding of the problem and the way to solve it.
2. Write your algorithm (pseudocode) in the docx file you started at Activity 1.
a. It should be self-explanatory.
3. Design (5) scenarios of usage of your (pseudo)code: for this, provide a user input (The possible access levels for a person accessing the system, language chosen, what information to print for the given user, and so on) and show the expected output.
Professor
Student
Student Designer
How to legally access the system?
Someone who properly enters the correct access code for professors (=codeProf) and has picked the English language
Someone who properly enters the correct access code for students (=codeAnyStudent), regardless of chosen language
Someone who properly enters the correct access code for student designer (=codeStudentDesigner) and has not picked English as a language
What is printed?
Asked (in the requested language) if he/she wants to know the name of the Student Designer (if so, the name should be printed as requested);
Then asked if he/she wants to know the GPA of the Student Designer (if so, the GPACalculator of Activity 1 should be invoked and its result printed);
Told (in the requested language) about CS1401 and your instructor.
Asked (in the requested language) if he/she wants to know his/her grade so far in the class (if so, print the grade so far);
Then asked if he/she wants to compute his/her GPA (if so, the GPA method from Activity 1 should be invoked: GPACalculator).
Explanation / Answer
package student.access;
import java.util.Scanner;
public class AccessControl {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String codeProfessor = "codeProf";
String codeStudentDesigner = "codeStuDesigner";
String codeAnyStudent = "codeAnyStu";
String nameOfStudentDesigner = "Your name";
String instructor = "Instructor";
System.out.println("Enter code");
String code = scanner.nextLine();
System.out.println("Enter language");
String language = scanner.nextLine();
if (code.equals(codeProfessor) && language.equals("English")) {
System.out.println("Do you want to know the name of the Student Designer?");
String response = scanner.nextLine();
if (response.toLowerCase().equals("yes")) {
System.out.println("Name of Student Designer is " + nameOfStudentDesigner);
}
System.out.println("Do you want to know the GPA of the Student Designer?");
response = scanner.nextLine();
if (response.toLowerCase().equals("yes")) {
System.out.println("GPA of Student Designer is " + 3.4); // You need to use GPA Calculator from Activity 1 here
}
}
else if (code.equals(codeAnyStudent)) {
System.out.println("Your course is CS1401 and your instructor is " + instructor);
}
else if (code.equals(codeStudentDesigner) && !language.equals("English")) {
System.out.println("Do you want to know your grade so far in the class?");
String response = scanner.nextLine();
if (response.toLowerCase().equals("yes")) {
System.out.println("Your GPA is " + 3.4); // You need to use GPA Calculator from Activity 1 here
}
}
}
}