Question

In: Advanced Math

Implementation in CLIPS programming language for the following problem Acme Electronics makes a device called the...

Implementation in CLIPS programming language for the following problem

Acme Electronics makes a device called the Thing 2000. This device is available in five different models distinguished by the chassis. Each chassis provides a number of bays for optional gizmos and is capable of generating a certain amount of power. The following table sumarizes the chassis attributes:

Chassis --------- Gizmo Bays provided --- Power Provided----- Price($)
C100--------------------------- 1--------------------------- 4------------------ 2000
C200------------------------- 2 -------------------------- 5------------------ 2500
C300--------------------------- 3---------------------------7 ------------------3000
C400---------------------------2----------------------------8------------------ 3000
C500-------------------------- 4 ---------------------------9 ------------------3500

Each gizmo that can be installed in the chassis requires a certain amount of power to operate. The following table summarizes the gizmo attributes

Gizmo-------------------- Power Used --------------------Price($)

Zaptron ------------------------ 2 ------------------------------100
Yatmizer ----------------------- 6------------------------------ 800
Phenerator--------------------- 1 ------------------------------300
Malcifier----------------------- 3 ------------------------------200
Zeta-shield------------------- 4 ------------------------------150
Warnosynchronizer---------- 2 -------------------------------50
Dynoseparator---------------- 3 ------------------------------400

Given as input facts representing the chassis and any gizmos that have been selected, write a program that generates facts representing the number of gizmos used, the total amount of power required for the gizmo, and the total price of the chassis and all gizmos selected

Solutions

Expert Solution

Answer:-

Here is a menu driven program that inputs the chasis type and the gizmaos and then calculates the total power and price.

If an invalid configuration (excessive power draw or insufficient gizmo bays) is detected then an appropriate error message is displayed.

import java.util.*;

class Acme {
public static void main(String args[]) {

Scanner sc = new Scanner(System.in);
int cost = 0;
int powerAvailable = 0;
int gizmosAvailable = 0;
int gizmosUsed = 0;
int powerUsed = 0;

while (true) {
System.out.println("Select a chassis: ");
System.out.println("\tName\tBays\tPower\tPrice\t");
System.out.println("1\tC100\t1\t4\t$2000");
System.out.println("2\tC200\t2\t5\t$2500");
System.out.println("3\tC300\t3\t7\t$3000");
System.out.println("4\tC400\t2\t8\t$3000");
System.out.println("5\tC500\t4\t9\t$3500");
System.out.print("Enter your choice: ");

int ch = sc.nextInt();

if (ch < 1 || ch > 5) {
System.out.println("Invalid selection");
continue;
} else {
switch (ch) {
case 1:
cost += 2000;
gizmosAvailable += 1;
powerAvailable += 4;
break;
case 2:
gizmosAvailable += 2;
powerAvailable += 5;
cost += 2500;
break;
case 3:
gizmosAvailable += 3;
powerAvailable += 7;
cost += 3000;
break;
case 4:
gizmosAvailable += 2;
powerAvailable += 8;
cost += 3000;
break;
case 5:
gizmosAvailable += 4;
powerAvailable += 9;
cost += 3500;
break;
}
break;
}
}

System.out.println("Enter your gizmos: ");
while (true) {
System.out.println("No. \tName\tPower\tPrice");
System.out.println("1\tZaptron\t2\t$100");
System.out.println("2\tYatmizer\t6\t$800");
System.out.println("3\tPhenerator\t1\t$300");
System.out.println("4\tMalcifer\t3\t$200");
System.out.println("5\tZeta-shield\t4\t$150");
System.out.println("6\tWarnosynchronizer\t2\t$50");
System.out.println("7\tDynoseparator\t3\t$400");

while (true) {
System.out.print("Enter your choice: ");
int ch = sc.nextInt();
if (ch < 1 || ch > 7) {
System.out.println("Invalid choice");
continue;
} else {
switch (ch) {
case 1:
gizmosUsed++;
powerUsed += 2;
cost += 100;
break;
case 2:
gizmosUsed++;
powerUsed += 6;
cost += 800;
break;
case 3:
gizmosUsed++;
powerUsed += 1;
cost += 300;
break;
case 4:
gizmosUsed++;
powerUsed += 3;
cost += 200;
break;
case 5:
gizmosUsed++;
powerUsed += 4;
cost += 150;
break;
case 6:
gizmosUsed++;
powerUsed += 2;
cost += 50;
break;
case 7:
gizmosUsed++;
powerUsed += 3;
cost += 400;
break;
}
break;
}

}

System.out.print("Add another? (y/n) ");
sc.skip("\n");
String s = sc.nextLine();
if (s.equals("y")) continue;
else break;
}

if (gizmosUsed > gizmosAvailable) {
System.out.println("Invalid configuration!");
System.out.println("Not enough gizmo slots!");
return;
}

if (powerUsed > powerAvailable) {
System.out.println("Invalid configuration!");
System.out.println("Not enough power!");
return;
}

System.out.printf("Total number of gizmos: %d\n", gizmosUsed);
System.out.printf("Total power used: %d\n", powerUsed);
System.out.printf("Total cost: $%d.00\n", cost);
  
}
}


Related Solutions

LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
Choose a problem that lends to an implementation that uses dynamic programming. Clearly state the problem...
Choose a problem that lends to an implementation that uses dynamic programming. Clearly state the problem and then provide high-level pseudocode for the algorithm. Explain why this algorithm can benefit from dynamic programming.
Java programming language should be used Implement a class called Voter. This class includes the following:...
Java programming language should be used Implement a class called Voter. This class includes the following: a name field, of type String. An id field, of type integer. A method String setName(String) that stores its input into the name attribute, and returns the name that was just assigned. A method int setID(int) that stores its input into the id attribute, and returns the id number that was just assigned. A method String getName() that return the name attribute. A method...
Scheme is a dialect of a programming language called Lisp, which was developed at MIT in...
Scheme is a dialect of a programming language called Lisp, which was developed at MIT in 1959. Alice 1.0 was released in 2006 from CMU, and Python in 1994. Based on what you know of the Scheme language, describe the major differences between how it works and how Alice or Python works. What advantages might Scheme have over Alice/Python? What advantages might Alice/Python have over Scheme?
Acme Electronics makes calculators. Consumer satisfaction is one the top priorities of the company’s management. The...
Acme Electronics makes calculators. Consumer satisfaction is one the top priorities of the company’s management. The company guarantees a refund or a replacement for any calculator that malfunctions within 2 years from the date of purchase. It is known from past data that despite all efforts, 5% of the calculators manufactured by Acme Electronics malfunction within a 2-year period. The company mailed a package of 10 randomly selected calculators to a store. a. Let x denote the number of calculators...
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that...
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that will use a while loop. The function will prompt the user to enter integers ine by one, until the user enters a negative value to stop. The function will display any integer that is less than 25. Declare and initialize any variables needed. The function takes no arguments and has a void return type.
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
In the R programming language, we would like to use the data set called iris to...
In the R programming language, we would like to use the data set called iris to build a simple linear regression model to predict Sepal.Length based on Petal.Length. Calculate the least squares regression line to predict Sepal.Length based on Petal.Length. Interpret the slope of the line in the context of the problem. Remember that both variables are measured in centimeters. Plot the regression line in a scatterplot of Sepal.Length vs. Petal.Length. Test H1: ??1 ≠ 0 at ?? = 0.05...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1- Leaf: that implements turn(), which changes the color of the Leaf object and returns true. If for any reason it is unable to change color, it should return false (you can come up with a reason for failure). The new color can be determined at random. 2- Document: that implements turn(), which changes the page on the document to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT