Questions
"""    CS 125 - Intro to Computer Science    File Name: CS125_Lab1.py    Python Programming...

"""
   CS 125 - Intro to Computer Science
   File Name: CS125_Lab1.py
   Python Programming
   Lab 1

   Name 1: FirstName1 LastName1
   Name 2: FirstName2 LastName2
   Description: This file contains the Python source code for deal or no deal.
"""

class CS125_Lab1():
def __init__(self):
# Welcome user to game
print("Let's play DEAL OR NO DEAL")
  
# Define instance variables and init board
self.cashPrizes = [.01, .50, 1, 5, 10, 50, 100, 250, 500, 1000, 5000, 10000, 100000, 500000, 1000000]
self.remainingPrizesBoard = []
self.gameOver = False
self.offerHistory = []
self.initializeRandomPrizeBoard()


"""----------------------------------------------------------------------------
Prints the locations available to choose from
(0 through numRemainingPrizes-1)
----------------------------------------------------------------------------"""
def printRemainingPrizeBoard(self):
# Copies remaining prizes ArrayList into prizes ArrayList (a temp ArrayList)
prizes = []
for prize in self.remainingPrizesBoard:
prizes.append(prize)
  
prizes.sort()
  
# TODO 1: Print the prizes in the prize ArrayList. All values should be on
# a single line (put a few spaces after each prize) and add a new line
# at the end (simple for loop);
  
# NOTE: '${:,.2f}'.format(num) is the python
# equivalent to the Java df.format(num) DecimalFormat class, which allows
# you to print a decimal num like 5.6 as $5.60.

  
"""----------------------------------------------------------------------------
Generates the banks offer. The banker algorithm computes the average
value of the remaining prizes and then offers 85% of the average.
----------------------------------------------------------------------------"""
def getBankerOffer(self):
pass
# TODO 2: Write code which returns the banker's offer as a double,
# according to the description in this method's comment above.

#----------------------------------------------------------------------------
# Takes in the selected door number and processes the result
#----------------------------------------------------------------------------
def chooseDoor(self, door):
# TODO 6: Add the current bank offer (remember, we have a method
# for to obtain the current bank offer - call self.getBankerOffer())
# to the our offerHistory.
if door == -1:
pass
# This block is executed when the player accepts the banker's offer. Thus the game is over.
  
# TODO 3: Set the gameOver variable to true
# Inform the user that the game is over and how much money they accepted from the banker.
# Print the offer history (there is a method to call for this).
else:
pass
# This block is executed when the player selects one of the remaining doors.
  
# TODO 4: Obtain the prize behind the proper door and remove the prize from the board
# Print out which door the user selected and what prize was behind it (this prize is now gone)

         
# If only one prize remaining, game is over!!!
if len(self.remainingPrizesBoard) == 1:
pass
# This block is executed when there is only one more prize remaining...so it is what they win!
  
# TODO 5: Set the gameIsOver variable to true
# Let the user know what prize they won behind the final door!
# Print the offer history (there is a method to call for this).


"""----------------------------------------------------------------------------
This method is called when the game is over, and thus takes as a
parameter the prize that was accepted (either from the banker's offer
or the final door).
  
Prints out the offers made by the banker in chronological order.
Then, prints out the money left on the table (for example, if the
largest offer from the banker was $250,000, and you ended up winning
$1,000, whether from a later banker offer or from the last door,
then you "left $249,000 on the table).
----------------------------------------------------------------------------"""
def printOfferHistory(self, acceptedPrize):
# Print out the history of offers from the banker
  
# TODO 7: Print out the banker offer history (will need to loop through
# your offerHistory member variable) and find the max offer made.
# Print one offer per line, like:
# Offer 1: $10.00
# Offer 2: $5.00
# .....
maxOffer = 0
print("\n\n\n***BANKER HISTORY***")
  
# TODO 8: If the max offer was greater than the accepted prize, then print out
# the $$$ left out on the table (see the example in this method's header above).
# Otherwise, congratulate the user that they won more than the banker's max
# offer and display the banker's max offer.

"""
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////DO NOT EDIT ANY PORTIONS OF METHODS BELOW///////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
"""
  
"""----------------------------------------------------------------------------
Processes all the code needed to execute a single turn of the game
----------------------------------------------------------------------------"""
def playNextTurn(self):
print("-----------------------------------------------------------------------")
  
# Print out remaining prizes
print("There are " + str(len(self.remainingPrizesBoard)) + " prizes remaining, listed in ascending order: ")
self.printRemainingPrizeBoard()
  
# Display all prize doors
print("\nThe prizes have been dispersed randomly behind the following doors:")
for i in range(0, len(self.remainingPrizesBoard)):
print(str(i), end=" ")
print("")
  
# Print out banker's offer and ask user what to do
print("\nThe banker would like to make you an offer of...................." + '${:,.2f}'.format(self.getBankerOffer()))
print("")      
  
# Get selection from user and choose door
promptStr = "What would you like to do? Enter '-1' to accept the banker's offer, " + "or select one of the doors above (0-" + (str(len(self.remainingPrizesBoard)-1)) + "): "
selectedDoorNum = int(input(promptStr))
if selectedDoorNum >= -1 and selectedDoorNum < len(self.remainingPrizesBoard): # Make sure valid sel.
self.chooseDoor(selectedDoorNum)
else:
print(str(selectedDoorNum) + " is not a valid selection.")
print("")
print("")


'''----------------------------------------------------------------------------
Basically, a getter method for the gameIsOver method. The client
will continually call playNextTurn() until gameIsOver() evaluates
to true.
----------------------------------------------------------------------------'''
def gameIsOver(self):
return self.gameOver


'''----------------------------------------------------------------------------
Copies the constant prizes (from an array) into a temporary array
and uses that array to populate the initial board into the member
variable 'remainingPrizesBoard'.
----------------------------------------------------------------------------'''
def initializeRandomPrizeBoard(self):
# Start with a fresh board with nothing in it
self.remainingPrizesBoard = []
  
# Copies cashPrizes array into prizes ArrayList (a temp ArrayList)
prizes = []
  
for prize in self.cashPrizes:
prizes.append(prize)
  
# Randomizes prizes into remainingPrizesBoard
while len(prizes) > 0:
from random import randint
i = randint(0, len(prizes)-1)
self.remainingPrizesBoard.append(prizes[i]) # Copy into our "board"
del prizes[i]
          
# Debug print which will show the random board contents
#for p in self.remainingPrizesBoard:
# print('${:,.2f}'.format(p), end=" -- ")
#print("")

In: Computer Science

Write a JAVA program that generates three random numbers from 1 to 6, simulating a role...

Write a JAVA program that generates three random numbers from 1 to 6, simulating a role of three dice. It will then add, subtract and multiply these two numbers. It will also take the first number to the power of the second and that result to the power of the third. Display the results for each calculation. Please note that the sample run is based on randomly generated numbers so your results will be different.

Sample run:

6 + 2 + 5 = 13

6 - 2 – 5 = -1

6 * 2 * 5 = 60

6 to the power of 2 to the power of 5 = 60,466,176

A second sample run:

2 + 3 + 5 = 10

2 – 3 - 5 = -6

2 * 3 * 5 = 30

2 to the power of 3 to the power of 5 = 32,768

In: Computer Science

JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a...

JAVASCRIPT: -
Please create an object (grade) with 10 names and 10 grades.
- Create a method (inputGrade) that can put a name and a grade to the grade object.
- Create another method (showAlltheGrades) to show all the grade in that object.
- Create the third method (MaxGrade) that can display the maximum grade and the student name.
- Using “prompt” and inputGrade method input 10 student names and their grades.
- Display all the grades and names by using showAlltheGrades method.
NOTE: Make sure to use the push() method when adding elements to the arrays. Please post the code and a screenshot of the output. Thanks!

[Reference JavaScript code]
<html>
<body>
<script>
// Declare a class
class Student {
// initialize an object
constructor(grade, name) {
this.grade=grade;
this.name=name; }
//Declare a method
detail() {
document.writeln(this.grade + " " +this.name)
}//detail
}//class
var student1=new Student(1234, "John Brown");
var student2=new Student(2222, "Mary Smith");
student1.detail();//call a method
student2.detail();
</script>
</body>
</html>

In: Computer Science

Determine the subnet mask for the following IP addresses. Please show your work how you got...

Determine the subnet mask for the following IP addresses. Please show your work how you got the answer so i can understand how to do it.

10.55.64.8 need 80 subnets

192.168.1.x /26 – subnet mask

172.16.10.2 / 18 – subnet mask

172.16.10.4 / 20- subnet mask

In: Computer Science

A department employs up to thirty employees, but an employee is employed by one department. For...

A department employs up to thirty employees, but an employee is employed by one department. For each employee you need to store unique employee Id, name, address and salary. Departments are identified by department Id and also have a name. Some employees are not assigned to any department. A division operates many departments, but each department is operated by one division. An employee may be assigned at the most three projects, and a project may have at the most six employees assigned to it. A project may have at least one employee assigned to it. Each project is identified by unique name and has a budget. A project can be related to other projects. There can be many related projects. One of the employees manages each department, and each department is managed by only one employee. One of the employees runs each division, and each division is run by only one employee. For each division, store unique Id and name.

REQUIRED:

a) Design a conceptual diagram from the above information.                     

b) Develop a logical data model for the database.                                      

c) Explain the importance of data modelling.                                                

In: Computer Science

Show that the external path length epl in a 2-tree with m external nodes satisfies epl≤...

Show that the external path length epl in a 2-tree with m external nodes satisfies epl≤ (1/2)(m^2+m−2). Conclude that epl≤ (1/2n)(n+ 3) for a 2-tree with n internal nodes.

In: Computer Science

In Java. Create a class called FileSumWrapper with a method that has the signature public static...

In Java.

Create a class called FileSumWrapper with a method that has the signature

public static void handle(String filename, int lowerBound)

Make this method call FileSum.read and make your method catch all the errors.

FileSum.read is a method that takes a filename and a lower bound, then sums up all the numbers in that file that are equal to or above the given lower bound.

FileSum :

import java.io.File;
import java.rmi.UnexpectedException;
import java.util.Scanner;

public class FileSum {

    public static int read(String filename, int lowerBound) throws Exception {
        Scanner inputFile = new Scanner(new File(filename));

        int acc = 0;
        boolean atLeastOneFound = false;
        while (inputFile.hasNext()) {
            int data = inputFile.nextInt();
            if (data >= lowerBound) {
                acc += data;
                atLeastOneFound = true;
            }
        }

        if (!atLeastOneFound) {
            throw new UnexpectedException("");
        }

        return acc;
    }

}

Question1:

import java.util.Scanner;

public class Question1 {

    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter a filename");
        String filename = keyboard.nextLine();
        System.out.println("Enter a lower bound");
        int lowerBound = keyboard.nextInt();

        FileSumWrapper.handle(filename, lowerBound);
    }
}

err.txt :

50 40 30
90
85
23
06
30x
54
675
875
34
2323
423
423
5
5
79
97
90y
7986
5
46
64656
66
6
333 93 9 300 20 2 9 209 290 39 48 85 7847 578048

t1.txt:

50 40 30
90
85
23
06
30x
54
675
875
34
2323
423
423
5
5
79
97
90y
7986
5
46
64656
66
6
333 93 9 300 20 2 9 209 290 39 48 85 7847 578048

Here is the input :

t1.txt
50

output:

Enter a filename\n
Enter a lower bound\n
Sum of all numbers in t1.txt is 665177\n

In: Computer Science

Write, test, and debug (if necessary) HTML file with the Javascript codes in an external file...

Write, test, and debug (if necessary) HTML file with the Javascript codes in an external file for the following problem:

Input: a number, n, using prompt, which is the number of the factorial numbers to be displayed.

Output: a bordered table of numbers with proper caption and headings in which the first column displays the numbers from 1 to n and the second column displays the first n factorial numbers.

For example, if a user enters 10 to be the value of n, the first column will include 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and the second column will include 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800.

Your Javascript codes must include a function to compute the factorial number given an input number. This function is to be called to generate corresponding factorial number for each number in the first column of the table. You must use document.write to produce the desired output. Use the external CSS document for the display of the table.

In: Computer Science

There are four tables in the database. 1. students (sno, sname, sgender, sbirthday, class) - sno:...

There are four tables in the database.

1. students (sno, sname, sgender, sbirthday, class)

- sno: student number

- sname: student name

- sgender: male or female

- sbirthday: date of birth

- class: class number

- primary key: sno

2. courses (cno, cname, tno)

- cno: course number

- cname: course name

- tno: teacher number

- primary key, cno, tno

3. scores (sno, cno, grade)

- sno: student number

- cno: course number

- grade: grade

- primary key, sno, cno

4. teachers (tno, tname, tgender, tbirthday, title, department)

- tno: teacher number

- tname: teacher name

- tgender: teacher gender

- tbirthday: date of birth

- title: title of the teacher, e.g. professor, lecture, or TA

- department: department name, e.g. CS, EE.

Question 1: In the score table, find the student number that has all the grades in between 90 and 70.

Question 2: For all the courses that took by class 15033, calculate the average grade.

Question 3: Find the class number that has at least two male students.

Question 4: Find the teacher's name in CS and EE department, where they have different title. Return both name and title.

Question 5: Find the students, who took the course number "3-105" and have earned a grade, at least, higher than the students who took "3- 245" course. Return the results in a descending order of grade.

Question 6: Find the students, who took more than 1 course, and return the students' names that is not the one with highest grade.

Question 7: For each course, find the students who earned a grade less than the average grade of this course.

In: Computer Science

Design and implement an algorithm that gets as input a list of k integer values N1,...

Design and implement an algorithm that gets as input a list of k integer values N1, N2, …., Nk, as well as a special value SUM. Your algorithm must locate a pair of values in the list N that sum to the value SUM. For example, If your list of values is 3, 8, 13, 2, 17, 18, 10, and the value of SUM is 20, then your algorithm would output either of the two values (2, 18) or (3, 17). If your algorithm cannot find any pair of values that sum to the value of SUM, then it should print the message ‘Sorry there is no such pair of values.’

In: Computer Science

A painting company has determined that for every 115 square feet of wall space, one gallon...

A painting company has determined that for every 115 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $20.00 per hour for labor. Design a modular program that asks the user to enter the square feet of wall space to be painted and the price of the paint per gallon.

The program should display the following data:

The number of gallons of paint required

The hours of labor required

The cost of the paint

The labor charges T

he total cost of the paint job

Using Python

In: Computer Science

In python idle 3.9.0 write a function that: i) will count all lower case, upper case,...

In python idle 3.9.0 write a function that:

i) will count all lower case, upper case, integers, and special symbols from a given string. The input string is provided by the user.

ii) will check if a sting is a palindrome. User supplies the input string.

In: Computer Science

In this assignment, you need to demonstrate your ability in using input, output, data types, and...

In this assignment, you need to demonstrate your ability in using input, output, data types, and if statement in C++ program. Assume that you need write a C++ program for a cash register. There are only four items in the store: Cereal, $3.99 Milk, $3.99 Egg, $0.25 Water, $ 1.50 Once a customer purchases items, you will ask her/his how many of them are bought. The quantity can be in the range of 0-10 (including 0 and 10). Then, calculate total for this transaction. Later ask for payment method, which could be either Credit Card or Cash. Do not use string variables. Just use char variables, for instance “1” for Credit Card, “2” for Cash. If the payment method is CC, your program exits. If it is cash, and enter the amount received from customer. Then show the due amount the customer. An example scenario for a CC payment: Enter how many cereal boxes customer bought:2 Enter how many milk jars customer bought:1 Enter how many eggs customer bought:3 Enter how many water bottles customer bought:0 Total is $12.72 Payment Method: 1 Thanks... An example scenario for a cash payment: Enter how many cereal boxes customer bought:1 Enter how many milk jars customer bought:0 Enter how many eggs customer bought:6 Enter how many water bottles customer bought:5 Total is $12.99 Payment Method: 2 Enter the amount received from customer: 20.00 Due amount is $7.01 Thanks...

In: Computer Science

Show that every 2-tree with n internal nodes has n+ 1 external nodes

Show that every 2-tree with n internal nodes has n+ 1 external nodes

In: Computer Science

Given a string, such as x = ‘itm330’, write a Python program to count the number...

Given a string, such as x = ‘itm330’, write a Python program to count the number of digits and the number of letters in it. For example, in ‘itm330’, there are 3 letters and 3 digits.

Hint: Very similar to page 11 on the slides. To check if a character c is a digit, use c.isdigit(). If c is a digit, c.isdigit() will be a True.

In: Computer Science