Question 4 You as a programmer, have been asked to

Berikut ini adalah pertanyaan dari affamera pada mata pelajaran Bahasa lain untuk jenjang Sekolah Menengah Atas

Question 4 You as a programmer, have been asked to write an application for Tesco Sdn Bhd to generate customer ID. This application prompts a user for full name and street address and constructs an ID from the user's initial and numeric part of the address. The sample are given below in Table 1: Customer name Customer address Customer ID Zeedny Eilman 213 Taman Megah ZE213 Table 1: Sample of Customer ID​

Jawaban dan Penjelasan

Berikut ini adalah pilihan jawaban terbaik dari pertanyaan diatas.

// Import Scanner class
import java.util.Scanner;
// Create a class Main public class Main
{
// Main method
public static void main(String[] args)
{
// Create an object of Scanner class
Scanner scan = new Scanner(System.in);
// Take Customer name
System.out.print("Enter full name of Customer: ");
String name = scan.nextLine();
// Take address
System.out.print("Enter address of Customer: ");
String address = scan.nextLine();
// Split the name string into array of string with delimeter space
String[] nameSplit = name.split(" ");
// Used to store intial of name
String intial = "";
// Loop for each string in splitted name
for(int i = 0; i < nameSplit.length; i++)
{
// Concatenate the first character from splitted name string
intial += nameSplit[i].charAt(0);
}
// SPlit the address using delimeter space
String[] addressSplit = address.split(" ");
// Concatenate the intial & first numerical part of address to create ID
String cutomer_id = intial + addressSplit[0];
// Print the Customer ID
System.out.println("Customer ID: " + cutomer_id);
}
}

Semoga dengan pertanyaan yang sudah terjawab oleh ECAH00 dapat membantu memudahkan mengerjakan soal, tugas dan PR sekolah kalian.

Apabila terdapat kesalahan dalam mengerjakan soal, silahkan koreksi jawaban dengan mengirimkan email ke yomemimo.com melalui halaman Contact

Last Update: Sat, 09 Jul 22