











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












Summative Feedback: Resubmission Feedback:
Figure 1 Flowchart of application
public int count; public int letter = 1 ; public String destination = ""; public void sendMessage(String mess) { System. out .println("Length of the message: " + mess.length() + " character."); while (count < mess.length()) { while ( sender .size() < mess.length()) { if (count == mess.length()) { break; } sender .offer(mess.charAt(count)); if (mess.charAt(count) == ' ' || mess.charAt(count) == '\t' || mess.charAt(count) == '\n') letter++; count++; } while ( sender .size() != 0 ) { receiver .push( sender .poll()); } while ( receiver .size() != 0 ) { destination = receiver .pop() + destination; } } } }
import java.util.*; public class Main { public static final String ANSI_RESET = "\033[0m"; public static final String GREEN_UNDERLINED = "\033[4;32m"; public static void main(String[] args) { Message message = new Message(); Scanner scanner = new Scanner(System. in ); System. out .print("Please input a message:"); String mess = scanner.nextLine(); boolean option = true; while (option) { try { if (mess.equals("")) { throw new IllegalStateException(); } else if (mess.length() > 250 ) { throw new IndexOutOfBoundsException(); } option = false; } catch (IllegalStateException e) { System. out .println("Message must not mull!!!!"); System. out .print("Please repeat input a message:"); mess = scanner.nextLine(); continue; } catch (IndexOutOfBoundsException e) {
System. out .println("This message is over 250 characters"); System. out .print("Please repeat input a message:"); mess = scanner.nextLine(); continue; } } //Use a programming language (Java) to write a program that can send a text messege (maximum 250 characters) from source to destination. // //Use a programming language (Java) to write a program that can send a text messege (maximum 250 characters) from source to destination. Use a programming language (Java) to write a program that can send a text messege (maximum 250 characters) from source to destination Use a programming language (Java) to write a program that can send a text messege (maximum 250 characters) from source to destination.. long start = System. currentTimeMillis (); message.sendMessage(mess); long finish = System. currentTimeMillis (); double time = finish - start; if (message.count == mess.length()) { System. out .println("The message is sent successfully."); System. out .println("The received message: " + GREEN_UNDERLINED + message.destination + ANSI_RESET ); System. out .println("The received message has " + GREEN_UNDERLINED + message.letter + ANSI_RESET + " letters."); System. out .println("The received message has " + GREEN_UNDERLINED + message.count + ANSI_RESET + " character."); System. out .println("Time : " + GREEN_UNDERLINED + time + ANSI_RESET + " ms"); } else System. out .println("The messege is not sent successfully."); } } II. ADT
} catch (IllegalStateException e) { Scanner scanner = new Scanner(System. in ); System. out .println("Message must not mull!!!!"); System. out .print("Please repeat input a message:"); mess = scanner.nextLine(); continue; } catch (IndexOutOfBoundsException e) { Scanner scanner = new Scanner(System. in ); System. out .println("This message is over 250 characters"); System. out .print("Please repeat input a message:"); mess = scanner.nextLine(); continue; } }
int n = 1000 ; System. out .println("Hey - your input is: " + n);
int n = 1000 ; System. out .println("Hey - your input is: "+n); System. out .println("Hmm.. I'm doing more stuff with: "+n); System. out .println("And more: "+n);
for (int i = 1 ; i < n; i = i * 2 ){ System. out .println("Hey - I'm busy looking at: " + i); }
for (int i = 1 ; i <= n; i++){ for(int j = 1 ; j < n; j = j * 2 ) { System. out .println("Hey - I'm busy looking at: " + i + " and " + j); } }
for (int i = 1 ; i <= n; i++) { for(int j = 1 ; j <= n; j++) { System. out .println("Hey - I'm busy looking at: " + i + " and " + j); } }
for (int i = 1 ; i <= Math. pow ( 2 , n); i++){ System. out .println("Hey - I'm busy looking at: " + i); }
for (int i = 1 ; i <= factorial(n); i++){ System. out .println("Hey - I'm busy looking at: " + i); }
II. Analyze performances
Table 2 Compare time complexity