• 0

Need Recheck and Help for Comp Sci assignment


Question

So basically I have these multiple questions that were given by my professor and I done several of it but I want to make sure whether these are corrects or not so please kindly help and check if any wrong

 

1. Which of the following strings would match the pattern: Pattern pattern = Pattern.compile("([Mm]e|[Yy}ou).*\\1$");

a. "Is it me or you"

b. "You're just You"

c. "Some come to me"

d. "Are you here for you or me"

e. "Me for you, and you for me"

f. "It's always me, me, me"

 

My answers: b, c, e, f

 

I posted a picture of my work 

2. Answer : C

3. Answer: A

Part B is shown on the link

For Part C please help me because it's unfinished and I do not think i get it right either

 

http://imgur.com/M4g9TBd,tRRpDLH,jd1j38y

 

 

7 answers to this question

Recommended Posts

  • 0

Are there any typos in this?

 

Pattern pattern = Pattern.compile("([Mm]e|[Yy}ou).*\\1$");

 

At the very least, that should be:

 

Pattern pattern = Pattern.compile("([Mm]e|[Yy]ou).*\\1$");

 

And your code... it looks like it says:

 

while(alist.isEmpty)

 

And that should probably say something like:

 

while(!alist.isEmpty())

  • 0
  On 12/05/2015 at 09:26, atyemail said:

Some1 please help :(

 

https://www.neowin.net/forum/topic/1175473-asking-for-help-with-your-assignments/

 

Ask specific questions and we'll be happy to help, but don't just post the questions and your answers and ask for it to be checked.

 

If you need more general help perhaps ask your teaching assistants for a face-to-face chat.

  • 0
  On 12/05/2015 at 03:06, atyemail said:

ermm no i type everything from the assignment without changing.

 

As correctly pointed out by rfirth, the '}' character in the pattern you quoted should be a ']'. If as you imply the mistake is in source question you copied from, i.e. you didn't make the typo yourself copying it here, then you should report it to your teacher/professor.

 

There's also a typo in part B - 'iter8er' instead of 'itR8R'.

 

  On 12/05/2015 at 02:12, atyemail said:

So basically I have these multiple questions that were given by my professor and I done several of it but I want to make sure whether these are corrects or not so please kindly help and check if any wrong

 

1. Which of the following strings would match the pattern: Pattern pattern = Pattern.compile("([Mm]e|[Yy}ou).*\\1$");

a. "Is it me or you"

b. "You're just You"

c. "Some come to me"

d. "Are you here for you or me"

e. "Me for you, and you for me"

f. "It's always me, me, me"

 

My answers: b, c, e, f

 

I posted a picture of my work 

2. Answer : C

3. Answer: A

Part B is shown on the link

For Part C please help me because it's unfinished and I do not think i get it right either

 

http://imgur.com/M4g9TBd,tRRpDLH,jd1j38y

 

Your answer to #1 is not quite right. Matching capitalisation is important! I won't tell you the answer outright, as it's better for you to work it out yourself, but that clue should be all you require to get the right answer.

 

I would concur with C for #2.

 

For #3 I really need to brush up on the java language constructs at play here (i.e. generics), so at this present time I can't tell you whether or not you are correct. However note that the question allows for more than one of the examples being correct instantiations (you only selected one, so I'm not certain whether you missed that or actually only felt that one was correct). I am not confident about A being a correct instantiation. There is one other, perhaps two that I feel may be correct, but I may very well be wrong.

 

Your answer to part B is correct, putting aside the fact that the typo I pointed out above would prevent the code from actually compiling.

 

For part C, firstly, I'm not happy with what you've written regarding big-Oh notation. Refer back to question #2; all they're asking for is something along the lines of "O(n)"! (But something applicable to this particular algorithm in place of 'n' here if 'n' is not applicable).

 

As for the code...

 

Do try really hard to not slant the code as you're writing it as doing so impacts readability. Furthermore check your indentation; your for loop seems to have an unnecessary extra indentation, when it should actually be inline with the line above it.

 

You started out somewhat well with your while loop, though as pointed out above, it should be checking that the list is NOT empty not that it is empty - big mistake!

 

Inside the while loop you loose me, part of your code seems to be cut off in the image you've taken of it; I can't make out exactly what you've written in that for loop - is that a splodge of ink next to the 'i' or what?; your for loop syntax is wrong (unless this is actually allowed in java, and I don;t think it is) - there are three things to include in a for loop - initialisation, condition and increment/decrement, each separated with a semi-colon (;) character (some can be left out, but the semi-colon separator is still required); your for loop only executes when i = 0, with no 'i' variable having been declared or initialized anywhere, and with no increment occurring anywhere; and what the hell does "temp = alist B empty" mean? And that's not the end of the problems with it. I'm sorry but this is a mess :/

 

Let's walk through this a little. Your code needs to walk through all items in 'aList' to determine which item has the smallest integer. Once it has found the smallest integer, it needs to remove it from 'aList' and add it to 'bList'. It needs to repeat these actions until aList is empty, and thus all items have been moved to bList, now in numerical order, from smallest to largest value. Your while loop, if corrected to run until aList is empty, fulfils the requirement of repeating the set of actions [find smallest; move it to bList] until all items have been moved to bList, so that's a great start. Within the while loop you simply need code to perform those actions. This code can start by assuming that the first entry in the list is the smallest, and needs a variable to keep track of the index number of the item with the smallest number. It then needs to loop over every entry in the list. On each loop, the value of the current item should be compared with the value of the list entry holding the smallest value found so far. If it is equal or greater, you do nothing, but if it is smaller, you set the current index number as being the index number for the smallest item so far. Your for loop can actually skip over the first entry in the list (i.e. initialise i=1 instead of i=0), since before starting the loop you should assume that the first item is the smallest, and there is no point in comparing the first entry with itself when the looping begins. Your code does not need a variable to hold a copy of the smallest value, only a variable to hold the index of the list entry with the smallest value (unless it provides a desirable performance optimisation to actually hold a copy - something that you can ignore here but you may wish to consider in real life code). After the for loop has found the index of the smallest list entry, you then need to simply perform the action of removing that entry from aList and adding a new entry with the same value to bList (tip: it may be best here to add to bList first, then remove from aList, since this avoids needing a variable to hold a copy of the value).

  • 0
  On 12/05/2015 at 02:12, atyemail said:

So basically I have these multiple questions that were given by my professor and I done several of it but I want to make sure whether these are corrects or not so please kindly help and check if any wrong

 

1. Which of the following strings would match the pattern: Pattern pattern = Pattern.compile("([Mm]e|[Yy}ou).*\\1$");

a. "Is it me or you"

b. "You're just You"

c. "Some come to me"

d. "Are you here for you or me"

e. "Me for you, and you for me"

f. "It's always me, me, me"

 

My answers: b, c, e, f

Unless I'm misunderstanding the expression (quite possible given my limited regexp knowledge), shouldn't it only match a starting Me/You (capitial or lower case M/Y) and ending with the same pattern ('\1' is the same pattern matched in group 1)? So according to my understanding only b fits. I wrote a quick java test and it agreed:

import java.util.regex.*;

public class recheck {

	public static void main ( String [] args ) {
		
		String [] matchers = { "Is it me or you", "You're just You", "Some come to me", "Are you here for you or me", "Me for you, and you for me", "It's always me, me, me" }; 

		Pattern p = Pattern.compile ( "([Mm]e|[Yy]ou).*\\1$" ); 
		
		for ( String matcher : matchers ) {
			Matcher m = p.matcher ( matcher );
			if ( m.matches () )
				System.out.format ( "Matcher '%s' matches the pattern\n", matcher );
			else
				System.out.format ( "Matcher '%s' does not match the pattern\n", matcher );
		}
	}	
}	
$ java recheck 
Matcher 'Is it me or you' does not match the pattern
Matcher 'You're just You' matches the pattern
Matcher 'Some come to me' does not match the pattern
Matcher 'Are you here for you or me' does not match the pattern
Matcher 'Me for you, and you for me' does not match the pattern
Matcher 'It's always me, me, me' does not match the pattern
This topic is now closed to further replies.
  • Posts

    • As it would on any other tech website whether it be Windows, Apple, etc. I wouldn’t expect it any other way.
    • Mozilla should shut down everything except the browser and the services they whitelabel (for example Firefox VPN from Mullvad). Everything else just cost them money and have never returned any revenue. Focusing in the browser is what makes sense considering what is going to change regarding their income sources. About Firefox and chromium... if they ever have to abandon Gecko because of financial issues it is more likely to use Apple's WebKit and not Chromium and Blink. WebKit is more versatile for Firefox because it will allow them even to keep Firefox's extension ecosystem. The same way GNOME Web which is a WebKit browser has experimental Firefox extension support.
    • I really dont like how they’ve put shadows under window elements making the sidebar and toolbar buttons look like they sit above the window itself. Looks very odd and clunky.
    • Rubbish. It's chock-full of ads and with manifest 3.0,the gloves are off. Google does not even pretend now. They want évil and want your data
    • Glary Utilities 6.27.0.31 by Razvan Serea Glary Utilities offers numerous powerful and easy-to-use system tools and utilities to fix, speed up, maintain and protect your PC. Glary Utilities allow you to clean common system junk files, as well as invalid registry entries and Internet traces. You can manage and delete browser add-ons, analyze disk space usage and find duplicate files. You can also view and manage installed shell extensions, encrypt your files from unauthorized access and use, split large files into smaller manageable files and then rejoin them. Furthermore, Glary Utilities includes the options to find, fix, or remove broken Windows shortcuts, manage the programs that start at Windows startup and uninstall software. All Glary Utilities tools can be accessed through an eye-pleasing and totally simplistic interface. Glary Utilities 6.27.0.31 changelog: Optimized Disk Cleaner: Optimized the scanning algorithm for Firefox to enhance user experience. Optimized Disk Cleaner: Added support for Nitro Pro 14. Optimized Tracks Eraser: Optimized the scanning algorithm for Firefox to enhance user experience. Optimized Tracks Eraser: Added support for Nitro Pro 14. Optimized Startup Manager: Optimized the review algorithm to enhance user experience. Optimized Uninstaller Manager: Optimized the scanning algorithm to enhance user experience. Minor GUI improvements. Minor bug fixes. Download: Glary Utilities 6.27.0.31 | 27.0 MB (Freeware) Download: Portable Glary Utilities | 32.3 MB View: Glary Utilities Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      IAMFLUXX earned a badge
      Week One Done
    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
    • First Post
      Kurotama earned a badge
      First Post
    • Collaborator
      Carltonbar earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      ATLien_0
      269
    3. 3
      +FloatingFatMan
      241
    4. 4
      +Edouard
      202
    5. 5
      snowy owl
      168
  • Tell a friend

    Love Neowin? Tell a friend!