Questions
IN JAVA PLEASE!!! Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior....

IN JAVA PLEASE!!!

Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input.

(1) Create an ItemToPurchase class per the following specifications:

  • Private fields
  • Create a default constructor
    • string itemName - Initialized in default constructor to "none"
    • float itemPrice - Initialized in default constructor to 0.0
    • int itemQuanity - Initialized in default constructor to 0
    • string itemDescription - Initialized in default constructor to "none"
  • Parameterized constructor to assign item name, item description, item price, and item quantity
  • Public member methods
    • setDescription() mutator & getDescription() accessor
    • setName() mutator & getName() accessor
    • setQuantity() mutator & getQuantity() accessor
    • setPrice() mutator & getPrice() accessor
    • printItemCost() - Outputs the item name followed by the quantity, price, and subtotal
    • printItemDescription() - Outputs the item name and description

Ex. of printItemCost() output:

Bottled Water 10 @ $1 = $10

Ex. of printItemDescription() output:

Bottled Water: Deer Park, 12 oz.

(2) Create two new files:

  • ShoppingCart.java - Class definition
  • ShoppingCartManager.java - Contains main() method

Build the ShoppingCart class with the following specifications. Note: Some can be method stubs (empty methods) initially, to be completed in later steps.

  • Private fields

  • String customerName - Initialized in default constructor to "none"

  • String currentDate - Initialized in default constructor to "January 1, 2016"

  • ArrayList cartItems

  • Default constructor

  • Parameterized constructor which takes the customer name and date as parameters

  • Public member methods

  • getCustomerName() accessor

  • getDate() accessor

  • addItem()
    • Adds an item to cartItems array. Has parameter ItemToPurchase. Does not return anything.
  • removeItem()
    • Removes item from cartItems array. Has a string (an item's name) parameter. Does not return anything.
    • If item name cannot be found, output this message: Item not found in cart. Nothing removed.
  • modifyItem()
    • Modifies an item's description, price, and/or quantity. Has parameter ItemToPurchase. Does not return anything.
    • If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify item in cart.
    • If item cannot be found (by name) in cart, output this message: Item not found in cart. Nothing modified.
  • getNumItemsInCart()
    • Returns quantity of all items in cart. Has no parameters.
  • getCostOfCart()
    • Determines and returns the total cost of items in cart. Has no parameters.
  • printTotal()
    • Outputs total of objects in cart.
    • If cart is empty, output this message: SHOPPING CART IS EMPTY
  • printDescriptions()
    • Outputs each item's description.

Ex. of printTotal() output:

John Doe's Shopping Cart - February 1, 2016
Number of Items: 8

Nike Romaleos 2 @ $189 = $378
Chocolate Chips 5 @ $3 = $15
Powerbeats 2 Headphones 1 @ $128 = $128

Total: $521

Ex. of printDescriptions() output:

John Doe's Shopping Cart - February 1, 2016

Item Descriptions
Nike Romaleos: Volt color, Weightlifting shoes
Chocolate Chips: Semi-sweet
Powerbeats 2 Headphones: Bluetooth headphones

(3) In main(), prompt the user for a customer's name and today's date. Output the name and date. Create an object of type ShoppingCart.
Ex.

Enter Customer's Name:
John Doe
Enter Today's Date:
February 1, 2016

Customer Name: John Doe
Today's Date: February 1, 2016

(4) Implement the printMenu() method. printMenu() has a ShoppingCart parameter, and outputs a menu of options to manipulate the shopping cart. Each option is represented by a single character. Build and output the menu within the method.

If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call printMenu() in the main() method. Continue to execute the menu until the user enters q to Quit.
Ex:

MENU
a - Add item to cart
d - Remove item from cart
c - Change item quantity
i - Output items' descriptions
o - Output shopping cart
q - Quit

Choose an option: 

(5) Implement Output shopping cart menu option.
Ex:

OUTPUT SHOPPING CART
John Doe's Shopping Cart - February 1, 2016
Number of Items: 8

Nike Romaleos 2 @ $189 = $378
Chocolate Chips 5 @ $3 = $15
Powerbeats 2 Headphones 1 @ $128 = $128

Total: $521

(6) Implement Output item's description menu option.
Ex.

OUTPUT ITEMS' DESCRIPTIONS
John Doe's Shopping Cart - February 1, 2016

Item Descriptions
Nike Romaleos: Volt color, Weightlifting shoes
Chocolate Chips: Semi-sweet
Powerbeats 2 Headphones: Bluetooth headphones

(7) Implement Add item to cart menu option.
Ex:

ADD ITEM TO CART
Enter the item name:
Nike Romaleos
Enter the item description:
Volt color, Weightlifting shoes
Enter the item price:
189
Enter the item quantity:
2

(8) Implement Remove item menu option.
Ex:

REMOVE ITEM FROM CART
Enter name of item to remove:
Chocolate Chips

(9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object and use ItemToPurchase modifiers before using modifyItem() method.
Ex:

CHANGE ITEM QUANTITY
Enter the item name:
Nike Romaleos
Enter the new quantity:
3

In: Computer Science

In details, explain the two types of software?

  1. In details, explain the two types of software?

In: Computer Science

11) How to bind property?

11) How to bind property?

In: Computer Science

Programming lang C++ Write a program that reads 10,000 words into an array of strings. The...

Programming lang C++

Write a program that reads 10,000 words into an array of strings. The program will then read a second file that contains an undetermined number of words and search the first array for each word. The program will then report the number of words in the second list that were found on the first list.

In: Computer Science

Create the database with at least 10 employees and 2 managers are populated. Important: your name...

Create the database with at least 10 employees and 2 managers are populated. Important: your name should be in the employee table.

Write a Python code that can do the following:

    1) Take an employee ID from user

    2) Display the output of the SQL, select * from employee;

Improve the Python code above that can do the following:

    1) Take an employee ID from the user. Let it be idEntered.

    2) Get the departmentID for the given employeeID, idEntered. Let it be deptFound.

    3) Check if idEntered is in the table manager

    4) If yes, then execute: query = ("select * from employee where dID = %s; "). Note that since a variable deptFound is included in SQL, if it should be included, then use %s in SQL. And then declare a variable, data_tuple = (deptFound, ) in a separate line. Finally, execute the query cursor.execute(query, data_tuple).

    5) if No, simply execute the SQL: select * from employee where eid = %s; do the similarly way for idEntered as above

In: Computer Science

The set of all strings consisting of an uppercase letter followed by zero or more additional...

The set of all strings consisting of an uppercase letter followed by zero or more additional characters, each of which is either an uppercase letter or one of the digits 0 through 9


Show the syntax diagram

In: Computer Science

Compare between malware that spread conceal in a table?

Compare between malware that spread conceal in a table?

In: Computer Science

Please write unit tests for the main method below. The unit tests must be used in...

Please write unit tests for the main method below. The unit tests must be used in MSTest for Visual Studio.

C#

//main method
public static void Main(string[] args)
{
//unsorted array
int[] dataSet = new int[5] { 2, 99, 27, 68, 3 };

//sortData method called for sorting the above unsorted array
sortData(dataSet);

//iterating the sorted array
for (int i = 0; i < dataSet.Length; i++)
{
//writing the sorted array to the console
Console.WriteLine(dataSet[i]);
}
}//end method

In: Computer Science

can someone please complete this for me? losing my mind Assignment Overview The Case Assignment in...

can someone please complete this for me? losing my mind

Assignment Overview

The Case Assignment in Module 2 will accomplish three tasks:

  • Demonstrate how to use pseudo code to help programming.
  • Use Scanner class to get user input from a keyboard (allow user interaction).
  • Demonstrate how to use class and objects (OOP concepts).

Case Assignment

Write a java program to help you calculate property tax. The program will perform the following tasks:

  1. Prompt the user to enter the property value of the house.
  2. Prompt the users for the property tax rate.
  3. Display the result.

Your task:

  1. Write pseudo code based on your analysis.
  2. Write a Java application program based on your pseudo code.

In: Computer Science

what is the network administration standards ? briefly course: Network Administration

what is the network administration standards ?
briefly
course: Network Administration

In: Computer Science

Please provide new response Virtualization technology has dramatically changed the landscape of how servers are designed,...

Please provide new response

Virtualization technology has dramatically changed the landscape of how servers are designed, secured, and administered. The hypervisor market has become commoditized due to core feature overlap among most hypervisor vendors. While there are many hypervisor options in the market today–the Big 3 are VMware (ESXi), Microsoft (Hyper-V), and Citrix (XenServer). On the basis of your understanding of Virtualization technology , create a report in a Microsoft Word document addressing the following: Compare and contrast the Big 3 hypervisor options available in the market on the basis of factors such as:

Features Licensing costs Security Support Make a recommendation to Zeus Books on which hypervisor they should use to create a high availability web server environment.

In: Computer Science

Write a Python program that allows the user to perform three operations (implemented as three functions)...

Write a Python program that allows the user to perform three operations (implemented as three functions) on a dictionary:

add_to_dict(): takes a dictionary, a key, a value and adds the <key,value> pair to the dictionary. If the key is already in the dictionary, then the program displays the error message: "Error. Key already exists.".
remove_from_dict(): takes a dictionary and key and removes the key from the dictionary. If no such key is found in the dictionary then the program prints: "Key not found."
find_key(): takes dictionary and key and returns the value associated with the key or None if not found. The program prints the value if found, else prints: "Key not found."
No printing should be done inside these three functions.

The user is presented with a menu and repeatedly offered to perform an operation until he/she quits.

Finally, a list of the key-value pairs in the dictionary is printed out.

The main program is given - do not change it.

Example 1:

Menu: 
(a)dd, (r)emove, (f)ind: a
Key: rich
Value: 1
More (y/n)? y
Menu: 
(a)dd, (r)emove, (f)ind: a
Key: alireza
Value: 2
More (y/n)? n
[('alireza', '2'), ('rich', '1')]

def main():
    more_input = True
    a_dict = {}
  
    while more_input:    
        choice = menu_selection()
        execute_selection(choice, a_dict)
        again = input("More (y/n)? ")
        more_input = again.lower() == 'y'
  
    tuple_list = dict_to_tuples(a_dict)
    print(sorted(tuple_list))

main()

In: Computer Science

What Makes a Successful Programmer

What Makes a Successful Programmer

In: Computer Science

Question(on Python). There is a Python program what could solve the simple slide puzzles problem by...

Question(on Python). There is a Python program what could solve the simple slide puzzles problem by A* algorithm. Please fill in the body of the a_star() function.

In order to solve a specific problem, the a_star function needs to know the problem's start state, the desired goal state, and a function that expands a given node. To be precise, this function receives as its input the current state and the goal state and returns a list of pairs of the form (new_state, h'-score). There is exactly one such pair for each of the possible moves in the current state, with new_state being the state resulting from that move, paired with its h'-score. Note that this is not the f'-score but the h'-score, i.e., an (optimistic) estimate of the number of moves needed to reach the goal from the current state. The expand function does not know g’and therefore cannot compute f'; this has to be done by the a_star function.

The a_star function calls the expand function (in this context, slide_expand) in order to expand a node in the search tree, i.e., obtain the states that can be reached from the current one and their h’-scores. Again, please note that these are not f’-scores but h’-scores;
a_star needs to compute the h’-scores for sorting the list of open nodes. Also, note that slide_expand does not (and cannot) check whether it is creating a search cycle, i.e., whether it generates a state that is identical to one of its ancestors; this has to be done by a_star. The given slide_expand function uses the same scoring function as discussed in class – it simply counts the number of mismatched tiles (excluding the empty tile).

Please add code to the a_star function so that slide_solver can find an optimal solution for Example #1 and, in principle, for any slide puzzle. You are not allowed to modify any code outside of the a_star function. Hints: It is best to not use recursion in a_star but rather a loop that expands the next node, prevents any cycles in the search tree, sorts the list of open nodes by their scores, etc., until it finds a solution or determines that there is no solution. It is also a good idea to keep a list of ancestors for every node on the list, i.e., the list of states from the start that the algorithm went through in order to reach this node. When a goal state is reached, this list of ancestors for this node can be returned as the solution.

A_Star.py

import numpy as np

example_1_start = np.array([[2, 8, 3],
                           [1, 6, 4],
                           [7, 0, 5]])

example_1_goal = np.array([[1, 2, 3],
                           [8, 0, 4],
                           [7, 6, 5]])
 
example_2_start = np.array([[ 2,  6,  4,  8],
                            [ 5, 11,  3, 12],
                            [ 7,  0,  1, 15],
                            [10,  9, 13, 14]])

example_2_goal = np.array([[ 1,  2,  3,  4],
                           [ 5,  6,  7,  8],
                           [ 9, 10, 11, 12],
                           [13, 14, 15,  0]])

# For a given current state, move, and goal, compute the new state and its h'-score and return them as a pair. 
def make_node(state, row_from, col_from, row_to, col_to, goal):
    # Create the new state that results from playing the current move. 
    (height, width) = state.shape
    new_state = np.copy(state)
    new_state[row_to, col_to] = new_state[row_from, col_from]
    new_state[row_from, col_from] = 0
    
    # Count the mismatched numbers and use this value as the h'-score (estimated number of moves needed to reach the goal).
    mismatch_count = 0
    for i in range(height):
        for j in range(width):
            if new_state[i ,j] > 0 and new_state[i, j] != goal[i, j]:
                mismatch_count += 1
   
    return (new_state, mismatch_count)

# For given current state and goal state, create all states that can be reached from the current state
# (i.e., expand the current node in the search tree) and return a list that contains a pair (state, h'-score)
# for each of these states.   
def slide_expand(state, goal):
    node_list = []
    (height, width) = state.shape
    (empty_row, empty_col) = np.argwhere(state == 0)[0]     # Find the position of the empty tile
    
    # Based on the positin of the empty tile, find all possible moves and add a pair (new_state, h'-score)
    # for each of them.
    if empty_row > 0:
        node_list.append(make_node(state, empty_row - 1, empty_col, empty_row, empty_col, goal))
    if empty_row < height - 1:
        node_list.append(make_node(state, empty_row + 1, empty_col, empty_row, empty_col, goal))
    if empty_col > 0:
        node_list.append(make_node(state, empty_row, empty_col - 1, empty_row, empty_col, goal))
    if empty_col < width - 1:
        node_list.append(make_node(state, empty_row, empty_col + 1, empty_row, empty_col, goal))
    
    return node_list
  
# TO DO: Return either the solution as a list of states from start to goal or [] if there is no solution.               
def a_star(start, goal, expand):
    return []

# Find and print a solution for a given slide puzzle, i.e., the states we need to go through 
# in order to get from the start state to the goal state.
def slide_solver(start, goal):
    solution = a_star(start, goal, slide_expand)
    if not solution:
        print('This puzzle has no solution. Please stop trying to fool me.')
        return
        
    (height, width) = start.shape
    if height * width >= 10:            # If numbers can have two digits, more space is needed for printing
        digits = 2
    else:
        digits = 1
    horizLine = ('+' + '-' * (digits + 2)) * width + '+'
    for step in range(len(solution)):
        state = solution[step]
        for row in range(height):
            print(horizLine)
            for col in range(width):
                print('| %*d'%(digits, state[row, col]), end=' ')
            print('|')
        print(horizLine)
        if step < len(solution) - 1:
            space = ' ' * (width * (digits + 3) // 2)
            print(space + '|')
            print(space + 'V')

slide_solver(example_1_start, example_1_goal)       # Find solution to example_1

In: Computer Science

Give an O(lg n)-time EREW algorithm that determines for each object in an n-object list whether...

Give an O(lg n)-time EREW algorithm that determines for each object in an n-object list whether it is the middle (n/2

th) object.

In: Computer Science