• 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

    • That will be an interesting comparison. My guess is that the B580 will be the more powerful card, but due to less mature game support, may be slower in some titles. Right now, the B580 is a great budget option, but when it is the same price as the RTX 5050, I suspect many users will opt for the NVidia option if it is their choice. However, a lot of OEM systems are using the B580, so users who barely understand what a dGPU is, are probably going to be using the B580.
    • Google Earth is now 20 years old, brings historical Street View imagery by Aditya Tiwari Google is no longer a young company, and many of its products have been in existence for over two decades. Its "not an April Fools joke" email service turned 21 earlier this year, and now, Google Earth is celebrating its 20th birthday. The search giant announced that Google Earth is getting historical Street View imagery to celebrate the milestone. "Now, you can access historical Street View imagery right from Google Earth — and if you use Google Earth in a professional capacity, you can easily access new datasets, like tree canopy coverage for cities, land temperatures and more," Google said in a blog post. Google Earth is well-known for offering many internet users an interactive bird's-eye view of the world at a time when mapping apps weren't as advanced. It was launched in June 2005 and features 3D buildings across major US cities, integrated local search, and 3D terrains showing mountains, valleys, and canyons around the world. Users could activate, tilt, and rotate 3D terrain for a different perspective of a location. It was an instant hit after launch, with over 100 million downloads in its first week. Just months later, Google worked with the National Oceanic and Atmospheric Administration (NOAA) to make updated imagery available to first responders battling Hurricane Katrina. However, the tech that powers Google Earth is a bit older than that. It was initially developed as Earth Viewer by Keyhole Inc., which Google acquired in 2004 and later rebranded. Now accessible via web browsers and mobile apps, Google Earth was initially available as free-to-download desktop software for Windows, Mac, and Linux. The company also offered Google Earth Pro for $399 per year, but it was later made available for free. Google Earth in 2005 Google Earth differs from Google Maps, which also debuted in 2005. While Google Earth is more focused on exploration and research, its sibling is inclined towards finding real-time information and navigation. Google Earth is known for the flying animation that appears when you go from one place to another. Not just the Earth's surface, you can also explore the ocean floor, the Moon, and Mars (via desktop app). The virtual globe app has been used to discover a rare type of coral reef off the west coast of Australia, often referred to as "the rainforest of the sea." The 2016 movie Lion told the story of a man who used Google Earth to reunite with his mother 25 years after he got separated from his family. Google Earth has seen several new features over the past two decades, including VR support, distance measuring support, the ability to create virtual tours, and Timelapse. In 2017, the 'new Google Earth' added the "I'm Feeling Lucky" button and a discovery-focused feature called Voyager. Another redesign introduced in 2023 allows professionals to evaluate building and solar design options. A feature introduced last year allows users to view historical aerial imagery of places dating back up to 80 years.
    • whats this crap, looks ai generated and what is the point of the fake video tape effect 
    • You say that thinking you will be running Windows 10 IoT...you'll realize you will not be doing that once you install it for the first time and realize what it is (and more importantly, what it is not).
    • couple of things to check:  Try disabling Wi-Fi Power Saving or eco Mode in the TV’s settings Disable band steering or Smart Connect in your router’s 5 GHz settings and create separate SSIDs for 2.4 GHz and 5 GHz, then connect the TV to the 5 GHz SSID there might me interfere from neighbours wifi, try wifiman (android app) . scan to see if there are any overlaps and then adjust yours accordingly  try disabling ipv6 on both  
  • Recent Achievements

    • Week One Done
      Sharon dixon earned a badge
      Week One Done
    • Dedicated
      Parallax Abstraction earned a badge
      Dedicated
    • First Post
      956400 earned a badge
      First Post
    • Week One Done
      davidfegan earned a badge
      Week One Done
    • First Post
      Ainajohn earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      593
    2. 2
      ATLien_0
      222
    3. 3
      Michael Scrip
      170
    4. 4
      +FloatingFatMan
      152
    5. 5
      Som
      136
  • Tell a friend

    Love Neowin? Tell a friend!