Book
SerialNum : String -
Name: String –
PublishYear: int -
+ Book()
Book(String, String, String, int , int)+
+ setName(String) : void
+ setSerialNum(String) : void
+ setAuthor(String) : void
+ setEdition(int) : void
+ setYear(int) : void
+ getName():String
+ getAuthor():String
+ getYear(): int
+ getSerialNum(): String
+ getEdition():int
+ setAvailable() : void
+ setUnavailable(): void
checkAvailability(): boolean
-----------------------------------------------------------------------------------
Library
Name : String
Address: String
Static NUMBEROFBOOKS: int
BooksAtLibrray : ArrayList
LibraryIssues: TreeMap
Library()
Library(String, String)
addBook(Book): void
removeBook(Book) : Boolean
searchBookByName(Book) : Boolean
searchBookBySerialNumber(Book) : Boolean
checkBookAvailablity(Book): Boolean
createLibraryIssue(LibrrayIssue):Boolean
addLibraryIssue(LibraryIssue)
removeLibrrayIssue(LibrrayIssue):Boolean
searchLibrrayIssueByStuent(Student): List
searchLibraryIssuebyID(String IssueID):LibrrayIssue
searchLibraryIssueByBook(Book): LibraryIssue
--------------------------------------------------------------------------------------------------------------
Student
id : String
Name: String
Age : int
Student()
Student(String, String, int)
setName (String):void
SetAge(int):void
setId(String):void
getID():String
getName():String
getAge():int
---------------------------------------------------------------------------------------------------
LibraryIsuue
IssueID : String
borrower : Student
borrowedBook : Book
LibraryIssue()
LibraryIssue(String, Student , Book)
setIssueId(String):void
setBorrower(Student):void
setBorrowedBook(Book):void
getIssueID():String
getBorrowed():Student
getBorrowedBook():Book
----------------------------------------------------------------------------------------------------------
Librray
Main()
-----------------------------------------------------------------------------------------------------------------------------------------
Use the attached UML diagrams to build up your project classes
Make sure to put view for your project by Entering true data
You will need to add 5 books and 5 students and at least 3 LibraryIssues
LibraryIssues keeps track of the borrowed book
The librray uses all classes as mentioned in the UML diagram
You will need to check if book is available before borrowing it.
searchLibrrayIssueByStuent(Student): List
This method returns all book if borrowed by single student, as a student could borrow more than one book
Static NUMBEROFBOOKS: int
Each time you add a book the static variable is increased and Each time a book is removed so the static variable is decreased.
createLibraryIssue(LibraryIssue) : boolean
changed the Boolean variable status in book element to false and return false if book is not available
removeLibrrayIssue(LibraryIssue):Boolean
changed the Boolean variable status in book element to true and return false if book is available
Note
LibrrayIssue and Book in the class Library should be List or map
Do not use array as the size is not fixed
In: Computer Science
When a customer or a powerful manager pushes a bad idea on a Project Manager (PM), a PM must learn "intelligent disobedience," that is, the ability to say "no" to demands that might put the project and, thus the company, in harm's way. If you were a PM facing a bad idea from a customer or a powerful manager, how would you say "no"?
In: Computer Science
In: Computer Science
Using Java
Create two exception classes to capture the improper entering of coin names and their corresponding values. Name one class CoinNameException and the other CoinValueException
Design and write a program that asks a young child to input a set of coin names and their corresponding values (in cents) in their piggybank. The program should work in a loop:
All exception classes should have at least two constructors:
In: Computer Science
What is the difference between “System Of Systems” and “System Of Sub-systems”? Give one example of each.
In: Computer Science
Using Java
A stack is a type of data collection on which things can be “pushed” and “popped”. For example, a stack of plates can have a plate added (or “pushed”) onto the stack, and a plate removed (or “popped”) from the stack. Plates are pushed onto or popped off of the stack one at a time. The last plate pushed onto the stack is the first plate popped off of the stack. This type of structure is known as “LIFO” – last in, first out.
In this project, you will create a stack that will hold objects of type Person. The stack itself will be in a class named PersonStack.
When manipulating the stack, three types (or classes) of exceptions can be thrown. Each Exception class will contain two constructors, one which provides a default message for the exception, and one which takes a String as an argument and sets the exception message to that String.
The three Exception classes in this project are:
"PersonStack is full – object not added."
"PersonStack is empty – no object to return."
"Object is not a Person – object not pushed."
Each class above extends Exception, so it is “checked”, and must appear inside a try-catch statement.
Next, you should define a class called PersonStack, which will implement the stack containing an array of Person objects. (Use the Person and Date classes provided on Canvas below.)
The details of this project:
Finally, you will need to write a main “tester” program. (Please put this method in its own class, not with PersonStack.) This program will:
In each “catch” block, print the exception message, but do not stop.
Please do not change the Person or Date classes.
A sample dialog might look like:
Just added five people onto the stack
Here are the contents of the stack:
Name: Harry Potter born: July 31, 1997
Name: Beyoncé born: September 4, 1981
Name: James T. Kirk born: March 22, 2233
Name: Tom Brady born: June 1, 1989
Name: Oprah Winfrey born: March 25, 1975
Trying to push one more onto the stack:
PersonStack is full - object not added
Popping the contents of the stack plus one.
Popped: Name: Oprah Winfrey born: March 25, 1975
Popped: Name: Tom Brady born: June 1, 1989
Popped: Name: James T. Kirk born: March 22, 2233
Popped: Name: Beyoncé born: September 4, 1981
Popped: Name: Harry Potter born: July 31, 1997
PersonStack is empty - no object to return
Trying to add an Object object to the stack.
Object not a Person - object not pushed |
In: Computer Science
Create a post describing something in your life that has a bad user interface. It does not have to be computer related, though a bad computer interface would certainly be on topic. In your post include the following:
In: Computer Science
JAVA FILE PROGRAM
Write a contacts database program that presents the user with a menu that allows the user to select between the following options:
If the user selects the first option, the user is prompted to
enter a person's name and phone number which will get saved at the
end of a file named contacts.txt.
If the user selects the second option, the program prompts the user
asking for the name of the contact. It then searches the
contacts.txt for a matching name. If found, it displays the phone
number on the screen. If not found, it will display an appropriate
error message.
If the user selects the third option, the program displays all
contacts stored in contacts.txt in a neat table.
The program is menu driven and will repeat presenting the menu and
processing choices until the user selects the fourth option to
quit.
If the user selects an invalid option, an appropriate error message
should be displayed.
If the user selects to print all contacts to the screen with no
stored contacts, an appropriate error message should be
displayed.
You may use message dialogs or make it a purely console-based application
In: Computer Science
List any 5 Unix commands with their brief description.
In: Computer Science
You will extend last week's workshop activity by adding a Player class. Each player has a number of Pokemons, and the player can select one of his or her Pokemon to play against another player's Pokenmon. The player who lost the battle lost his or her Pokemon to the other player.
You will be working with three.java files in this zyLab.
Complete the Player class with the following specifications:
(1) add the following three private fields
(2) add a constructor, which takes one parameter to initialize the name field. The level is initialized as 0. The constructor also creates the ArrayList.
(3) add each of the following public member methods
Complete the PokemonField.java
PokemonField.java
import java.util.Random;
import java.util.Scanner;
public class PokemonField {
public static void main(String[] args) {
Player player1 = new Player("dragonslayer");
Player player2 = new Player("voldemort");
Random random = new Random();
initialize(player1, player2);
player1.printStat();
player2.printStat();
play(random, player1, player2);
System.out.println("Game over");
player1.printStat();
player2.printStat();
}
public static boolean fight(Random random, Pokemon p1, Pokemon
p2){
double prob = (double)p1.getAttackPoints() / (p1.getAttackPoints()
+ p2.getAttackPoints());
while(p1.getHitPoints() > 0 && p2.getHitPoints() > 0)
{
if(random.nextDouble() < prob) {
p2.setHitPoints(Math.max(p2.getHitPoints()- p1.getAttackPoints(),
0));
}
else{
p1.setHitPoints(Math.max(p1.getHitPoints() - p2.getAttackPoints(),
0));
}
}
if(p1.getHitPoints() > 0){
System.out.println(p1.getName() + " won!");
return true;
}
else {
System.out.println(p2.getName() + " won!");
return false;
}
}
public static void initialize(Player player1, Player player2)
{
String[] pokemonNames1 = {"Butterfree", "Ivysaur", "Pikachu",
"Squirtle"};
int[] pokemonMaxHps1 = {10, 15, 20, 30};
int[] pokemonAps1 = {1, 2, 2, 3};
String[] pokemonNames2=
{"Jigglypuff","Oddish","Gloom","Psyduck","Machop"};
int[] pokemonMaxHps2 = {12, 18, 25, 27, 32};
int[] pokemonAps2 = {1, 1, 2, 2, 3};
for(int i = 0; i < pokemonNames1.length; i++) {
/*FIX(1) create a Pokemon object with the following three
arguments:pokemonNames1[i], pokemonMaxHps1[i], pokemonAps1[i]
Add the Pokemon object to the Pokemon array list in player1
Increment player1's level by 1*/
}
for(int i = 0; i < pokemonNames2.length; i++) {
/*FIX(2) create a Pokemon object with the following three
arguments:pokemonNames2[i], pokemonMaxHps2[i], pokemonAps2[i]
Add the Pokemon object to the Pokemon array list in player2
Increment player2's level by 1*/
}
}
public static void play(Random random, Player player1, Player
player2) {
Pokemon p1, p2;
int index1, index2;
Scanner scnr = new Scanner(System.in);
boolean result;
System.out.println("Let's play!");
System.out.println(player1.getName() + " choose a pokemon to
fight\nenter 1 to " + player1.getPokemons().size() + " or -1 to
stop");
index1 = scnr.nextInt();
System.out.println(player2.getName() + " choose a pokemon to
fight\nenter 1 to " + player2.getPokemons().size() + " or -1 to
stop");
index2 = scnr.nextInt();
while(index1 != -1 && index2 != -1) {
p1 = player1.getPokemons().get(index1-1);
p2 = player2.getPokemons().get(index2-1);
result = fight(random, p1, p2);
if(result) {
/*FIXME(3) p1 won, reset p2, remove p2 from player2, and add p2 to
player 1, increment player1's level by 1*/
}
else {
/*FIXME(4) p2 won, reset p1, remove p1 from player1, and add p1 to
player 2, increment player2's level by 1*/
}
System.out.println(player1.getName() + " choose a pokemon to
fight\nenter 1 to " + player1.getPokemons().size() + " or -1 to
stop");
index1 = scnr.nextInt();
System.out.println(player2.getName() + " choose a pokemon to
fight\nenter 1 to " + player2.getPokemons().size() + " or -1 to
stop");
index2 = scnr.nextInt();
}
}
}
Player.java
import java.util.ArrayList;
public class Player {
/*FIXME(1) Add three fields: name, level, pokemons*/
/*FIXME(2) Add a constructor, which takes one parameter: String
n.
Initialize name to n, level to 0, and create an ArrayList for
pokemons*/
/*FIXME (3) Define the accessor for name*/
/*FIXME (4) Define the accessor for level*/
/*FIXME (5) Define the accessor for pokemons*/
/*FIXME (6) Define the mutator for level*/
/*FIXME(7) Complete this method by adding p into the Pokemon
ArrayList*/
public void addPokemon(Pokemon p){
}
/*FIXME(8) Complete this method by removing p from the Pokemon
ArrayList*/
public void removePokemon(Pokemon p){
}
public void printStat(){
System.out.println("\nPlayer: " + name + " at level " + level + ",
has " + pokemons.size() + " pokemons");
/*FIXME(9) Complete this method by printing the stat of each
pokemon in the Pokemon ArrayList.
Each pokemon's stat is printed in an individual line. Hint: loop
through the ArrayList and call the printStat method of Pokemon
class*/
}
}
Pokemon.java
public class Pokemon {
private String name;
private int maxHp;
private int hitPoints;
private int attackPoints;
public Pokemon(String name, int maxHp, int ap) {
this.name = name;
this.maxHp = maxHp;
hitPoints = maxHp;
attackPoints = ap;
}
public String getName(){
return name;
}
public int getHitPoints() {
return hitPoints;
}
public int getAttackPoints() {
return attackPoints;
}
public void setHitPoints(int hp) {
hitPoints = hp;
}
public void setAttackPoints(int ap) {
attackPoints = ap;
}
public void reset() {
hitPoints = maxHp;
}
public void printStat() {
System.out.println(name + " has " + hitPoints + " hit points and "
+ attackPoints + " attack points");
}
}
/*FIXME(2) Add a constructor, which takes one parameter: String
n.
Initialize name to n, level to 0, and create an ArrayList for
pokemons*/
/*FIXME (3) Define the accessor for name*/
/*FIXME (4) Define the accessor for level*/
/*FIXME (5) Define the accessor for pokemons*/
/*FIXME (6) Define the mutator for level*/
/*FIXME(7) Complete this method by adding p into the Pokemon
ArrayList*/
public void addPokemon(Pokemon p){
}
/*FIXME(8) Complete this method by removing p from the Pokemon
ArrayList*/
public void removePokemon(Pokemon p){
}
public void printStat(){
System.out.println("\nPlayer: " + name + " at level " + level + ",
has " + pokemons.size() + " pokemons");
/*FIXME(9) Complete this method by printing the stat of each
pokemon in the Pokemon ArrayList.
Each pokemon's stat is printed in an individual line. Hint: loop
through the ArrayList and call the printStat method of Pokemon
class*/
}
}
In: Computer Science
This lesson's Group Activities are:
Use python and use double strings
Talk like a Pirate! In this activity you are to create an English to Pirate Translator. Users should input a phrase and your program should translate it into pirate speak. A few rules:
1. Certain words need to be converted:
2. You need to obey capitalization and punctuation: if the word is capitalized, then its translation should also be capitalized. If the sentence ends in a period, then the translation should end in a period. To keep punctuation simple, you can stick to coding for commas and periods, and ignore all the rest.
3. Pirates like the word "arr". For fun, randomly insert it into your translation.
4. Remember to use all the tools in your arsenal, especially mainline logic, functions, loops, and error handling.
In: Computer Science
C++ Programming
Convert problems 6 in to template classes, of week 5 and week 4.
Test each with Implicit int, float, double, long int.
Test each with explicit int, float, double, long int.
Problem 6:
//Box.h
#include<iostream>
using namespace std;
class Box
{
public:
double Length;
double Width;
double Height;
public:
//Default constructor
Box();
//Parameterized constructor
Box(double ,double,double);
//Setter methods
void setWidth ( double n ) ;
void setDepth ( double n ) ;
void setHeight ( double n );
//getter methods
double getWidth () ;
double getHeight ();
double getDepth () ;
//Methods to calculate area and volume of box
double calcArea () ;
double calcVolume () ;
};
//Box.cpp
#include <iostream>
#include "Box.h"
using namespace std;
//default constructor
Box::Box()
{
Length = 0;
Width = 0;
Height = 0;
}
//parameterized constructor
Box::Box(double l,double w, double h)
{
Length = l;
Width = w;
Height = h;
}
void Box::setWidth ( double n )
{
Width = n;
}
void Box::setDepth ( double n )
{
Length = n;
}
void Box::setHeight ( double n )
{
Height = n;
}
double Box::getWidth ()
{
return Width;
}
double Box::getHeight ()
{
return Height;
}
double Box::getDepth ()
{
return Length;
}
double Box::calcArea ()
{
return 2*(Length*(Width+Height)+Width*Height);
}
double Box::calcVolume ()
{
return Length*Width*Height;
}
------
//main.cpp
#include<iostream>
#include<string>
#include "Box.h"
using namespace std;
//start of main method
int main()
{
cout<<"Name";
string myName= "yourname";
cout<<"Name: "<<myName<<endl;
//default constructor
Box B1;
cout<<"Testing default constructor"<<endl;
cout << "Height = " << B1.getHeight() << endl;
cout << "Area = " << B1.calcArea() << endl;
cout << "Volume = " << B1.calcVolume() << endl;
//parmeter constructor
Box B2(1,2,3);
cout<<"Testing parameterized constructor"<<endl;
cout << "Height = " << B2.getHeight() << endl;
cout << "Area = " << B2.calcArea() << endl;
cout << "Volume = " << B2.calcVolume() << endl;
Box B3;
B3.setWidth(3);
B3.setDepth(5);
B3.setHeight(10);
cout<<"Testing functions "<<endl;
cout << "Height = " << B3.getHeight() << endl;
cout << "Area = " << B3. calcArea() << endl;
cout << "Volume = " << B3.calcVolume() << endl;
system("pause");
return 0;
}
In: Computer Science
Modifying the tree traversal C program shown below to do reversed tree traversal as defined below.
Reversed PreOrder: Root, Right, Left.
Reversed InOrder: Right, Root, Left.
Reversed PostOrder: Right, Left, Root.
The tree is:
Root = 1, Left(1) = -2, Right(1) = -3;
Left(-2) = 4, Right(-2) = 5;
Left(-3) = 6, Right(-3)= 7;
Left(5) = -8, Right(5)= -9;
Left(7) = 10, Right(7) = 11;
Left(11) = -12, Right(11) = -13;
Left(-13) = 14.
Your program should output the printed sequence of node IDs (positive or negative) according to the required order.
Code:
// C program for different tree traversals
#include <stdio.h>
#include <stdlib.h>
/* A binary tree node has data, pointer to left child
and a pointer to right child */
struct node
{
int data;
struct node* left;
struct node* right;
};
/* Helper function that allocates a new node with the
given data and NULL left and right pointers. */
struct node* newNode(int data)
{
struct node* node = (struct node*)
malloc(sizeof(struct
node));
node->data = data;
node->left = NULL;
node->right = NULL;
return(node);
}
/* Given a binary tree, print its nodes according to the
"bottom-up" postorder traversal. */
void printPostorder(struct node* node)
{
if (node == NULL)
return;
// first recur on left subtree
printPostorder(node->left);
// then recur on right subtree
printPostorder(node->right);
// now deal with the node
printf("%d ", node->data);
}
/* Given a binary tree, print its nodes in inorder*/
void printInorder(struct node* node)
{
if (node == NULL)
return;
/* first recur on left child */
printInorder(node->left);
/* then print the data of node */
printf("%d ", node->data);
/* now recur on right child */
printInorder(node->right);
}
/* Given a binary tree, print its nodes in preorder*/
void printPreorder(struct node* node)
{
if (node == NULL)
return;
/* first print data of node */
printf("%d ", node->data);
/* then recur on left sutree */
printPreorder(node->left);
/* now recur on right subtree */
printPreorder(node->right);
}
/* Driver program to test above functions*/
int main()
{
struct node *root = newNode(1);
root->left
= newNode(2);
root->right =
newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printf("\nPreorder traversal of binary tree is
\n");
printPreorder(root);
printf("\nInorder traversal of binary tree is
\n");
printInorder(root);
printf("\nPostorder traversal of binary tree is
\n");
printPostorder(root);
getchar();
return 0;
}
In: Computer Science
Based on the question below, construct an outline of two body paragraphs. Write your outline in complete sentences.
The mass media, which includes television, radio, newspapers or social networking sites, plays an important role in society. What are the positive effects of mass media on today’s generation?
Explain your views by providing two effects.
Thesis statement:
___________________________________________________________________
Body Paragraph 1
Topic Sentence:
___________________________________________________________________
Supporting Sentences:
1. ___________________________________________________________________
2. ___________________________________________________________________
Concluding Sentence:
___________________________________________________________________
Body Paragraph 2
Topic Sentence:
___________________________________________________________________
Supporting Sentences:
1. ___________________________________________________________________
2. ___________________________________________________________________
Concluding Sentence:
___________________________________________________________________
In: Computer Science
The program you will be writing displays a weekly payroll report. A loop in the program should ask the user for the employee's number, last name, worked hours, hourly pay rate, state tax and federal tax rate. After data in entered and the user hits the enter key, the program will calculate gross an net pay, then displays all employee's payroll information, and ask for the next employees' information. if worked hour is more than 40, double pay the hours worked more than 40 hours.
In the program, after done first employee, display "would you like to enter next employee's information?"
if the user type "y", "Y", "YES", "Yes", "YEs", "yES", "yeS", the program should prompt for second employee info entry.
if the user type "n", "N", "No","NO", nO", "no", the program should exit.
Need the code in Java (I have struggle in the big loop when asking input second employee's info or not).
In: Computer Science