1 Create a Java Program (75 points) Write a class to solve department codes at E
ID: 3681650 • Letter: 1
Question
1 Create a Java Program (75 points) Write a class to solve department codes at Engineering and Architecture Faculty for Gediz University. Your class should have the following abilities Finding the department name for a given department code. (10 points) Finding the department code for a given department at university and shown in the Table1. (15 points) Getting the department code and department (10 points) Editing the department code and department (10 points) Department Department Code AR BME COM EEM END INAR CIV MEC Others Architecture Biomedical Engineering Computer Engineerin Electrical Electronics Engineerin Industrial Engineerin Interior Architecture and Environmental Design Civil Engineerin Mechanical Engineerin Undefined Table 1: Engineering and Architecture Faculty Department list for Gediz University Then, write a test application to produce output similar to the following. (23 points) *Please, before coding, draw a UML class diagram for the classes. (7 points)Explanation / Answer
(1) Code for question 1
import java.util.*;
public class departmentCode{
public Map<String, String> table = new HashMap<String, String>();
public String departmentNameToCode(String dept){
if(table.containsKey(dept))
return table.get(dept);
else
return "Others";
}
public String departmentCodeToName(String code){
if(table.containsValue(code)){
for (Map.Entry<String, String> entry : table.entrySet()) {
if (entry.getValue().equals(code)) {
return (entry.getKey());
}
}
}
else
return "Undefined";
return "";
}
public void getDepartmentCodeAndName(){
for (Map.Entry<String, String> entry : table.entrySet()) {
System.out.println(entry.getKey()+" "+entry.getValue());
}
}
public static void main(String[] args){
departmentCode obj=new departmentCode();
obj.table.put("Architecture","AR");
obj.table.put("Biomedical Engineering","BME");
obj.table.put("Computer Engineering","COM");
obj.table.put("Electrical-Electronics Engineering","EEM");
obj.table.put("Industrial Engineering","END");
obj.table.put("Interior Architecture and Environmental Design","INAR");
obj.table.put("Civil Environmental","CIV");
obj.table.put("Mechanical Environmental","MEC");
System.out.println("This program a department code solver for Architecture and engineering Faculty at Gadiz university!");
while(true){
System.out.println("*********************MENU*********************");
System.out.println(" 1-Search department by department code");
System.out.println(" 2-Search department code by department name");
System.out.println(" -1-Exit");
System.out.println("**********************************************");
System.out.println("");
System.out.println("Please enter your choice [1,2,-1]");
int n = Integer.parseInt(System.console().readLine());
System.out.println(" ");
if(n==1){
System.out.println("Please enter a department code : ");
Scanner s = new Scanner(System.in);
String code = s.nextLine();
if(obj.departmentCodeToName(code)=="Undefined")
System.out.println("The department code does not belongs to the faculty!");
else
System.out.println(code+" is department code for "+obj.departmentCodeToName(code));
}
else if(n==2){
System.out.println("Please enter a department name in the faculty : ");
Scanner s = new Scanner(System.in);
String dept = s.nextLine();
if(obj.departmentNameToCode(dept)=="Others")
System.out.println("There is no such a department in the faculty!");
else
System.out.println(dept+"'s code is "+obj.departmentNameToCode(dept));
}
else if(n==-1){
System.out.println("Exiting..........");
System.out.println("Program terminated!");
break;
}
}
}
}
(2) Code for question 2:
public static void main(String args[]){
int row=1;
while(row<=10){
int column=1;
if(row%2==0)
System.out.print(" ");
while(column<=20){
System.out.print(" * ");
column++;
}
System.out.println();
row++;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.