Programming & Computer Science Answers

C++ 9913
Python 5288
Java | JSP | JSF 3611
C 1680
C# 1362
Computer Networks 989
Algorithms 652
Databases | SQL | Oracle | MS Access 641
HTML/JavaScript Web Application 588
Other 537
Visual Basic 358
Assembler 209
Software Engineering 202
AJAX | JavaScript | HTML | PHP 166
MatLAB 150
MatLAB | Mathematica | MathCAD | Maple 124
Action Script | Flash | Flex | ColdFusion 112
UNIX/Linux Programming 89
Web Development 73
Excel 36
ASP | ASP.NET 23
Delphi | Pascal 21
Perl 16
Prolog 9
Functional Programming 9
MathCAD 5
Wolfram Mathematica 4
WPF 4
Ruby | Ruby on Rails 3
NodeJS Web Application 2

Questions answered by Experts: 26 876

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search


Learning Journal Unit 5

1. Consider the loop from Section 8.3 of your textbook.


prefixes = 'JKLMNOPQ'

suffix = 'ack'

for letter in prefixes:

   print(letter + suffix)

Put this code into a Python script and run it. Notice that it prints the names "Oack" and "Qack".

Modify the program so that it prints "Ouack" and "Quack" but leaves the other names the same.

Include the modified Python code and the output in your submission.

2. Give at least three examples that show different features of string slices. Describe the feature illustrated by each example. Invent your own examples. Do not copy them for the textbook or any other source.



Write a program that takes an integer input from the user. The program should print if the integer is positive or negative. (a) Write another program for the same purpose but the program should say if the integer is positive, negative or zero.


Write a program that asks the user to input their percentage score.The program should then print out their grade. Use the ‘char’ data type to store the value of the grade.Use the following boundaries to assign the letter grade: Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >=70% : Grade C 


Write a program to check if a student is eligible for a master’s program at UD. A person is eligible if their GPA is above 3.0. If a person is an Emirati, the minimum GPA requirement is reduced to 2.5. Write a program that asks that checks for this information. Your program should print “Person is eligible” or “Person is not eligible”. 


Write a program to check if the person is eligible to go into a musical concert. For a person to be eligible, they must be over 21, and they must have a ticket. If neither condition is satisfied, the person will not be allowed in. Your program should print “Person is eligible” or “Person is not eligible”. 


Create a class named RecipeFactory

–public static Recipe makeRecipe(String recipeType, String recipeName, HashMap<String, String> ingredients)

–public static final String (DESSERT and DINNER)

•“Dessert” and “Dinner”

•Create an abstract class named Recipe

–protected HashMap<String, String> ingredients

•Key: ingredient name

•Value: ingredient amount

–protected String name

–HashMap<String, String> getIngredients()

•Can implement here

–String getName()

•Can implement here

•Extend your abstract class in DessertRecipe and DinnerRecipe

–Override toString

•Expected output on next slide

•Use the StringBuilder class

–Implement a constructor that takes String name and HashMap<String, String> ingredients.

–Warning: assigning HashMap from constructor and memory

•new HashMap<String, String>(hashMap)

•Hint: use “\n” to add a newline and “\t” to add the tab

–Since this will go through an autograder, you must exactly match the formatting (do not add an extra \n to the very end)

•Create a singleton class named Cookbook

–private Cookbook() { }

–private ArrayList<Recipe> recipes

–void addRecipe(Recipe r)

–void clearRecipes()

–ArrayList<Recipe> getRecipes()

Cookbook getInstance()

•Create a file named FinalProject.java

•This file will contain all your code when you submit your completed project

•Both methods you work on this week should be in the public FinalProjectclass

•You can add main to this class to help you test your code

•Define a static method that can take a recipe string and convert it into the appropriate Recipe subclass object

–Remember:

•Key: ingredient name

•Value: ingredient amount

–Use your RecipeFactory to create the object

•Practice with this test string and verify your method works.

–String test = "Cake~Dessert~flour@3/4 cups#milk@3/4 cups#sugar@2/3 cups#vanilla@1 tsp";

•Define a static method called connectToServer that takes as input a String ipAddress and integer port.

•Create a socket (client) and connect to the input port

–This will be your connection to the RecipeServer

•Make sure your socket is continually reading in messages from the socket

–Pseudocode: while (input from socket != null) print out input from socket

–Use an InputStreamReader wrapped in a BufferedReader

•If you run the following code from main in FinalProject.java…

–FinalProject.connectToServer(8765);

–System.out.println(“Hello”);

•…Hello will never be printed

•Why?

•Update your connectToServermethod

•Instead of performing the connection and reading on the main thread, perform the work in a new thread.

•To test your changes, run your code from the previous slide. Hello should be print out immediately.

•Also make sure you are still able to receive messages continually from RecipeServer.

•Write the following methods in your FinalProject class.

•public static void serializeRecipe(Recipe r, String path)

–Serialize the given recipe to the path

–You should only store the following fields

•name

•ingredients

–You can serialize the object as a Recipe

•No need to check which child class was input

•public static Recipe deserializeRecipe(String path)

–Deserialize a Recipe at the given path

•Cast the returned object to Recipe

–Note: Even if you treat it as a Recipe, the data from the child class you used will be saved

•i.e. no need to cast it to the child class

•Place all your classes in your FinalProject.java file.

•Test to make sure all the code still works.

•Submit it online to the autograder.

•Here is how testing will be done:

–A server socket will await your connection

–Recipe strings will be sent over the socket

–Your Cookbook should be updated after each recipe

–All of your methods will be tested, including your RecipeFactory and Cookbook methods.

Feel free to choose you own recipe names and ingredients.

•As you receive recipes over the socket, you should create the appropriate Recipe object (using the factory) and add them to the Cookbook list.

•Test your code with the RecipeServercode. You can use 8765 as your testing port.

–Note: You will have to run the server and your code separately. You will need to test it locally.

•You should be able to continually send messages from the server and receive them from your client.

–Do not change the server code – this version will be used to test your program.




Input : the input will be a single line containing a positive integer (N).

Out put : output should be a single line containing years, weeks, days values separated by spaces

N is 1329


create java code forr class called realtor commission. fields include the sale price of a house, the house, the sales commission rate and the commission. create two constructors. each constructor requires the sales prices(expressed as double) and the commission rate. one constructor requires the commission rate to be double, such as 0.06. the other requires sale price and commission rate expressed as whole number such as 6. each constructor calculates the commission value based on the price of the house multiplied by the commission rate. the difference is that the constructor that accepts the whole number must convert it into a percentage by dividing by 100. also include display function for the fields contained in realtor commission class. write a main function that instantiate at least 2 realtor commission objects one that uses decimal and one that uses a whole number as commission rate. display the realtor commission object values.


Your program will deal the opening hand of Blackjack where there is a dealer and one player You will deal the player two cards and you will deal the dealer two cards


Polynomial

Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.Input


The first line contains a single integer N.

Next N lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes coefficient of Pi.Output


Print the polynomial in the format Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0, where Pi's are powers in decreasing order, Ci is coefficient, and C0 is constant. There will be space before and after the plus or minus sign.

If the coefficient is zero, then don't print the term.

If the term with the highest degree is negative, the term should represent -Cix^Pi.

For the term where power is 1, represent it as C1x instead of C1x^1.

If the polynomial degree is zero and the constant term is also zero, then print 0 to represent the polynomial.

For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.Explanation


If N = 4

For power 0, the coefficient is 5

For power 1, the coefficient is 0

For power 2, the coefficient is 10

For power 3, the coefficient is 6.

Then polynomial represents "6x^3 + 10x^2 + 5"Constraints


N <= 100

0 <= Pi < 1000

-1000 <= Ci <= 1000

Sample Input

Sample Output

6x^3 + 10x^2 + 5
7x^4 + 6x^3 + x^2 + 3x + 2
LATEST TUTORIALS
APPROVED BY CLIENTS