代写Java代码,实现多重通配符的逻辑,同时不允许使用String类中的任何方法。
Important Notes
- You need the knowledge from Lecture 1 to Lecture 9 to complete the assignment.
- If your program is found to be a copy, your name will be submitted to university.
- You should use methods in this assignment whenever appropriate.
- You are not allowed to use methods in STRING class (except for printing purpose) for this assignment.
Pattern Matching with a Wild Card
Your task
A pattern matches a list if the list contains the pattern. For example, if a
pattern is 34 and a list is 123456, there is a match between the pattern and
list. A wild card is a pattern with a hidden digit (), which can match to
none or any single digit in a list. For example, if a pattern is 35 and a
list is 12345678, there is one match between the pattern and list (i.e., 345).
Write a program to check whether a pattern matches a list, and output 1) the
number of matches, 2) all the matches, and 3) the frequency of each match.
Note that a pattern can have none or any number of hidden digits.
Your program should prompt the user to enter a list of digits (from 1 to 9) as
an array of integers and a pattern as an integer. For pattern, use the digit
‘0’ to represent a hidden digit or *. For list, the first number in the list
indicates the number of the elements in the list.
Sample output
The underline characters are input by the user.
Sample 1 - easy sample!
Note: 88:2 means the pattern 88 is matched by two times.
Enter list: 9 2 5 6 8 8 4 5 8 8
Enter pattern: 88
There are 2 matches.
The matches are 88:2
Sample 2 - easy sample!
Enter list: 8 5 5 6 6 6 3 2 9
Enter pattern: 304
There is no match.
Sample 3 - normal sample!
Note: The pattern 83 matches the “843” and “823” in the list.
Enter list: 10 2 5 6 8 4 3 4 8 2 3
Enter pattern: 803
There are 2 matches.
The matches are 83:2
Sample 4 - difficult sample!
Enter list: 12 2 5 6 4 5 6 1 6 2 4 6 1
Enter pattern: 803
There are 2 matches.
The matches are 83:2
Sample 5 - very difficult sample by spotting with human eye!
Enter list: 9 2 5 8 8 3 8 8 3 3
Enter pattern: 80803
There are 4 matches.
The matches are 883:2, 883:1, 883:1
Marking scheme
Programming Skill
You should use methods to make your program readable.
Program Correctness
The total mark is 70%. Mark will be allocated depending on the level of
difficulty your program can handle.
Difficulty level I
Your program can handle a pattern with at most three digits, including one of
the digits as the hidden digit. See samples1, 2 and 3 for examples.
Difficulty level II
Your program can handle a pattern with at most four digits, including two of
the digits as the hidden digits. See sample 4 for example.
Difficulty level III
Your program can handle a pattern with at most 41 digits, and with at most 39
hidden digits. See sample 5 for example.
Advice
Concentrate on easy and normal samples first (difficulty level I)! Samples 4
and 5 (levels II & III) are not easy, but students expect to receive grade A
or above should attempt.
Submission Guidelines
How to name my files?
Source Program: P1xxxxxxxx.java (xxxxxxxx is your student number)
Bytecode file: P1xxxxxxxx.class (xxxxxxxx is your student number)
(If your student number is 50259415, your filenames should be P150259415.java
and P150259415.class)
What files do I need to submit?
- A single zip file (by Winzip) named as xxxxxxxx.zip for submission. There should be 2 files in the zip file, one source program and one bytecode.
- The source program should be named as:
P1xxxxxxxx.java - The Java bytecode file should be named as:
P1xxxxxxxx.class
(Note: xxxxxxxx is your eight digit student number)
What if I do not follow the suggested filenames
Your assignment may not be marked.
What is “Programming Skills”?
- Document your source programs properly (e.g., put appropriate comments at appropriate places in your source programs)
- Name the variables in the meaningful ways
- Use proper indentation
- Your programs are well designed and easily readable
How do you mark my assignment?
- For each problem, we have several test cases. If your .class program gives correct answers to all the test cases, you get full marks for “Program correction”
- If your program does not show correct answers, some (or all) marks will be deducted depending on the mistakes/errors you make
- If your program has “compilation errors”, at least half marks will be deducted.
- We also also mark your “programming skills”.
What else I should know?
Each source program must start with the following comments:
// Name: (Your name)
// Student ID: (Your student ID)
// Lab section: (Your lab session) (e.g., T01)
—|—
Please delete your package line (for example: package assignment2;) before
submission.