first commit

This commit is contained in:
Boris
2024-01-15 20:14:10 +00:00
commit 8c81ee28b7
3106 changed files with 474415 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
#BlueJ class context
comment0.params=
comment0.target=InputReader()
comment0.text=\n\ Create\ a\ new\ InputReader\ that\ reads\ text\ from\ the\ text\ terminal.\n
comment1.params=
comment1.target=java.lang.String\ getInput()
comment1.text=\n\ Read\ a\ line\ of\ text\ from\ standard\ input\ (the\ text\ terminal),\n\ and\ return\ it\ as\ a\ String.\n\n\ @return\ \ A\ String\ typed\ by\ the\ user.\n
numComments=2

View File

@@ -0,0 +1,36 @@
import java.util.Scanner;
/**
* InputReader reads typed text input from the standard text terminal.
* The text typed by a user is then chopped into words, and a set of words
* is provided.
*
* @author Michael Kölling and David J. Barnes
* @version 0.2 (2016.02.29)
*/
public class InputReader
{
private Scanner reader;
/**
* Create a new InputReader that reads text from the text terminal.
*/
public InputReader()
{
reader = new Scanner(System.in);
}
/**
* Read a line of text from standard input (the text terminal),
* and return it as a String.
*
* @return A String typed by the user.
*/
public String getInput()
{
System.out.print("> "); // print prompt
String inputLine = reader.nextLine();
return inputLine;
}
}

View File

@@ -0,0 +1,21 @@
TechSupport - the DodgySoft Technical support system, version #2.
This project is part of the material for the book
Objects First with Java - A Practical Introduction using BlueJ
Sixth edition
David J. Barnes and Michael Kölling
Pearson Education, 2016
This project is discussed in chapter 6.
This project implements a second version of the technical support system
example. It is an intermediate version intended to demonstrate the first
few changes discussed in this book chapter.
To start this program, create a SupportSystem object and execute the "start"
method.
Then start describing your problem by typing in the terminal window.

View File

@@ -0,0 +1,11 @@
#BlueJ class context
comment0.params=
comment0.target=Responder()
comment0.text=\n\ Construct\ a\ Responder\n
comment1.params=
comment1.target=java.lang.String\ generateResponse()
comment1.text=\n\ Generate\ a\ response.\n\ \n\ @return\ \ A\ string\ that\ should\ be\ displayed\ as\ the\ response\n
comment2.params=
comment2.target=void\ fillResponses()
comment2.text=\n\ Build\ up\ a\ list\ of\ default\ responses\ from\ which\ we\ can\ pick\ one\n\ if\ we\ don't\ know\ what\ else\ to\ say.\n
numComments=3

View File

@@ -0,0 +1,62 @@
import java.util.ArrayList;
import java.util.Random;
/**
* The responder class represents a response generator object. It is used
* to generate an automatic response. This is the second version of this
* class. This time, we generate some random behavior by randomly selecting
* a phrase from a predefined list of responses.
*
* @author Michael Kölling and David J. Barnes
* @version 0.2 (2016.02.29)
*/
public class Responder
{
private Random randomGenerator;
private ArrayList<String> responses;
/**
* Construct a Responder
*/
public Responder()
{
randomGenerator = new Random();
responses = new ArrayList<>();
fillResponses();
}
/**
* Generate a response.
*
* @return A string that should be displayed as the response
*/
public String generateResponse()
{
// Pick a random number for the index in the default response
// list. The number will be between 0 (inclusive) and the size
// of the list (exclusive).
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 this in more detail?");
responses.add("No other customer has ever complained about this \n" +
"before. What is your system configuration?");
responses.add("I need a bit more information on that.");
responses.add("Have you checked that you do not have a dll conflict?");
responses.add("That is covered in the manual. Have you read the manual?");
responses.add("Your description is a bit wishy-washy. Have you got \n" +
"an expert there with you who could describe this better?");
responses.add("That's not a bug, it's a feature!");
responses.add("Could you elaborate on that?");
responses.add("Have you tried running the app on your phone?");
responses.add("I just checked StackOverflow - they don't know either.");
}
}

View File

@@ -0,0 +1,14 @@
#BlueJ class context
comment0.params=
comment0.target=SupportSystem()
comment0.text=\n\ Creates\ a\ technical\ support\ system.\n
comment1.params=
comment1.target=void\ start()
comment1.text=\n\ Start\ the\ technical\ support\ system.\ This\ will\ print\ a\ welcome\ message\ and\ enter\n\ into\ a\ dialog\ with\ the\ user,\ until\ the\ user\ ends\ the\ dialog.\n
comment2.params=
comment2.target=void\ printWelcome()
comment2.text=\n\ Print\ a\ welcome\ message\ to\ the\ screen.\n
comment3.params=
comment3.target=void\ printGoodbye()
comment3.text=\n\ Print\ a\ good-bye\ message\ to\ the\ screen.\n
numComments=4

View File

@@ -0,0 +1,71 @@
/**
* This class implements a technical support system. It is the top level class
* in this project. The support system communicates via text input/output
* in the text terminal.
*
* This class uses an object of class InputReader to read input from the user,
* and an object of class Responder to generate responses. It contains a loop
* that repeatedly reads input and generates output until the users wants to
* leave.
*
* @author Michael Kölling and David J. Barnes
* @version 0.2 (2016.02.29)
*/
public class SupportSystem
{
private InputReader reader;
private Responder responder;
/**
* Creates a technical support system.
*/
public SupportSystem()
{
reader = new InputReader();
responder = new Responder();
}
/**
* Start the technical support system. This will print a welcome message and enter
* into a dialog with the user, until the user ends the dialog.
*/
public void start()
{
boolean finished = false;
printWelcome();
while(!finished) {
String input = reader.getInput().trim().toLowerCase();
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("Welcome to the DodgySoft Technical Support System.");
System.out.println();
System.out.println("Please tell us about your problem. We will assist you");
System.out.println("with any problem you might have. Please type 'bye'");
System.out.println("to exit our system.");
}
/**
* Print a good-bye message to the screen.
*/
private void printGoodbye()
{
System.out.println("Nice talking to you. Bye...");
}
}

View File

@@ -0,0 +1,61 @@
#BlueJ package file
dependency1.from=SupportSystem
dependency1.to=InputReader
dependency1.type=UsesDependency
dependency2.from=SupportSystem
dependency2.to=Responder
dependency2.type=UsesDependency
objectbench.height=76
objectbench.width=754
package.editor.height=406
package.editor.width=646
package.editor.x=70
package.editor.y=80
package.numDependencies=2
package.numTargets=3
package.showExtends=true
package.showUses=true
project.charset=UTF-8
readme.editor.height=651
readme.editor.width=823
readme.editor.x=53
readme.editor.y=23
target1.editor.height=762
target1.editor.width=908
target1.editor.x=53
target1.editor.y=60
target1.height=60
target1.name=InputReader
target1.naviview.expanded=true
target1.showInterface=false
target1.type=ClassTarget
target1.typeParameters=
target1.width=110
target1.x=130
target1.y=210
target2.editor.height=767
target2.editor.width=1248
target2.editor.x=32
target2.editor.y=23
target2.height=60
target2.name=Responder
target2.naviview.expanded=false
target2.showInterface=false
target2.type=ClassTarget
target2.typeParameters=
target2.width=100
target2.x=380
target2.y=210
target3.editor.height=657
target3.editor.width=921
target3.editor.x=53
target3.editor.y=23
target3.height=60
target3.name=SupportSystem
target3.naviview.expanded=true
target3.showInterface=false
target3.type=ClassTarget
target3.typeParameters=
target3.width=140
target3.x=240
target3.y=90