Study Weekly | Week 4 in March

The editing page of wow CSDN has been updated. (^ - ^) It
feels more convenient in the past. Hahahaha

1. Learning content

1.Overview

  • Exception handling
  • Comprehensive project 3: Development team scheduling software
  • Advanced articles-multithreading
  • Advanced articles-commonly used categories

2.Specific contents

Exception handling

  • Exception handling mechanism: (2 methods)
    try catch finally: commonly used, try {enclose exception} catch (exception type) {handle exception method} finally {content that will be executed}
    throws: throw to the superior
  • Manually throw exception objects-catch and throw method
    Throw: 2 kinds, the system automatically throws, throw throws (such as negative input, etc.)
    catch: 2 kinds, try catch finally, throws

Insert picture description here

Project 3 Development team scheduling software

domain-the package where the Javabean class is located

Employee and subclass Programmer, Designer, Architect
Interface Equipment and implementation classes NoteBook, PC, Printer

Basic class creation

service-specific implementation module

NameListService:
responsible for encapsulating data Data of the Employee [] array, while providing related operations Employee [] method
Insert picture description here
Employee [] charged with ID name, age, salary bonus stock positions device
1. First Data to build the number of array
2. Total The ID name, age and salary can be obtained by Data.EMPLOMMES [i] [1]
* Note that int type double should use Integer.parseInt to convert string type to int
[eg] double salary = Integer.parseInt (Data.EMPLOYEES [i] [4 ]);
3. Use switch (type)
{case xxx:
break; ...
}
According to the type, extract the corresponding equipment and bonuses, stocks, positions
【eg】 employees [i] = new Architect (id, name, age, salary , equipment, bonus, stock); The
equipment obtained in 4.3 can be written as a method: createEquipment (i)
generates the corresponding text content according to the type in the Data.EQUIPMENTS [] [] array, using switch case
[eg]
double price = Double.parseDouble (Data.EQUIPMENTS [i] [2]);
return new NoteBook (model, price);
5. Get all employees method getAllEmployees ()
directly return employees;
6. Get employees method with specified id getEmployee (int id) throws TeamException {
* Note that the specified employee exception cannot be found
【eg】 throw new TeamException (“Cannot find the specified Employee "); // throw an exception
Insert picture description here

TeamService
management of development team members: add, delete, etc.
Insert picture description here
1. Attribute
counter: member id from 1 ++ [static int]
MAX_MEMBER: limit the number of development teams [final int]
Programmer [] team: array team, save development team members
total: record the actual number of people in the development team [int]
2.getTeam ()
Get all members of the development team
team [i] = this.team [i];
3.addMember (Employee e) throws TeamException {
Add the specified employee to
3.1 errors in the development team, the error is reported
that the member is not a developer and cannot be added
The employee is already in the development team (using the isExit method)
The employee is already a member of the team (judging by status status) The member is on vacation and cannot be added
There can be at most one architect in the
team. There can be at most two designers in the
team. There can be at most three programmers in the team.

[Eg] This member is not a developer and cannot be added
if (! (E instanceof Programmer)) {
throw new TeamException ("This member is not a developer and cannot be added");
}
[eg] Determine the status
The employee is already a member of a team (judgment by status) The employee is on vacation and cannot be added
// 1. Forced
Programmer p = (Programmer) e;
// 2. Judgment status
if (“BUSY” .equals (p. getStatus (). getNAME ())) {// Note in front, may be null pointer error
throw new TeamException ("The employee is already a team member");
} else if ("VOCATION" .equals (p.getStatus ( ) .getNAME ())) {
throw new TeamException ("This member is on vacation and cannot be added");
}
3.2 If the limit is reached, an error is reported
// Get the architects, designers, programmers of the existing members of the team the number of
IF (team [I] the instanceof Architect) {
numOfArch ++;
// get the current category p
IF (Architect the instanceof p) {
IF (numOfArch> =. 1) {
the throw new new TeamException ( "team can have at most one architect ”);
}
} Else if (p instanceof Designer) {
Note the necessary if () {if ()…} writing, and the order from small Arc to big Pro
With && writing, when the architect is full, joining the architect will enter the else if and treat the architect as a designer.
Logically understand
3.3 join
// add
team [total ++] = p;
// status
p.setStatus (Status.BUSY);
// mID
p.setMemberId (counter ++);
4. delete
removeMember (int memberId) throws TeamException {
// 1 for traversing the team to find the id, the status is changed to FREE, and it breaks out when it finds it
// error is reported if (i == total) {// If it is known that no match can be found, the last is total
throw new TeamException ("Cannot find the specified Staff memberId, delete failed ");
}
// 2 delete — j-1 = j; total-1 = null;

View module

Write the corresponding output interface and
pay attention to when and when the while loop is not used

 switch (menu){
               case '1':
                   getTeam();//显示团队成员列表
                   break;
               case '2':
                   addMember();//添加成员
                   break;
               case '3':
                   deleteMember();//删除成员
                   break;
               case '4':
                   System.out.println("确认是否退出(Y/N):");
                   char isExit = TSUtility.readConfirmSelection();
                   if (isExit == 'Y'){
                       loopFlag = false;
                   }

Insert picture description here
Insert picture description here

Advanced articles-multithreading

Thread creation (4 methods)

Inherit Thread,
implement runnable interface,
implement Callable interface,
use thread pool (commonly used)

Solve the problem of thread safety (3 methods)

Synchronized code block synchronized (same synchronization monitor) {}
Synchronization method private synchronized void show () {}
Lock lock manual.lock .unlock

Advanced articles-JAVA commonly used ing

String ... the location created internally

Insert picture description here

3. Problems encountered and reflection (80/100)

  • Unfamiliar with IDEA's shortcut keys,
    slowly accumulate and replace common operations with shortcut keys
  • I don't quite understand the relationship between the packages under the IDEA project
  • Huawei pick soft warm-up match ... get it working ... even import data
    retrieval capabilities to enhance, Baidu is not in place
    and other systems completion and then look

2. Plan next week

  • Continue to advanced stage
  • HW soft pick topics look at
  • Android development tutorial
Published 14 original articles · Likes0 · Visits 575

Guess you like

Origin blog.csdn.net/weixin_44618426/article/details/105167181