import java.util.Scanner;
public class Grade {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Reading score from user
System.out.println("Enter the student's score:");
double score = scnr.nextDouble();
System.out.print("Grade:");
// Checking if score is less than 60
if(score<60){
System.out.println("F");
}
// Checking if score is less than 70
else if(score<70){
System.out.println("D");
}
// Checking if score is less than 80
else if(score<80){
System.out.println("C");
}
// Checking if score is less than 90
else if(score<90){
System.out.println("B");
}
// Checking if score is less than 100
else {
System.out.println("A");
}
}
}
I need this codes output to say
Enter the student's score:
A
and mine says
Enter the student's score:
Grade: A
How do I fix that in my code?
In: Computer Science
Java program
Bounds checking
Make an array {4, 6, 2, 88, 5}, ask the user what number they would like to change. If their pick is out of bounds, tell them. Otherwise ask them what they would like to change the number to. After the change, display all the numbers with a for loop
In: Computer Science
CREATE TABLE IF NOT EXISTS students (
student_id INT NOT NULL AUTO_INCREMENT,
first_name VARCHAR(16),
last_name VARCHAR(24),
birthday DATE,
street_address VARCHAR(128),
city VARCHAR(32),
PRIMARY KEY (student_id));
INSERT INTO students
(first_name, last_name, birthday, street_address, city) VALUES
('John','Jones','2000-12-17','250 Pines Blvd.','Pembroke Pines'),
('Mark','Bacon','2000-04-12','1270 Walnut St.','Prarie Bluff'),
('Bill','Carlson','1999-07-06','250 Pines Blvd.','Pembroke Pines'),
('Jean','Carlson','1999-07-06','250 Pines Blvd.','Pembroke Pines'),
('Leonard','Cook','2000-09-14','8046 Maple St.','Highland Park'),
('William','Markham','1999-07-06','1600 Sylvan Ln.','Lake Forest'),
('Sam','Cook','1998-10-13','8046 Maple St.','Highland Park'),
('Fred','Williams','1999-07-08','722 Oack Knoll','Arlington'),
('Sally','Fillmore','2000-03-25','1215 Carrington St.','Decatur'),
('Mary','Jones','1999-11-13','1940 Grant St.','Denver'),
('Phyllis','Jones','1999-11-13','1940 Grant St.','Denver');
In: Computer Science
Create a class Client. Your Client class should include the following attributes:
Company Name (string)
Company id (string)
Billing address (string)
Billing city (string)
Billing state (string)
Write a constructor to initialize the above Employee attributes.
Create another class HourlyClient that inherits from the Client class. HourClient must use the inherited parent class variables and add in hourlyRate and hoursBilled. Your Hourly Client class should contain a constructor that calls the constructor from the Client class to initialize the common instance variables but also initializes the hourlyRate and hoursBilled. Add a billing method to HourlyClient to calculate the amount due from a service provided. Note that billing amount is hourlyRate * hoursBilled
Create a test class that prompts the user for the information for five hourly clients, creates an arraylist of 5 hourly client objects, display the attributes and billing for each of the five hourly clients. Display the company name and billing amount for each company and the total billing amount for all five companies.
Remember to submit your pseudocode algorithm
In: Computer Science
can u give me an example of how to removing Double Linked List a node at a given location in java
the method should be like this:
public void removeFromLocation(int location) {
}
}
In: Computer Science
Problem Statement
Josephus attended a party where they had a rather strange raffle. Everyone was to stand in a circle, and every Mth person was to be eliminated until only one person was remaining, who won the lawnmower.
Write the function Josephus, which takes as parameters a vector<string> representing the N guests at the party in the order they line up for the raffle, and the integer M, giving which person will be eliminated at each turn. Your function should return a string giving the name of the winner of the raffle (the last person standing).
Hint: While there is a mathematical solution, a queue will be much more straightforward.
Constraints
Examples
guests = {"Josephus", "Titus", "Simon", "Eleazar"} M = 3 Returns: "Josephus"
Counting every third person from Josephus (remember, they are in a circle), Simon is eliminated first. Skipping Eleazar and Josephus, Titus goes next. Skipping Eleazar and Josephus, we come back to Eleazar. Josephus, who cleverly suggested M = 3, comes out the winner!
guests = {"Bradford", "Rosette", "Ji", "Ashleigh", "Avery", "Lavonna", "Fredericka"} M = 2 Returns: "Fredericka"
guests = {"Tiffany", "Randy", "Kit", "Sharlene", "Marquerite", "Debra", "Pok", "Tanisha", "Claudio"} M = 17 Result: "Debra"
Given Function
string Josephus(vector<string> guests, int M) {
// your code here
}
Use the given function to solve the problem statement. Please follow the given notes and constraints. Please code this problem in C++.
In: Computer Science
Python Programming, Below included the Skeleton, input and output. Could you also include indents in the solutions.
In this programming laboratory you will create a Python program that evaluates the sum of the following mathematical series:
Sum = x0 / 0! + x1 / 1! + x2 / 2! + x3 / 3! + … + xn / n!
The variable x is a real (float) number and the variable n is an integer that can assume values greater than or equal to 0. You program is to consist of a main program that allows the user to input values of x and n and then executes a loop with an index going from 1 to n. Your program should also include two functions, factorial and power, that calculate (respectively) factorial values and numbers to a power. The main program should call the factorial and power functions, from within the loop, to evaluate the expression for relevant values and add the value of the current term to the running sum. You may use the factorial function that was introduced in the examples in this week’s module (included in the skeleton of the program). You will need to write your own power function. The power function should compute x to the 0 power or x to positive integer powers. Do not worry about negative powers of x.
# Function to compute x to the k power
def power(x,k):
You will need to complete this function here
If x is 0 then return 0
Otherwise if n is 0 return 1
Otherwise use a loop to multiply x times itself n times and return the product
# The function below is the factorial function used in the Week Six examples
def factorial(num):
if num < 0:
print('Number must be >= 0')
exit()
else:
fac = 1
while num >= 1:
fac = fac * num
num = num - 1
return fac
# Main program
sum = 0.0
x = input("Enter x value ")
x = float(x)
n = input("Enter n value ")
n = int(n)
if n < 0:
print("n must be < 0")
quit()
…
You will need to complete your main
program here. It will
need to include a while loop that goes from 0 to n and calls to the
factorial and power functions.
After the loop, you will need to print the sum value
Your program should produce the results shown below when executed. Multiple executions with different x and n values are displayed.
Enter x value 2
Enter n value 0
Sum is 1.0
Enter x value 2
Enter n value 1
Sum is 3.0
Enter x value 2
Enter n value 2
Sum is 5.0
Enter x value 2
Enter n value 3
Sum is 6.333333333333333
In: Computer Science
You are to write a program that grades students (Maybe I will use it on you). Your program must open and read in "input.txt" (an example of which is below). It will contain the students name and their test scores. You are to calculate the students final grade in the course. Take the average of their test scores and output their average to a file with the below format. For the output.txt ensure that the formatting is in the block style shown below. Test scores should always be shown to the second decimal place. input txt: (Meryl Streep 100 105 98.5 99.5 106)
output txt : (Meryl StreepTest scores:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Average score: .......................101.80Test score 1: ........................100.00Test score 2: ........................105.00Test score 3: .........................98.50Test score 4: .........................99.50Test score 5: ........................106.00~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Input fields: <First Name> <Last Name> <Score on Test 1> <Score on Test 2> <Score on Test 3> <Score on Test 4> <Score on Test 5>
In: Computer Science
List.h
template
class List { // List class ADT
public:
virtual void clear() = 0;
// Inserts an item into the list at position index
virtual bool insert(const ListItemType& newItem) =
0;
// Append "it" at the end of the list
// The client must ensure that the list's capacity is
not exceeded
virtual bool append(const ListItemType& newItem) =
0;
// Deletes an item from the list at a given
position
virtual ListItemType remove() = 0;
// Set the current position to the start of the
list
virtual void moveToStart() = 0;
// Set the current position to the end of the
list
virtual void moveToEnd() = 0;
// Move the current position one step left, no
change if already at beginning
virtual void prev() = 0;
// Move the current position one step right, no
change if already at end
virtual void next() = 0;
//Return the number of items stored in the
list
virtual int length() const = 0;
// Return the position of the current element
virtual int currPos() const = 0;
// Set the current position to "pos"
virtual bool moveToPos(int pos) = 0;
// Return true if current position is at end of the
list
virtual bool isAtEnd() const = 0;
// Return the current element
virtual ListItemType getValue() const = 0;
// Note: The fololwing methods assume that ListItemType is comparable: that is to say the relational operators such as == exist.
//search for the first occurance in the list of an
item. If found return true and set curr to the location.
// if not found, return false and set curr to the end
of the list.
virtual bool find(const ListItemType& newItem) =
0;
//search for the next occurance in the list of an
item. Start with the next position after curr. If found return true
and set curr to the location.
// if not found, return false and set curr to the end
of the list.
virtual bool findNext(const ListItemType& newItem)
= 0;
// count the number of times a value is found in
the list
// curr should be set back to its current location
after the count.
virtual int count(const ListItemType& newItem) =
0;
};
LList.h
#include "list.h"
// Linked list implementation
template
class Node
{
public:
ListItemType element;
Node* next;
Node()
{
next = nullptr;
}
Node(const ListItemType& e)
{
this->element = e;
next = nullptr;
}
};
template
class LList : public List {
private:
Node* head;
Node* tail;
Node* curr;
int listSize;
public:
// Constructor
LList() {
head = tail = curr = nullptr;
listSize = 0;
}
//Destructor
~LList() {
clear();
}
// Remove all elements
void clear() {
if (listSize > 0) {
Node*
temp;
curr =
head;
do {
temp = curr -> next;
delete curr;
curr = temp;
} while (curr !=
nullptr);
}
curr = tail = head = nullptr;
listSize = 0;
}
bool insert(const ListItemType& newItem) {
if (listSize == 0) {
head = new
Node(newItem);
tail =
head;
curr =
head;
}
else if (curr == head) {
Node* temp = new
Node(newItem);
temp->next =
head;
head =
temp;
curr =
head;
}
else if (curr == nullptr) {
return
false;
}
else {
Node* temp =
head;
while
(temp->next != curr)
temp = temp->next;
temp->next =
new Node(newItem);
temp->next->next = curr;
curr =
temp->next;
}
listSize++;
return true;
}
// Append "it" to list
bool append(const ListItemType& newItem) {
// hint: handle an empty list and a
non-empty list separately
cout << "*****
complete this method ...\n";
return false;
}
// Remove and return current element
ListItemType remove() {
ListItemType it =
curr->element;
if (curr == head) {
head =
head->next;
delete
curr;
curr =
head;
listSize--;
if (head ==
nullptr)
tail = nullptr;
}
else if (curr == tail) {
moveToPos(listSize - 2);
delete
curr->next;
tail =
curr;
tail->next =
nullptr;
curr =
nullptr;
listSize--;
}
else {
Node* temp =
head;
while
(temp->next != curr)
temp = temp->next;
temp->next =
curr->next;
delete
curr;
curr =
temp->next;
listSize--;
}
return it;
}
void moveToStart() { curr = head; }
void moveToEnd() { curr = nullptr; }
void prev() {
if (head == curr) return;
Node* temp = head;
while (temp -> next != curr)
temp = temp -> next;
curr = temp;
}
void next() { if (curr != nullptr) curr = curr ->
next; }
int length() const { return listSize; }
int currPos() const {
if (curr == nullptr) return
listSize;
Node* temp = head;
int i;
for (i = 0; curr != temp;
i++)
temp = temp
-> next;
return i;
}
// Move down list to "pos" position
bool moveToPos(int pos) {
if ((pos < 0) || (pos >
listSize)) return false;
curr = head;
for (int i = 0; i next;
return true;
}
// Return true if current position is at end of the
list
bool isAtEnd() const { return curr == nullptr; }
// Return current element value.
ListItemType getValue() const { return curr ->
element; }
// Check if the list is empty
bool isEmpty() const { return listSize == 0; }
bool find(const ListItemType&
it) {
cout << "*****
complete this method ...\n";
// hint: if list is empty return
false
// set curr to head and traverse
list until curr becomes nullptr or "it"is found
return false;
}
//search for the next occurance in the list of an
item. Start with the next position after curr. If found return true
and set curr to the location.
// if not found, return false and set curr to the end
of the list.
bool findNext(const ListItemType&
it) {
cout << "*****
complete this method ..\n";
// hint: if curr is nullptr return
false
// set curr to curr->next and
traverse list until curr becomes nullptr or "it" is found
return false;
}
// count the number of times a value is found in the
list
// curr should remain where it is
int count(const ListItemType& it)
{
cout << "*****
complete this method ...\n";
// hint: do not use curr, but a
temp pointer to traverse the list.
// set temp to head, and traverse
list until temp is nullptr counting elements that are equal
int count = 0;
return count;
}
};
1- Complete the append method in LList.h( Bold
)
2- Complete the find, findNext and count in LList.h(Bold)
In: Computer Science
In: Computer Science
Using the bisection method, find the root of the following function:
f(x)=cos(2x) - x
Use the following initial values: xl=0 and xu=2
NOTE: Perform only 3 iterations.
In: Computer Science
Write a c++ function named multi_table to print out multiplication table for a given number of rows and columns. Your program should print a header row and a header column to represent each row and column number. For example your function call multi_table(4, 4) would print below to the command line:
1 | 1 2 3 4
_________
2 | 2 4 6 8
3 | 3 6 9 12
4 | 4 8 12 16
Test your function in a driver program for 12 by 12 multiplication table.
In: Computer Science
In the game of craps, a pass line bet proceeds as follows: Two six-sided dice are rolled; the first roll of the dice in a craps round is called the “come out roll.” A come out roll of 7 or 11 automatically wins, and a come out roll of 2, 3, or 12 automatically loses. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number becomes “the point.” The player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the bet. If a 7 is rolled first, then the player loses. Write a program that simulates a game of craps using these rules without human input. Instead of asking for a wager, the program should calculate whether the player would win or lose. The program should simulate rolling the two dice and calculate the sum. Add a loop so that the program plays 10,000 games. Add counters that count how many times the player wins and how many times the player loses. At the end of the 10,000 games, compute the probability of winning [i.e., Wins / (Wins + Losses)] and output this value. Over the long run, who is going to win the most games, you or the house?
In: Computer Science
8,2,10,10,8,10,2,8,,8,10,2,8,1,1,8
Trace the above using (3 way partitioning) quick sort java
In: Computer Science
In: Computer Science