Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is Java programing. The file ( fruit.txt ) contains name of fruitsYou may u

ID: 3788516 • Letter: T

Question

This is Java programing. The file (fruit.txt) contains name of fruitsYou may use ArryList to save the data into your memory. Your program choose one of the fruits using random method, then outputs the selected fruit name after using Collections.shuffle. User can answer the exact name of the fruit. You are required to use Collections.shuffle for this program. Don’t need to check whether the answer is collect or not.

B A N A N A
A P P L E
O R A N G E
G R A P E
A P R I C O T
H O N E Y B E R R Y
P A P A Y A
B L U E B E R R Y
C H E R R Y
R A S P B E R R Y
G R A P E F R U I T

Out put(Bold is User input)

R G E N A O

Orange

G P A R E

Grape

N A A N A B

Banana

Explanation / Answer

package com.example.shreya.mychegg;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.*;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public static void main(String[] args) {

// create array list object
ArrayList arrayList = new ArrayList();

// populate the list

arrayList.add("BANANA");
arrayList.add("APPLE");
arrayList.add("ORANGE");
arrayList.add("GRAPE");
arrayList.add("APPRICOT");
arrayList.add("HONEYBERRY");
arrayList.add("PAPAYA");
arrayList.add("BLUEBERRY");
arrayList.add("CHERRY");
arrayList.add("RASPBERRY");
arrayList.add("GRAPEFRUIT");



// print all available elements

for (Object num : arrayList) {
System.out.println("Element = " + num);
}

while(true) {
// Shuffle the array
Collections.shuffle(arrayList);
System.out.println(arrayList);

String user = System.console().readLine();
System.out.println("Your guess" + user);

}

}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote