1. Data in Java: Primitives and Objects In this section, we’ll build a class that is composed of both primitives and objects. Java has classes to help in converting from primitives to objects (for example an int to an Integer) and vice-versa. Let’s start by building a small class used to represent a single concept such as a Car or Vehicle. Make a new Java project and and create a new class called “Car”. Cars should define primitives for things like odometers, etc., and Strings for make and model. Inside your Car class but outside of any method, define three (instance) variables for the odometer, make, and model. Write a main that builds 2 cars and prints them out. (Hint: Car c1 = new Car(); and System.out.println(c1.toString());.)
2. Variable Scope in Java: Local and Class-Level Lets practice building classes again and defining two variables: one local and one with class-level scope. Prove to yourself that you can access the class-level variable throughout the class in which it’s defined. Then, try to access the local variable from a method other than the one in which it’s defined. Finally, look inside of Rectangle.java and identify at least 4 instance variables (class-level) and at least 2 local variables. Indicate these using comments.
3. This (the Implicit Parameter) Take a class you’ve already built (or build the Car Class described in the “Data in Java” section) and build an object from that class. Observe the address of that object in main by using println with toString(). Next, from a method inside the class, print out the address of the “this” object using println. Call that method on the object you’ve just built, and explain why the two addresses are the same.
4. Access Modifiers: Public and Private Build yet another simple class (say, a Point or Pair). Then, create another (separate, distinct) class that is to be the “driver” for this example (just like the driver above). In your driver, build an object of the Point class and try to access a method declared as public. Now, on the same vehicle object, try to call a method declared as private. What message does Java print out? Next, declare some class-level data item as public (an int, say), and declare another class-level data item as private. In your driver’s “main”, try again to access these two data items – what message does the Java compiler display now?
5. Accessors and Mutators (or, Getters and Setters) Each of these sections encourages you to practice building small classes, and we’ll continue that pattern here. Construct a simple class used to store the time or date. Add a field for minute, second, and hour, but make these class-level variables private. So that our class can be used by external clients, we need to declare some public methods for use with our private data. Build two methods for each data item: one to get the value of the data item, and one to set the value of the data item. See the getters and setters defined in the Rectangle class for examples of these getters & setters.
6. Overriding toString() (and equals()) Build a simple class to represent a Vehicle (or reuse your Car class above). In a main, build an object of that class, and print out the object using System.out.println(). Notice that this simply reports the memory address of the object in question, and we’d like to do something more useful. To replace (or override) the toString (or equals) function, first see the examples defined in the NewAndReviewExamples.java file for both toString and equals. Now, build a toString function that prints out the make, model, and odometer reading for a vehicle object.
7. Overloading Methods Check out the Rectangle class constructors to see an example of overloading – defining multiple methods with the same name. Now build a SquareSomething class, with all static functions, whose purpose is to take an int, a double, or a float, and report back the square of the number (returning the correct type). This will mean your square class has three functions ( all named “square”) that each take a different type of data as input (int, double, float). Your square function that takes a double should return a double as well. This is how the println() method accomplishes such flexibility – you can hand it an int, a string, a double, a float, etc. and it simply prints the data. How it does so is by overloading the println() method to provide a different function for each possible type of input.
8. Constructors as Methods First, check out the set of constructors provided for you in the Rectangle class. Notice how they are overloaded (meaning many methods with the same name, but different with regards to input) to provide flexibility for users of this class. Add to your Car class two constructors – one to take a string make, the other to take two strings: a make and a model. Test these constructors by building multiple Cars in your main() driver, calling each constructor in turn.
In: Computer Science
Envision an algorithm that when given any positive integer n, it will print out the sum of the squares from 1 to n.
E.g. given 4 the algorithm would print 30 (because 1 + 4 + 9 + 16 = 30) You can use multiplication denoted as * in your solution and you do not have to define it (e.g. 2*2=4)
Write pseudocode for this algorithm using iteration (looping).
Create a flow chart
Implement solution from flowchart in Python at http://www.codeskulptor.org/
In: Computer Science
#include <stdio.h>
#include <ctype.h>
int main(void) {
int ch;
unsigned long int charcount=0, wordcount=0, linecount=0;
while((ch=getchar())!=EOF){
if(ch==' ' || ch=='\n' || ch=='\t' || ch=='\0' || ch=='\r') {
wordcount++;
}
if(ch=='\n' || ch=='\0') {
linecount++;
}
charcount++;
}
printf("%lu %lu %lu\n", charcount, wordcount, linecount);
getchar();
return 0;
}
When my code reads a blank line, it increment my wordcount by one.
How can I fix this problem? Could you help me with this problem?
In: Computer Science
Database Schema:
Book(bookID, ISBN, title, author, publish-year, category)
Member(memberID, lastname, firstname, address, phone-number, limit)
CurrentLoan(memberID, bookID, loan-date, due-date)
History(memberID, bookID, loan-date, return-date)
Members can borrow books from the library. The number of books they can borrow is limited by the “limit” field of the Member relation (it may differ for different members). The category of a book includes fiction, non-fiction, children’s and reference. The CurrentLoan table represents the information about books that are currently checked out. When the book is returned to the library, the record will be removed from CurrentLoad relation, and will be inserted into History relation with the return-date. A library may have more than one copy of the same book, in which case each copy has its own bookID, but all copies share the same ISBN.
Write SQL statements for each of the following questions.
(1) (16 pts) Create all the relations listed above. Make sure to indicate the primary key and the foreign keys (if any) in your statements.
(2) (10 pts) Insert at least 5 members, 10 books, and enough tuples in the CurrentLoan and History relation. Add tuples as needed to be able to test the following queries for different test cases.
(3) (8 pts) Find the book ID, title, author, and publish-year of all the books with the words “XML” and “XQuery” in the title. These two keywords can appear in the title in any order and do not have to be next to each other. Sort the results by publish year in descending order.
(4) (8 pts) Find the book ID, title, and due date of all the books currently being checked out by John Smith.
(5) (8 pts) Find the member ID, last name, and first name of the members who have never borrowed any books in the past or currently.
Note:
• Please put all the SQL statements in a single file and name it as hw2_yourPirateID.sql.
• Remember to change all the dash “-” in attribute names to underscore “_”.
• For the ease of testing, please add the “drop table” statements at the beginning of your file to drop all the tables.
• Remember to add “commit;” after your last “insert” statement.
• Comment your code as needed. You can use /* … */ to have multi-line comments or use double hyphen (--) for single line commenting. You may use PROMPT … to print any message to the screen. For example, you may use PROMPT Answer for Question 3 (before the query for question 3).
• For this assignment, you need to test your solutions in Oracle and submit your .sql file
In: Computer Science
In: Computer Science
JAVA script!
You will write a program that will input the nationalities of your favorite types of food, examples, and prices of some of your favorite food. You will save a type of food, two examples of that type of food, the price of each of those two examples, and a total price of both together. You must input your own types, examples, and prices, but check a sample run below. You must use the concepts and statements that we have covered so far this semester. Use a loop that loops two times using a counter. Inside the loop, first ask the user to input the nationality of their favorite foods (ex. German, Italian, etc.). The user will now input an example of that type of food and the cost of that food. The user will now input another example of that type of food and the cost of that food. Add the two costs to a total amount variable. Now output the nationality of the type of food and the total amount of the two types of food rounded to two decimal places. Then, ask the user if they would like to list their choices, by answering either y/n or 1/2. If they say y or 1 for yes, print the two examples of that type of food. Hint: When running your program, keep track of the enters in the memory buffer. Whenever an input is skipped over, clear the enter from the input memory buffer. Whenever the program wants an extra input, do not clear the input memory buffer.
In: Computer Science
(1) Explain program-data independence.
(2) Explain what advantages NoSQL approaches have over traditional DBMS solutions.
(3) One company has many departments. A department has many cars and many employees. An employee can loan his/her department’s car for a business trip. Every department needs to keep track the car rental history including “start date”, “return date”, “start mileage”, and “end mileage”. Design an ERD based on above requirements. Please identify (strong and weak) entities, attributes, and (identifying and non-identifying) relationships clearly.
In: Computer Science
You are to design a database for the upcoming Greater Wisconsin River Fishing Contest. Consider the following functional dependencies;
Please note the following;
Create an ERD in 3NF for these relations. Create appropriate table names for the ERD. Include all applicable fields based on information you have been given and underline the Primary or Composite Primary Key fields. Make sure to include the correct ERD diagram symbols between tables to show the proper relationship type (e.g. 1:1, 1:M, etc.)
In: Computer Science
1. Write a program array_compare.c that determines the number of elements are different between the two integer arrays (same size) when compared element by element (first element with first element, second with second, and so on). The program should include the following function. Do not modify the function prototype.
void count_diff(int *a1, int *a2, int n, int *num_diff);
The function takes two integer array parameter a1 and a2 of size n. The function stores the number of elements that are different to the variable pointed by the pointer variable num_diff.
The function should use pointer arithmetic – not subscripting – to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function. The main function should ask the user to enter the size of the arrays and then the elements of the arrays, and then declare the arrays. The main function calls the count_diff function. The main function displays the result.
Example input/output #1: Enter the length of the array: 5
Enter the elements of the first array: -12 0 4 2 36
Enter the elements of the second array: -12 0 4 2 36
Output: The arrays are identical
Example input/output #2:
Enter the length of the array: 4
Enter the elements of the first array: -12 0 4 36
Enter the elements of the second array: 12 0 41 36
Output: The arrays are different by 2 elements
In: Computer Science
Database Design
Give one example of a cardinality ratio for a relationship of degree five.
In: Computer Science
q1)
Critically analyse the problems you are likely to encounter in creating a cross-platform multimedia projects and list several ways to deal with these problems
In: Computer Science
. A simple way to encrypt a number is to replace each digit of the number with another digit. Write a C program that asks the user to enter a positive integer and replace each digit by adding 6 to the digit and calculate the remainder by 10. For example, if a digit is 6, then the digit is replaced by (6+6)%10, which is 2. After all the digits are replaced, the program then swap the first digit with the last digit. The main function reads in input and displays output.
A sample input/output:
Enter the number of digits of the input number: 3
Enter the number: 728
Output: 483
2) The user will enter the total number of digits before entering the number.
3) You can use format specifier "%1d" in scanf to read in a single digit into a variable (or an array element). For example, for input 101011, scanf("%1d", &num) will read in 1 to num.
4) As part of the solution, write and call the function encrypt() with the following prototype.
The function assumes that the digits are stored in the array a and computes the encrypted digits and store them in the array b. c represents the size of the arrays. void encrypt(int *a, int *b, int n); The function should use pointer arithmetic – not subscripting – to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.
5) As part of the solution, write and call the function swap() with the following prototype. void swap(int *p, int *q);
When passed the addresses of two variables, the swap() function should exchange the values of the variables: swap(&i, &j); /* exchange values of i and j */
In: Computer Science
Design a Python program with a While loop that lets the user enter a number. The number should be multiplied by 10 and the result
stored in a variable named "product". The loop should repeat as long as the product variable < 10. Anything not completely obvious to a newbie should be commented on as in line comments. Should be modulated and repeatable as well as there should be an invocation of the main routine at the end of the program.
Grading Rubrick
| Program Compiles Cleanly | syntax errors |
| 25 pts | -5 per error |
| Program runs without runtime errors ( validation) | run-time errors |
| 25 pts | -5 per error |
| Program give correct answers | Logic errors |
| 30 pts | -5 per error |
| Program is repeatable | Not repeatable |
| 5 pts | -5 pts |
| Program is well modularized | Barely Modularized |
| 10 pts | - 5 pts |
| Documented Well | Documented Some |
| 5 pts | - 3 pts |
| Something Cool (but relevant) beyond strict requirements | Something extra |
| 5 pts | + 3 pts |
| Best possible grade : 105 |
In: Computer Science
What is the legal basis of the argument that privacy is a right?
In: Computer Science
hello! So I have this CIS assignment lab but when I try to make the code I don't really know where to start from. My professor is very hard and he likes to see the outcomes as they are shown in the problem. Please help me! the program should be a C++ PLS
Write a program that can be used as a math helper for an
elementary student. The program should display two random integer
numbers that are to be added, such as:
247
+ 129
-------
The program should wait for the students to enter the answer. If
the answer is correct, a message of congratulations should be
printed. If the answer is incorrect, a message should be printed
showing the correct answer.
The program displays a menu allowing the user to select an
addition, subtraction, multiplication, or division problem. The
final selection on the menu should let the user quit the program.
After the user has finished the math problem, the program should
display the menu again. This process is repeated until the user
chooses to quit the program.
Input Validation: If the user select an item not on the menu,
display an error message and display the menu again.
Requirements:
Addition
Generate two random numbers in the range 0 - 9.
Subtraction
Generate two random numbers in the range 0 - 9.
num1 = rand() % 10;
num2 = rand() % 10;
Make sure num2 <= num1...
while (num2 > num1)
num2 = rand() % 10;
Multiplication
Generate two random numbers. The first in the range 0 - 10, the
second in the range 0 - 9.
Division
Generate a single digit divisor
num2 = rand() % 9;
Generate a num1 that is a multiple of num2 so the division has no
remainder. The num1 is never zero.
num1 = num2 * (rand() % 10 + 1);
All constant values must be declare as a constant variable. Use
the constant variable in the calculation.
Validating the selection (1 to 5). If the selection is not in the
range between 1 and 5, the program keeps asking the input until the
correct selection is entered.
Comments in your program to explain the code logic and
calculation.
Output sample:
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 1
1
+ 2
---
4
Sorry, the correct answer is 3.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 7
The valid choices are 1, 2, 3, 4, and 5. Please choose: 2
8
+ 6
---
2
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 3
9
* 4
---
36
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 4
8 / 2 = 4
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 4
6 / 2 = 3
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 5
"Thank you for using math helper!"
In: Computer Science