1Write a Java program that calculates and displays the Fibonacciseries, defined by the recursive formula
F(n) = F(n-1) + F(n-2).
F(0) and F(1) are given on the command line.Define and use a class Fib with the following structure:
public class Fib {
// constructorpublic Fib(int f0, int f1){.....}
// computes F(n) using an ***iterative*** algorithm, where F(n) =
F(n-1) +
F(n-2) is the recursive definition.
// use instance variables that store F(0) and F(1).
// check parameter and throw exception if n < 0. Don't worry about
arithmetic overflow.
public int f(int n) {....}
// computes F(n) using the ***recursive*** algorithm, where F(n) =
F(n-1)
+ F(n-2) is the recursive definition.
// use instance variables that store F(0) and F(1).// check parameter and throw exception if n < 0. Don't worry about
arithmetic overflow.
public int fRec(int n) {....}
public static void main(String[] args){
// get numbers F(0) and F(1) from args[0] and args[1].// use
either the Scanner class or Integer.parseInt(args[...])// you must
handle possible exceptions !....
// get n from args[2]:....
// create a Fib object with params F(0) and F(1)....
// calculate F(0), ..., F(n) and display them with
System.out.println(...) using
// the iterative methode f(i)....
// calculate F(0), ..., F(n) and display them with
System.out.println(...) using
// the recursive methode fRec(i)....
}
// instance variables store F(0) and F(1):....
};
Write javadoc comments for the Fib class.
In: Computer Science
In 2 to 3 paragraphs describe the C program written below (What the program is supposed to do). State the requirements for the program (How does the program meet the requirements) and discuss the logical process your program uses to meet those requirements (The process steps to meet the requirements).
#include "stdio.h"
int main(void)
{
//initialize array
int arr[100];
//initialize variables
int i=0, j=0, n=0;
//infinite loop which will stop when user enters
-1
while(n != -1)
{
printf("Enter percentage grade(0-100). Enter -1 to stop: ");
//read grade
scanf("%d",&n);
//if user entered grade is not -1
if(n != -1)
{
//save it to array
arr[i++] = n;
}
//if user entered -1, then exit this loop
else
{
break;
}
}
printf("\n\nThe grades are: \n");
//loop which will iterate till no:of user entered grades
for(j=0; j<i; j++)
{
//print the grade
printf("%d ",arr[j]);
}
return 0;
}
In: Computer Science
Program should be written in Java
b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out class or the JOptionPane classes as you desire. The purpose of this exercise is practice for concatenating Strings and producing String output.
In: Computer Science
You will need the following variables:
ExamAvg, FinalExam, Partication, AssignAvg, MyName, Grade
Create lists for Exams and Assignments, ExamList and AssignList.
Assume Participation is 100% for now and assign values to assignments and exams (you'll have to guess at Exam2). Use methods we have learned on lists to calculate the averages.
Your grade is calculated by the following weighting formula:
Grade = (0.30)*(ExamAvg) + (0.25)*FinalExam + (0.05)*Participation + (0.40)*AssignAvg
Use a series of if-else, and elif statements to calculate (and print) your grade according to the following:
if 90 <= grade <= 100 Congratulations, MyName, you earned an A.
if 80 <= grade <= 89 Good work, MyName, you earned a B.
if 70 <= grade <= 79 You earned a C, MyName, perhaps a bit more work?
if 60 <= grade <= 69 You earned a D, MyName, come for help if you need it.
if grade < 60 You are failing the course. Please come for help.
You are free to use different variable names, put values in a list, etc.
In: Computer Science
CIS247C WEEK 2 LAB
The following problem should be created as a project in Visual Studio, compiled and debugged. Copy your code into a Word document named with your last name included such as: CIS247_Lab2_Smith. Also include screen prints of your test runs. Be sure to run enough tests to show the full operation of your code. Submit this Word document and the project file (zipped).
The Zoo Class
This class describes a zoo including some general visitor information. We will code this class using the UML below. There is a video in the announcements on how to code a class from a UML diagram. There is also an example shown by the Exercise we complete together in the Week 2 class.
It is required to use a header file for your class definition that contains the private attributes and prototypes for the functions (no code in the header file!) Use a .cpp file for the code of the functions. Then create a separate .cpp file for the main function.
The file with the main function should have a documentation header:
/*
Programmer Name: Your Name
Program: Zoo Class
Date: Current date
Purpose: Demonstrate coding a simple class and creating objects from it.
*/
Coding the Zoo Class
Create a header file named: Zoo.h and a .cpp file named: Zoo.cpp. The easiest way to do this is to use the “Add Class” function of Visual Studio.
In the header file, put your class definition, following the UML as a guide. In the private access section, declare your variables. In the public access section, list prototypes (no code) for the two constructors, setters and getters and the other functions shown.
Zoo |
-zooName : string //example: Brookfield Zoo -zooLocation : string //city, state -yearlyVisitors : int -adultAdmissionCost : double |
+Zoo() //default constructor should zero numbers and set strings to “unknown” +Zoo(name : string, place : string, visitors: int, cost : double) +getName() : string +getLoc() : string +getVisitors() : int +getAdmission() : double +setName(name : string) : void +setLoc(place : string) : void +setVisitors(visitors : int) : void +setAdmission(cost : double) : void +printInfo() : void //prints the name, location, visitors and adult admission cost |
In the Zoo.cpp file, put the code for all the functions. Remember to put the class name and scope resolution operator in front of all function names.
Example setter:
void Zoo::setVisitors(int visitors) {yearlyVisitors = visitors;}
Example getter:
int Zoo:getVisitors() {return yearlyVisitors;}
In the .cpp file for the main function, be sure to add this to your includes:
#include “Zoo.h”
Here is some high level pseudocode for your main function:
main
declare 2 string variables for the name and location
declare int variable for the number of visitors
declare double variable for the adult admission cost
declare a Zoo object with no parentheses (uses default constructor)
set a name for the Zoo (name of your choice such as “Brookfield Zoo”)
set a location for the Zoo in the format: city, state (example: “Chicago, IL”)
set the yearly number of visitors (any amount)
set the adult admission cost (any amount)
//use proper money formatting for the following
use the printInfo() method to print the Zoo object’s information
//Preparing for the second Zoo object
//Suggestion: use getline(cin, variable) for the strings instead of cin
Ask the user for a zoo name and input name into local variable declared above
Ask the user for the zoo location and input the location into local variable
Ask the user for the zoo yearly number of visitors and input into local variable
Ask the user for the adult admission cost and input into local variable
//Using the constructor with parameters to create an object
declare a Zoo object and pass the four local variables in the parentheses
use the printInfo() method to print the Zoo object’s information
end main function
SUBMITTING YOUR PROGRAM
When you are done testing your program, check that you have used proper documentation. Then copy and paste your code from Visual Studio into a Word document. Be sure to copy all three files. Take a screenshot of the console window with your program output. Paste this into the same document.
Save your Word document as: CIS247_Week2Lab_YourLastName.
Submit your Word document and also the properly zipped project folder.
C++ language
In: Computer Science
Write a regular expression for the language of all strings over {a,b} in which every b is directly preceded by a, and may not be directly followed by more than two consecutive a symbols.
In: Computer Science
Assume you already have a non-empty string S, which is guaranteed to contain only digits 0 through 9. It may be of any length and any number of digits may occur multiple times. Starting from the front of the string, write a loop that jumps through the characters in the string according to the following rule: Examine the current character and jump that many characters forward in the string Stop if you jump past the end of the string, or if you ever land on a 0 Keep track of how many characters are examined during this jumping process (including the final 0). Associate the answer with a variable called charCount. Example 1: For S = "11011", you will examine 3 characters (the first two 1s and then the 0. The last two 1s will not be examined). Example 2: For S = "3120" you will examine 2 characters (seeing the first 3, you will jump 3 spaces to the right and land on the 0). Example 3: For S = "11111" you will examine 5 characters.(in python)
In: Computer Science
Binary
How is 00001001 (base 2) represented in 8-bit two’s complement notation?
Convert 0.3828125 to binary with 4 bits to the right of the binary
point.
How is 00110100 (base 2) represented in 8-bit one's
complement.
In: Computer Science
In java, Create a GUI which works as an accumulator
1. There is a textfield A which allows user to enter a number
2. There is also another textfield B with value start with 0.
3. When a user is done with entering the number in textfield A and press enter, calculate the sum of the number in textfield B and the number user just entered in textfield A, and display the updated number in textfield B
In: Computer Science
I need to add this checkpoint to an existing code that i have in python
Checkpoint 1:
Once you have created and tested the Bank Account Class create subclasses to the BankAccount class. There should be two subclasses, CheckingAccount and SavingsAccount. You should add interest_rate to the parent BankAccount class. To the CheckingAccount add variables called per_check_fee default to false and allow_overdraft default to True. To SavingsAccount add the variable transactions_per_month, default it to 5. Create instances of CheckingAccount and SavingsAccount and test them to ensure all the methods work. You should also verify that BankAccount still behaves correctly. You will need to extend the __init__ and __str__ routines from your BankAccount class.
The BankAccount, CheckingAccount, SavingsAccount, and BankAccountTester should all be separate files. You will need to import the BankAccount into the SavingsAccount, CheckingAccount, and BankAccountTester. You will need to import the BankAccount into the SavingsAccount and CheckingAccount classes.
To set default values for a parameter, you say paramater_name = default_value.
In testing you will need to create an instance of the BankingAccount, and test all the methods, deposit and withdraw, and try to withdraw more money than is in the account. You must also create instances of the checking account testing the same methods.
Existing code:
class BankAccount(): def __init__(self, name, id, ssn, balance=0.0): self.__name = name self.__account_id = id self.__ssn = ssn self.__balance = balance def deposit(self, amount): if amount <= 0: print('Error: Deposit amount ${} is in negative'.format(amount)) return else: self.__balance += amount print('Success: Amount ${} deposited succesfully') def withdraw(self, amount): if amount <= 0: print('Error: Withdraw amount ${} is in negative'.format(amount)) return else: if amount <= self.__balance: self.__balance -= amount print('Success: Amount ${} withdrawn succesfully') else: print('Error: Insufficient funds.') def __str__(self): return 'Name: {}, Account ID: {}, SSN: {}, Current Balance: ${:.2f}'.format( self.__name, self.__account_id, self.__ssn, self.__balance )
=========================================================================
from BankAccount import BankAccount def main(): account = BankAccount('John Doe', 1234, '234-789-1221', 1000) print(account) print('Depositing $100 into account') account.deposit(100) print(account) print('Withdrawing $950 from account') account.withdraw(950) print(account) print('Withdrawing $400 from account') account.withdraw(400) print(account) main()
====================================================================
In: Computer Science
create a program that asks user math questions and keeps track of answers...
Python
Allow the user to decide whether or not to keep playing after each math challenge.
Ensure the user’s answer to each math problem is greater than or equal to zero.
Keep track of how many math problems have been asked and how many have been answered correctly.
When finished, inform the user how they did by displaying the total number of math problems, the number they answered correctly, and their percent correct.
Provide meaningful comments
In: Computer Science
Assignment Objectives:
500 words or more, please.
In: Computer Science
You are part of the IT Department at the newly established 200-bed Hospital Puteri Bestari in Ipoh, Perak. The hospital decided to have an in-house inventory system for all of its assets. Write a short program that accepts the inventory tagging number, and store it in a global array named ASSET_NUMBER. The array must be able to store up to 100 assets, and the tagging number is a 7-digit integer. The program should not overwrite existing data in the array, and must first find an empty element before storing the integer at that location.
USE ONLY C++!!
In: Computer Science
In: Computer Science
Write a short program that asks the user for a sentence and prints the result of removing all of the spaces. Do NOT use a built-in method to remove the spaces. You should programmatically loop through the sentence (one letter at a time) to remove the spaces.
In: Computer Science