辅导Eclipse workspace、辅导java/C/C++程序语言、讲解CS/python 解析Haskell程序|解析Haskell程序
Project Requirements
Create a new Eclipse workspace named "Project_1234567890" on the desktop of your computer (replace
1234567890 with your student ID number). For each question below, create a new project in that workspace. Call
each project by its question number: "Question1", "Question2", etc. If you do not remember how to create a
workspace or projects, read the "Introduction to Eclipse" document which is on iSpace. Answer all the questions below.
At the end of the project, create a ZIP archive of the whole workspace folder. The resulting ZIP file must be called
"Project_1234567890.zip" (replace 1234567890 with your student ID number). Upload the ZIP file on iSpace.
Here are a few extra instructions:
Give meaningful names to your variables so we can easily know what each variable is used for in your program.
Put comments in your code (in English!) to explain WHAT your code is doing and also to explain HOW your program
is doing it. Also put comments in your tests.
Make sure all your code is properly indented (formatted). Your code should be beautiful to read.
Failure to follow these instructions will result in you losing points.
Question 1
In this project you need to write software for an electricity company. The electricity company has different kinds of
buildings connected to its electrical grid: electric power plants that generate electricity, different kinds of houses that
consume electricity, etc. All these buildings generate or consume a certain amount of electric power, expressed in watts.
Write a Consumer interface for electricity consumers, with the following UML specification:
+-------------------------------+
| <> |
| Consumer |
+-------------------------------+
| + getName(): String |
| + getPower (): int |
| + morePower(int amount): void |
+-------------------------------+
and a Building class that implements Consumer and has the following UML specification:
+------------------------------------+
| Building |
+------------------------------------+
| - name: String |
| - power: int |
+------------------------------------+
| + Building(String name, int power) |
| + getName(): String |
| + getPower(): int |
| # setPower(int power): void |
| + morePower(int amount): void |
| + testBuilding(): void |
+------------------------------------+The name instance variable indicates the name of the building. The power instance variable indicates the amount of
power consumed by the building (to simplify the assignment we will assume that power is always expressed as an
integer number of watts).
The setPower method changes the amount of power consumed by the building. The setPower method is
protected, not public. This means that only subclasses of the Building class can use the setPower method.
All the other classes in the software cannot use the setPower method, so they cannot set the amount of power
consumed by a building.
The purpose of the morePower method is to increase the amount of power generated or consumed by a building
(depending on what kind of building it is) by the amount given as argument to the method. The morePower method of
the Building class is abstract, since we do not know what kind of building (a building generating power or a
building consuming power) the building is.
Also add to your program a Test class to test your Building class.
Question 2
Add a class PowerPlant that extends Building. The constructor of the PowerPlant class takes as arguments a
name and the amount of power generated by the power plant. The PowerPlant class does not have any instance
variable.
Warning: the constructor of the PowerPlant class takes as argument the amount of power generated by the power
plant, but the power instance variable of the Building class indicates how much power the building consumes!
Generating power is the same as consuming a negative amount of power (in accordance with the passive sign
convention of electrical engineering).
The morePower method of the PowerPlant class increases the amount of power generated by the power plant by
the amount of power given as argument to the method (so the power consumed by the power plant becomes more
negative!)
Here are some tests for your new PowerPlant class:
public static void testPowerPlant() {
PowerPlant p = new PowerPlant("UIC Power Plant", 1000000);
System.out.println(p.getName() == "UIC Power Plant");
System.out.println(p.getPower() == -1000000);
p.setPower(-2000000); // Sets the power consumed by the power plant.
System.out.println(p.getPower() == -2000000);
p.morePower(500000); // Increases the power generated by the power plant.
System.out.println(p.getPower() == -2500000);
p.morePower(-2510000); // Turn off the power plant: it now consumes electricity.
System.out.println(p.getPower() == 10000);
}
Question 3
Add a class House that extends Building. The constructor of the House class takes as arguments the name of the
house’s owner and the amount of power consumed by the house. If the amount of power given as argument is strictly
less than zero then the constructor must throw a NotAPowerGeneratorException with the message "A new
house cannot generate power". The House class does not have any instance variable.The morePower method of the House class increases the amount of power consumed by the house by the amount of
power given as argument to the method (so the power consumed by the house becomes more positive!) For example, if
a house currently consumes 1000 watts and morePower(200) is called then the house consumes 1200 watts. It is fine
for the morePower method to be given a negative value as argument, which means the house then just consumes less
power. For example, if a house currently consumes 1000 watts and morePower(-200) is called then the house
consumes 800 watts. However, a house cannot generate power, so the amount of power consumed by the house must
always be positive or zero, never negative. If the argument given to the morePower method is too negative and would
change the house into a generator of power, then instead the amount of power consumed by the house must not
change and the morePower method must throw a NotAPowerGeneratorException with the message “A
house cannot generate XXX watts of power”, where XXX is replaced with the amount of power that the
house would generate if the house were wrongly allowed to become a power generator. For example, if a house
currently consumes 1000 watts and morePower(-1200) is called then the house still consumes 1000 watts and the
method throws a NotAPowerGeneratorException with the message “A house cannot generate 200
watts of power”.
Change other classes and interfaces as necessary.
Make sure you test your new House class.
Question 4
Add a class SolarHouse that extends House. The constructor of the SolarHouse class takes as arguments the
name of the solar house’s owner and the amount of power consumed by the solar house. The SolarHouse class does
not have any instance variable.
The morePower method of the SolarHouse class increases the amount of power consumed by the house by the
amount of power given as argument to the method (so the power consumed by the house becomes more positive!) A
solar house can generate power using its solar panels, so the amount of power consumed by the house can become
negative without throwing any exception: a negative power consumption just means that the solar panels of the house
are currently generating more power than the rest of the house is consuming.
Change other classes and interfaces as necessary.
Make sure you test your new SolarHouse class.
Question 5
Add an ElectricityCompany class with the following UML specification:
+--------------------------------------------+
| ElectricityCompany |
+--------------------------------------------+
| - name: String |
| - consumers: ArrayList |
+--------------------------------------------+
| + ElectricityCompany(String name) |
| + addConsumer(Consumer consumer): void |
| + totalConsumption(): int |
| + getPower(String name): int || + morePower(String name, int amount): void |
| + testElectricityCompany(): void |
+--------------------------------------------+
When an electricity company is created, it has an arraylist of electricity consumers but the arraylist is empty (the
arraylist does not contain any electricity consumer).
The addConsumer method takes an electricity consumer as argument and adds the consumer to the arraylist of
consumers for the electricity company.
The totalConsumption method returns as result the total amount of power consumed by all the consumers of the
electricity company (if the result is negative then it means that the power plants of the electricity company generate
more power than the houses need and the electricity company can then sell some power to other electricity companies;
if the result is positive then it means that the houses consume more electricity than the power plants generate and the
electricity company must then buy some power from other electricity companies; if the result is zero then it means that
the power plants of the electricity company generate exactly enough powers for all the houses).
The getPower method takes as argument the name of an electricity consumer and returns as result the amount of
electric power currently consumed by this consumer. If the electricity company does not have a consumer with the
correct name then the getPower method must throw an UnknownConsumerException with the message
"Consumer XXX unknown", where XXX is replaced with the name of the consumer.
The morePower method takes as argument the name of an electricity consumer and an amount of electric power and
changes the amount of power currently consumed by that consumer. If the electricity company does not have a
consumer with the correct name then the morePower method must throw an UnknownConsumerException with
the message "Consumer XXX unknown", where XXX is replaced with the name of the consumer.
Note: the morePower method does not catch any exception, it only throws exceptions.
Make sure you test your new ElectricityCompany class.
Question 6
In this question and the next one we want to create a command line interface (CLI) for our electricity company software.
Add a CLI class with a main method. Your code then has two classes with a main method: the Test class that you
can use to run all your tests for all your classes, and the CLI class that you will now use to run the interactive text-based
interface of your program.
The CLI class does not have any testCLI method because this class is only used to allow users to use the software
interactively.
Add to the CLI class a private static input instance variable which is a Scanner object that reads input from the
standard input stream System.in:
private static Scanner input = new Scanner(System.in);
Always use this input scanner object when you need to read input. (Never close this scanner object, because this
would also close the standard input stream System.in, and then the next time you tried to read something from the
standard input stream you would get a NoSuchElementException!)In addition to the main method and the input instance variable, the CLI class has two methods called readLine
and readPosInt.
The readLine method is static and private, it takes a string as argument, and returns another string as result. The
readPosInt method is static and private, it takes a string as argument, and returns a positive integer as result.
The readLine method uses System.out.print (not println) to print its string argument on the screen (later
when we use the readLine method, the string argument of the method will be a message telling the user to type
some text). Then the readLine method uses the input scanner object to read a whole line of text from the user of
the program and returns the text as result.
The readPosInt method uses System.out.print (not println) to print its string argument on the screen (later
when we use the readPosInt method, the string argument of the method will be a message telling the user to type some
integer). Then the readPosInt method uses the input scanner object to read an integer from the user of the
program.
After reading the integer, the readPosInt method must also use the scanner’s nextLine method to read the single
newline character that comes from the user pressing the Enter key on the keyboard after typing the integer (if you do
not read this newline character using the nextLine method inside the readPosInt method, then the newline
character will remain in the input stream, and, the next time you use the readLine method described above, the
readLine method will just immediately read only the newline character from the input stream and return an empty
string as result, without waiting for the user to type anything!)
If the user types something which is not an integer, then the nextInt method of the scanner will throw an
InputMismatchException. In that case the code of your readPosInt method must catch the exception, use
System.out.println to print the error message "You must type an integer!" to the user (use
System.out.println for this, not System.err.println, otherwise you might hit a bug in Eclipse...), use the
scanner’s nextLine method to read (and ignore) the wrong input typed by the user of the program (if you do not do
this, the wrong input typed by the user will remain in the input stream, and the next time you call the nextInt method
again, you will get an InputMismatchException again!), and then do the whole thing again (including printing
again the string argument of the readPosInt method) to try to read an integer again (hint: put the whole code of the
method inside a while loop).
After reading the integer and the newline character (which is just ignored), the readPosInt method tests the integer.
If the integer is bigger than or equal to zero, then the readPosInt method returns the integer as result. If the integer
is strictly less than zero, then the readPosInt method uses System.out.println to print the error message
"Positive integers only!" to the user (use System.out.println for this, not System.err.println,
otherwise you might hit a bug in Eclipse...), and then does the whole thing again (including printing again the string
argument of the readPosInt method) to try to read an integer again (hint: just print the error message, and then the
while loop you already have around the whole code will automatically do the whole thing again...)
For example, if you want to check that your two methods readLine and readPosInt work correctly, put the
following code in the main method of your CLI class:
public static void main(String[] args) {
String str1 = readLine("Type some text: ");
System.out.println("Text read is: " + str1);
int i = readPosInt("Type an integer: ");
System.out.println("Integer read is: " + i);
String str2 = readLine("Type some text again: ");System.out.println("Text read is: " + str2);
}
then running the main method of the CLI class should look like this (where aaaa bbbb, cccc, dddd eeee, -100,
-200, 1234, and ffff gggg are inputs typed by the user on the keyboard):
Type some text: aaaa bbbb
Text read is: aaaa bbbb
Type an integer: cccc
You must type an integer!
Type an integer: dddd eeee
You must type an integer!
Type an integer: -100
Positive integers only!
Type an integer: -200
Positive integers only!
Type an integer: 1234
Integer read is: 1234
Type some text again: ffff gggg
Text read is: ffff gggg
Question 7
Once you have checked that your methods readLine and readPosInt work correctly, remove all the code inside
the main method of the CLI class so that the main method is empty again.
In the rest of this question, use the readLine and readPosInt methods every time your program needs to read a
string or an integer from the user.
In the empty main method of the CLI class, create a single ElectricityCompany object with the name "UIC
Electric". The main method of the CLI class must then print a menu that allows the user of your software to do six
different actions that involve the electricity company object, and your program must then read an integer from the user
that indicates which action must be performed by the program (see below for the details of each action). Use the
readPosInt method to print the menu (give the string for the menu as the argument of readPosInt) and to read
the integer typed by the user.
For example, the menu should look like this:
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
The user then types an integer between 1 and 6 to select the action.
For example (where 3 is an input from the user):
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
and your program then performs the selected action.
After an action has been performed by your program, your program must again print the menu and ask again the user of
the program for the next action to perform (hint: put the whole code of the main method inside a while loop, except
for the one line of code that creates the single electricity company object).
If the user types an integer which is not between 1 and 6, then your program must print an error message "Unknown
action!" to the user (hint: when testing the integer for the action, use the default case of a switch statement)
and then print the menu again (by just going back to the beginning of the while loop).For example (where 7 is an input from the user):
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 7
Unknown action!
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
If the user types something which is not an integer, the readPosInt method that you implemented in the previous
question will automatically repeat the menu and ask the user to type an integer again until the user actually types an
integer, so you do not have to worry about this in the code of the main method of your CLI class.
For example (where aaaa and bbbb cccc are inputs from the user):
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): aaaa
You must type an integer!
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): bbbb cccc
You must type an integer!
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
Here are the detailed explanations for each action.
Action 1: printing the total amount of power consumed.
When the user of the software specifies action 1, your program must simply print on the screen the total amount of
power currently consumed by all the consumers of the electricity company. Then your program goes back to printing the
menu of actions (by just going back to the beginning of the while loop).
For example (where 1 is an input from the user):
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 1
Total amount of power consumed: 2000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
Action 2: adding a new consumer to the electricity company.
When the user of the software specifies action 2, your program must add a new consumer to the electricity company. To
add a new consumer, your program needs to ask the user three things: the type of consumer (an integer read using
readPosInt: the integer 1 represents a power plant, the integer 2 represents a house, the integer 3 represents a
solar house, and any other integer must result in an error message "Unknown type of consumer!" being
printed and the software going immediately back to the main menu), the name of the consumer (a string read using
readLine), and the initial amount of power that the consumer generates (for a power plant) or consumes (for a house
or a solar house) when the consumer is created. You program must then create the correct consumer, add it to the
electricity company, and print an information message for the user of the software. The program then goes back to the
menu.
For example (where 1, 2, -100, 4, 2, 1, UIC PowerPlant, 5000, 1, 2, 2, Philippe, 1000, 1, 2, 3, Meunier,
2000, and 1 are inputs from the user):
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 1
Total amount of power consumed: 0
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 2
Type the consumer type (power plant:1 house:2 solar house:3): -100
Positive integers only!
Type the consumer type (power plant:1 house:2 solar house:3): 4
Unknown type of consumer!
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 2
Type the consumer type (power plant:1 house:2 solar house:3): 1
Enter the name of the consumer: UIC PowerPlantEnter the initial amount of power: 5000
Power plant "UIC PowerPlant" generating 5000 watts of power added
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 1
Total amount of power consumed: -5000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 2
Type the consumer type (power plant:1 house:2 solar house:3): 2
Enter the name of the consumer: Philippe
Enter the initial amount of power: 1000
House of "Philippe" consuming 1000 watts of power added
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 1
Total amount of power consumed: -4000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 2
Type the consumer type (power plant:1 house:2 solar house:3): 3
Enter the name of the consumer: Meunier
Enter the initial amount of power: 2000
Solar house of "Meunier" consuming 2000 watts of power added
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 1
Total amount of power consumed: -2000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
Note that the readPosInt method prevents the initial amount of power from being negative, so the constructor for
the House class will never throw a NotAPowerGeneratorException when you create a house object.
Nevertheless the code of the main method of your CLI class must handle this exception by printing the error message
"BUG! This must never happen!" and immediately terminating the program using System.exit(1). The
same applies to a solar house.
Action 3: listing the amount of power consumed by a given consumer.
When the user of the software specifies action 3, your program must ask the user to type the name of a consumer, and
the program then prints the amount of power which is currently consumed by this consumer.
For example (where 3, UIC PowerPlant, 3, Philippe, 3, and Meunier are inputs from the user):
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: UIC PowerPlant
UIC PowerPlant uses -5000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Philippe
Philippe uses 1000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Meunier
Meunier uses 2000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
If the name of the consumer is wrong (the electricity company does not have a consumer with this name) then an
UnknownConsumerException will be thrown by the ElectricityCompany object. The code of the main
method of your CLI class must catch this exception, print the error message from the exception object, and then it just
goes back to printing the menu of actions (by just going back to the beginning of the while loop).
For example (where 3 and aaaa are inputs from the user):
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: aaaa
Consumer aaaa unknown
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):Action 4: increasing the power of a given consumer.
When the user of the software specifies action 4, your program must ask the user to type the name of a consumer and
an amount of power, and the program then uses that amount of power to increase the amount of power generated or
consumed by the consumer. Then the program goes back to the main menu.
For example:
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: UIC PowerPlant
UIC PowerPlant uses -5000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 4
Enter the name of the consumer: UIC PowerPlant
Enter the amount of power: 1000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: UIC PowerPlant
UIC PowerPlant uses -6000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Philippe
Philippe uses 1000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 4
Enter the name of the consumer: Philippe
Enter the amount of power: -1000
Positive integers only!
Enter the amount of power: 1000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Philippe
Philippe uses 2000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Meunier
Meunier uses 2000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 4
Enter the name of the consumer: Meunier
Enter the amount of power: 500
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Meunier
Meunier uses 2500 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
If the name of the consumer is wrong (the electricity company does not have a consumer with this name) then an
UnknownConsumerException will be thrown by the ElectricityCompany object. The code of the main
method of your CLI class must catch this exception, print the error message from the exception object, and then it just
goes back to printing the menu of actions (by just going back to the beginning of the while loop).
For example:
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 4
Enter the name of the consumer: aaaa
Enter the amount of power: 1000
Consumer aaaa unknown
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
Note that, even if a consumer is a house, the readPosInt method prevents the typed amount of power from being
negative. This means a house will never throw a NotAPowerGeneratorException. Nevertheless the code of the
main method of your CLI class must handle this exception by printing the error message "BUG! This must
never happen!" and immediately terminating the program using System.exit(1).Action 5: decreasing the power of a given consumer.
When the user of the software specifies action 5, your program must ask the user to type the name of a consumer and
an amount of power, and the program then uses that amount of power to decrease the amount of power generated of
consumed by the consumer. Then the program goes back to the main menu.
Note: the electricity company object that you are using does not have a method to decrease power. So, in the code of
the main method of the CLI class, simulate decreasing power by simply increasing power by a negative amount! For
example, decreasing the power of a house by 500 watts is the same as increasing the power of the house by -500 watts.
For example:
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: UIC PowerPlant
UIC PowerPlant uses -6000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 5
Enter the name of the consumer: UIC PowerPlant
Enter the amount of power: 1000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: UIC PowerPlant
UIC PowerPlant uses -5000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Philippe
Philippe uses 2000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 5
Enter the name of the consumer: Philippe
Enter the amount of power: -1000
Positive integers only!
Enter the amount of power: 1000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Philippe
Philippe uses 1000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Meunier
Meunier uses 2500 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 5
Enter the name of the consumer: Meunier
Enter the amount of power: 500
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Meunier
Meunier uses 2000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
If the name of the consumer is wrong (the electricity company does not have a consumer with this name) then an
UnknownConsumerException will be thrown by the ElectricityCompany object. The code of the main
method of your CLI class must catch this exception, print the error message from the exception object, and then it just
goes back to printing the menu of actions (by just going back to the beginning of the while loop).
For example:
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 5
Enter the name of the consumer: aaaa
Enter the amount of power: 1000
Consumer aaaa unknown
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
If a consumer is a house and the amount of power typed by the user is too big then a
NotAPowerGeneratorException will be thrown by the House object. The code of the main method of your CLI class must catch this exception, print the error message from the exception object, and then it just goes back to
printing the menu of actions (by just going back to the beginning of the while loop).
For example:
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Philippe
Philippe uses 1000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 5
Enter the name of the consumer: Philippe
Enter the amount of power: 2000
A house cannot generate 1000 watts of power
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Philippe
Philippe uses 1000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: UIC PowerPlant
UIC PowerPlant uses -5000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 5
Enter the name of the consumer: UIC PowerPlant
Enter the amount of power: 10000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: UIC PowerPlant
UIC PowerPlant uses 5000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Meunier
Meunier uses 2000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 5
Enter the name of the consumer: Meunier
Enter the amount of power: 3000
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3
Enter the name of the consumer: Meunier
Meunier uses -1000 watts
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6):
Action 6: quitting the program.
When the user of the software specifies action 6, your program must print a "Goodbye!" message, and terminate the
program using: System.exit(0).
For example (where 6 is an input from the user):
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 6
Goodbye!
Here is a more complete example of running the software:
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): aaaa
You must type an integer!
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): bbbb cccc
You must type an integer!
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): -100
Positive integers only!
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 7
Unknown action!
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 1
Total amount of power consumed: 0
Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 2
Type the c