You are on page 1of 3

C:/Users/User/Desktop/OneDrive - Curro Holdings/Documents/NetBeansProjects/G10_Selection Statements Mock/src/g10_selection/statements/mock/G10_SelectionStatementsMock.

java
1 /*
2 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
4 */
5 package g10_selection.statements.mock;
6
7 import java.util.Scanner;
8
9 /**
10 *
11 * @author User
12 */
13 public class G10_SelectionStatementsMock {
14
15 public static void main(String[] args) {
16
17 }
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
1.1 of 10 2022.05.19 09:55:39
C:/Users/User/Desktop/OneDrive - Curro Holdings/Documents/NetBeansProjects/G10_Selection Statements Mock/src/g10_selection/statements/mock/G10_SelectionStatementsMock.java
34 public static void Mock_1(){
35
36 Scanner input = new Scanner(System.in); //1 Declare scanner
37 String surname, petName, petNameLastTwo, randomUppercaseLetter, randomLowercaseLetter; //2 Correct variable
declaration
38 int age;
39
40 System.out.println("\tPASSWORD GENERATOR"); //1 Displays menu
41 System.out.println("==================================================");
42
43 System.out.println("Please Enter The Following Details: ");
44 System.out.print("\n\tSurname: ");
45 surname = input.next(); //1 Correct capture
46
47 System.out.print("\tAge: ");
48 age = input.nextInt(); //1 Correct capture
49
50 System.out.print("\tPet's Name: ");
51 petName = input.next(); //1 Correct capture
52
53 int length = surname.length(); //1 length used correctly
54
55 int randomLetter1 = (int)(Math.random() * (length - 0 + 1) + 0); //2 random and bounds set
56 int randomLetter2 = (int)(Math.random() * (length - 0 + 1) + 0); //2 random and bounds set
57
58 if(age < 16) //1 correct condition
59 age = age - 5; //1 correct action
60
61 petNameLastTwo = petName.substring(petName.length()-2, petName.length()); //2 substring and parameters
62
63 randomUppercaseLetter = surname.substring(randomLetter1, randomLetter1 + 1).toUpperCase(); //3 substring and
parameters, use of toUpperCase
64
2.1 of 10 2022.05.19 09:55:39
C:/Users/User/Desktop/OneDrive - Curro Holdings/Documents/NetBeansProjects/G10_Selection Statements Mock/src/g10_selection/statements/mock/G10_SelectionStatementsMock.java
65 randomLowercaseLetter = "" + surname.charAt(randomLetter2); //2 charAt and parameters
66 randomLowercaseLetter = randomLowercaseLetter.toLowerCase(); //1 toLowerCase
67
68 String message = petNameLastTwo + "_" + age + randomUppercaseLetter + "/-" + randomLowercaseLetter; //2 Correct
concatenation
69
70 System.out.println("\nNew Password --> " + message); //1 Displayed correctly
71
72 //25 Marks
73 }
74
75
76 public static void Mock_2(){
77
78 int randomNum = (int)(Math.random() * (1000 - 100 + 1) + 100); //2 random and bounds set
79
80 String num = String.valueOf(randomNum); //2 valueOf and parameters //2 Correct variable declaration
81
82 String rearranged = "" + num.charAt(2) + num.charAt(1) + num.charAt(0); //4 correct rearrange using charAt or
substring
83
84 if(num.equals(rearranged)){ //2 correct condition and equals
85
86 System.out.println(num + " Is A Palindrome"); //1 Displayed correctly
87 }
88 else{ //1 else
89
90 System.out.println(num + " Is Not A Palindrome"); //1 Displayed correctly
91 }
92
93 //15 Marks
94 }
95
3.1 of 10 2022.05.19 09:55:39

You might also like