Tugas PBO A - Technical Support System
Tugas PBO A kali ini yaitu membuat Technical Support System dengan BlueJ.
Nama : Ifta Jihan N
NRP : 05111740000034
Kelas : PBO A
Technical support system yaitu sebuah program untuk melayani problem dari para customer.
Class yang saya buat yaitu:
1. SupportSystem
2. InputReader
3. Responder
Source code:
1. SupportSystem
/**
* Class SupportSystem
* @author Ifta Jihan N (05111740000034)
* PBO A 08/10/2018
*/
public class SupportSystem
{
private InputReader reader;
private Responder responder;
/**
* Creates a technical support system.
*/
public SupportSystem()
{
reader = new InputReader();
responder = new Responder();
}
/**
* Welcome message and enter into a dialog with the user.
*/
public void start()
{
boolean finished = false;
printWelcome();
while(!finished)
{
String input = reader.getInput();
if(input.startsWith("bye"))
{
finished = true;
}
else
{
String response = responder.generateResponse();
System.out.println(response);
}
}
printGoodbye();
}
/**
* Print a welcome message to the screen.
*/
private void printWelcome()
{
System.out.println("Hello!");
System.out.println();
System.out.println("Please tell us about your problem.");
System.out.println("We will assist you with any problem you might have.");
System.out.println("Please type 'bye' to exit our system");
}
/**
* Print a good-bye message to the screen
*/
private void printGoodbye()
{
System.out.println("Nice talking to you. Bye!");
}
}
2. InputReader
import java.util.Scanner;
/**
* class InputReader
*
* @author Ifta Jihan N (05111740000034)
* PBO A 08/10/2018
*/
public class InputReader
{
private Scanner reader;
public InputReader()
{
reader = new Scanner(System.in);
}
/**
* Read a line of text from standard input (the text terminal),
* and return it as a String.
*/
public String getInput()
{
System.out.print("> "); // print prompt
String inputLine = reader.nextLine();
return inputLine; //A string typed by the user
}
}
3. Responder
import java.util.ArrayList;
import java.util.Random;
/**
* class Responder
*
* @author Ifta Jihan N (05111740000034)
* PBO A 08/10/2018
*/
public class Responder
{
private Random randomGenerator;
private ArrayList<String> responses;
/**
* Construct a Responder
*/
public Responder()
{
randomGenerator = new Random();
responses = new ArrayList<String>();
fillResponses();
}
public String generateResponse()
{
int index = randomGenerator.nextInt(responses.size());
return responses.get(index);
}
/**
* Build up a list of default responses from which we can pick one
* if we don't know what else to say.
*/
private void fillResponses()
{
responses.add("That sounds odd. Could you describe that problem in more detail?");
responses.add("Okay. Tell me more...");
responses.add("I need a bit more information on that.");
responses.add("Okay, Don't worry");
}
}
Output:
Comments
Post a Comment