To practice more with collections and exceptions

Assignment Help Computer Engineering
Reference no: EM132076106

Need help to this Java problem.

Objectives:

To practice more with collections and exceptions.

Assignment:

Your job is to extend the Registration System we built in class (attached below) in 3 ways:

• Support a new type of class called a OpenUniversity student. These students do not have an ID, but they do have a phone number. Two students are the same if they have the same name and phone number.

• Allow each course to have a set of Open University students, in addition to regular students. There should be 2 capacities for each course, the number of regular students and the number of Open University students.

• The number of Open Unversity students should not exceed the number of regular students at any time or else an exception should be thrown.

• It should be possible to delete students from a course using a new "ds" command. When that command is entered, the system should ask the user for the ID of the student and then search both the full time students and Open University student lists for that student in the course. If found, that student should be removed from that list.

Retristration System: package mar06registration; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class RegistrationSystem { private Map<String, Course> school; public RegistrationSystem() { school = new HashMap<String, Course>(); } private static void out(String s) { System.out.print(s); } private static void outln(String s) { System.out.println(s); } public static void main(String[] args) { RegistrationSystem rs = new RegistrationSystem(); Scanner s = new Scanner(System.in); boolean done = false; do { out("What next? "); try { String cmd = s.next(); s.nextLine(); switch (cmd) { case "q": { done = true; outln("Goodbye!"); break; } case "ac": { handleAddCourse(s, rs); break; } case "as": { handleAddStudent(s, rs); break; } default: outln("I do not understand you!"); break; } } catch (Exception e) { outln("ERROR: "+e.getMessage()); } } while (!done); } private static void handleAddStudent(Scanner s, RegistrationSystem rs) { out("Student name: "); String name = s.next(); s.nextLine(); out("Student ID: "); String id = s.next(); s.nextLine(); out("Course: "); String courseName = s.next(); s.nextLine(); Student student = new Student(name, id); Course course = new Course(courseName); rs.addStudentToCourse(student, course); outln("Student added!"); } private static void handleAddCourse(Scanner s, RegistrationSystem rs) { out("Course name: "); String name = s.next(); s.nextLine(); out("Course capacity: "); int capacity = s.nextInt(); s.nextLine(); Course c = new Course(name, capacity); rs.addCourse(c); outln("Course added"); } private void addCourse(Course c) { if (courseExist(c)) { throw new RuntimeException("Course already exists"); } addCourseToSchool(c); } private boolean courseExist(Course c) { return school.get(c.getName()) != null; } private void addCourseToSchool(Course c) { school.put(c.getName(), c); } private void addStudentToCourse(Student student, Course course) { Course c = school.get(course.getName()); if (c == null) { throw new RuntimeException("No such course!"); } c.addStudent(student); } }

Reference no: EM132076106

Questions Cloud

Find the average rate of change of c : The cost in dollars of producing x units of a particular camera is C(x) = x2 - 10000.
How long will it take two get the result from the 8-bit : How many gates would be required for an 8-bit adder if it utilized these 4 bit adders in a carry select adder configuration?
Write the equation of the tangent lines : The graph of x^2 + y^2 =100 is a circle having center at the origin and radius 10.
Find the number of units that should be sold : A) Find the number of units that should be sold in order to maximize the total profit. B) What is the maximum profit?
To practice more with collections and exceptions : These students do not have an ID, but they do have a phone number. Two students are the same if they have the same name and phone number.
Combined surface area of all six sides of the box : A box has a square base of side length x meters and height h meters. The volume of the box is V(h,x) and S(h,x) is the combined surface area of all six sides
Write a test program that creates two rectangle objects : Write a test program that creates two Rectangle objects-one with width 4 and height 40 and the other with width 3.5 and height 35.9.
Write a constructor for the dictionary class : Write a constructor for the Dictionary class. The constructor should initialize the instance data variables using parameters.
What are the values of a and b : A given curve in the family x2 + xy + ay2 = b has a tangent line at point (1, 3) with slope -5/14. What are the values of a and b?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd