CS508 Assignment Solution Code Fall 23

 CS508 Assignment Solution Code Fall 23


Get Cs508 Assignment code :



import java.util.Random;

import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        // Print student ID

        System.out.println("VU Student ID: JUNAID MALIK");


        // Create a Scanner object for input

        Scanner input = new Scanner(System.in);


        // Get input for brand name, gender, product name, and year of manufacturing

        System.out.print("Enter the brand name: ");

        String brandName = input.nextLine();

        System.out.print("Enter the gender: ");

        String gender = input.nextLine();

        System.out.print("Enter the product name: ");

        String productName = input.nextLine();

        System.out.print("Enter the year of manufacturing: ");

        String year = input.nextLine();


        // Generate product ID

        String productId = generateProductId(brandName, gender, productName, year);

        System.out.println("Product ID: " + productId);

    }


    private static String generateProductId(String brandName, String gender, String productName, String year) {

        // Get first two characters of brand name

        String brandInitials = brandName.substring(0, 2).toUpperCase();


        // Get first two characters of gender

        String genderInitials = gender.substring(0, 2).toUpperCase();


        // Get first two characters of product name

        String productInitials = productName.substring(0, 2).toUpperCase();


        // Get last two digits of year

        String yearDigits = year.substring(2);


        // Generate a random 5-digit number

        Random rand = new Random();

        int randomNumber = rand.nextInt(99999) + 1;

        String randomNumberString = String.format("%05d", randomNumber);


        // Concatenate all the parts of the product ID

        String productId = brandInitials + genderInitials + productInitials + yearDigits + randomNumberString;


        return productId;

    }

}


CS508 Assignment Solution Code Fall 23

Visit this site for more assignments, GDBs etc