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

END-OF-SEMESTER S710 Question 2 (22 marks) CFS IM is planning to have a self-ser

ID: 3586682 • Letter: E

Question

END-OF-SEMESTER S710 Question 2 (22 marks) CFS IM is planning to have a self-service laundry facilitiy at students' mahallah. The washing machines in the laundromat will operate based on the following charges TIME (min) 40 35 20 PRICE (RM) 12.00 5.00 6.50 TYPE OF FABRICS Regular Wool You are required to write a program for the self service laundry based on the following requirements DO NOT use any global variable Declare and initialize the following arrays in madn A one-dimensional array named input [1 to read type of fabrics entered by b. A two-dimensional array named fabrica11 to store the available type of array named time [1 to store the allocated time to wash each abric types of fabrics array named price [1 to store the charges for each fabrics. array named yesno [1 to store user option either to continue The program will continue with another washing until user decides to stop. Use a or not. Accepted value for amay yesno[1 is either "YES" or "NO" only do.uhile loop structure for this process

Explanation / Answer

/**The program runs on user input as YES/NO on a do while loop so the count of user input cannot be defined, and arrays cannot be created since for arrays, the size must be fixed.

The program uses a String variable instead of an 1-D array, and a String variable yes/no instead of an 1-D array.

The fabrics array, time array and price array are 3 parallel 1-D arrays.

**/

import java.io.*;

public class SelfServiceLaundry {

public static void main(String args[])throws IOException {

String input="";

String fabrics[]={"Blanket","Regular","Wool"};

int time[]={40,35,20};

double price[]={12.00,5.00,6.50};

int index=-1;

String yesno="";

int totaltime=0;

double totalprice=0;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

do{

System.out.println("Please enter your choice of fabric:");

input=br.readLine();

index=searchFabric(fabrics,input);

if(index==-1){

System.out.println("Sorry! We do not wash "+input);

}

else {

System.out.println("Time required= "+time[index]+" mins");

System.out.println("Price= "+price[index]+" RM");

totaltime+=time[index];

totalprice+=price[index];

System.out.println(input + " washed.");

}

System.out.println("Do you want to continue? [YES / NO] ");

yesno=br.readLine();

}while(yesno.equals("YES"));

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

System.out.println("Thank you. Total time= "+totaltime+" min"+

" Total Price= "+totalprice+" RM");

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

}

public static int searchFabric(String fabrics[],String args) {

for(int i=0;i<fabrics.length;i++){

if(fabrics[i].equalsIgnoreCase(args)){

return i;

}

}

return -1;

}

}

/******************************************************/

END OF PROGRAM

/******************************************************/

Sample Input 1:

Blanket

YES

Regular

YES

Wool

NO

Sample Output 1:

Please enter your choice of fabric:

Time required= 40 mins

Price= 12.0 RM

Blanket washed.

Do you want to continue? [YES / NO]

Please enter your choice of fabric:

Time required= 35 mins

Price= 5.0 RM

Regular washed.

Do you want to continue? [YES / NO]

Please enter your choice of fabric:

Time required= 20 mins

Price= 6.5 RM

Wool washed.

Do you want to continue? [YES / NO]

************************************

Thank you.

Total time= 95 min

Total Price= 23.5 RM

************************************

Sample Input 2:

Mattress

YES

Regular

NO

Sample Output 2:

Please enter your choice of fabric:

Sorry! We do not wash Mattress

Do you want to continue? [YES / NO]

Please enter your choice of fabric:

Time required= 35 mins

Price= 5.0 RM

Regular washed.

Do you want to continue? [YES / NO]

************************************

Thank you.

Total time= 35 min

Total Price= 5.0 RM

************************************