Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Comment the code please: (1) import java.util.ArrayList; import java.util.Scanner; public class ScannerExample { public static void main(String[] args) { Scanner scanner; int cid, cpin; String

Comment the code please:

(1)

import java.util.ArrayList;

import java.util.Scanner;

public class ScannerExample {

public static void main(String[] args) {

Scanner scanner;

int cid, cpin;

String cname, mname;

ArrayList movieList;

/* create movie list */

movieList = new ArrayList<>();

movieList.add("star wars");

movieList.add("the matrix");

movieList.add("the godfather");

/* Scanner gets various input types */

scanner = new Scanner(System.in);

System.out.print("Enter Movie Name You Want To See: ");

mname=(scanner.nextLine());

System.out.print("Enter Customer ID: ");

cid = (scanner.nextInt());

scanner.nextLine(); //needed to pick up the new line

System.out.print("Enter Customer Name: ");

cname=(scanner.nextLine());

System.out.print("Enter Customer PIN: ");

cpin=(scanner.nextInt());

scanner.close();

System.out.println("Movie Name: " + mname);

System.out.println("Customer ID: " + cid);

System.out.println("Customer Name: " + cname);

System.out.println("Customer PIN: " + cpin);

/* search for customer requested movie */

System.out.println();

System.out.println("Search for customer requested movie");

int n=0;

for(String movieName : movieList) {

System.out.print("movie[" + n++ + "] = " + movieName);

if(movieName.equals(mname)) {

System.out.print(" **** movie FOUND");

}

System.out.println();

}

/* parse string in ename and get each token/word */

String[] words = cname.split("\\s");

System.out.println();

System.out.println("Output of words in string array cname ---- words[] length: " + words.length);

for(int i=0; i

System.out.println("words[" + i + "] = " + words[i]);

if(words[i] == "the matrix") {

System.out.println("movie FOUND");

}

}

/* parse string in ename and get each character */

char[] stringToCharArray = cname.toCharArray();

System.out.println();

System.out.print("Output of characters in string array cname: ");

for (char output : stringToCharArray) {

System.out.print(output + " ");

}

System.out.println();

}

}

(2)

import java.util.HashMap;

import java.util.HashSet;

import java.util.ArrayList;

public class HashMapHashSetArrayListDemo {

private static HashMap demoMap;

private static HashSet demoSet;

private static ArrayList demoList;

public static void main(String[] args) {

runExample();

}

private static void runExample() {

System.out.println("runExample()");

demoSimpleMap();

demoHashSet();

demoArrayList();

}

private static void demoSimpleMap() {

demoMap = new HashMap<>();

demoMap.put("piano", "hello doug");

demoMap.put("k-line", "hello marvin");

String message = demoMap.get("piano");

System.out.println("hashmap: " + message);

message = demoMap.get("k-line");

System.out.println("hashmap: " + message);

}

private static void demoHashSet() {

demoSet = new HashSet<>();

demoSet.add("member 1");

demoSet.add("member 2");

demoSet.add("member 3");

for(String item : demoSet) {

System.out.println("demoSet: " + item);

}

}

private static void demoArrayList() {

demoList = new ArrayList<>();

demoList.add("chopin");

demoList.add("beethoven");

demoList.add("bach");

for(String item : demoList) {

System.out.println("demoList: " + item);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions