I. Design and code a class Rectangle that has the following properties:
Two private members double length and width
A constructor that accepts two parameters for the private members
Default constructor that sets both members to 0
Setters/getters for each private member
Method area() that returns the area of the rectangle
Method Perim() that returns the perimeter of the rectangle
Method toString that return the param as a String
Method Add that accepts a Rectangle and returns a rectangle with the length as sum of lengths of this and the input rectangle and the width as the sum too.
Method equals() that accepts a rectangle and returns true if the two rectangles are the same and false if not.
II. Design a Class Cube that has the following:
Private member Rectangle
Private member height.
A constructor that accepts three double (length, width, height)
Setters getters
Method volume that returns the volume of the cube which is the area of the rectangle multiplied by the height
Method toString() that returns the length, width and height as a string
Method equals that accepts another Cube and returns true if the two cubes are the same and false if not. Use the equals in Rectangle.
Method Cube add(Cube C) that returns the sum of the Cube this
In: Computer Science
absorption refection scattering refraction and diffraction can all have an impact on RF signal strength. Identify at least three objects or types of materials in each of the five categories that can impact rf signals. Next research how much the impact is in terms of loss either DBm or mW.
In: Computer Science
This is my code I need to complete it?
//The code
package arraylists;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
*
*/
public class SoftOpening {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList foodList = generateMenu();
User user = generateUser(input);
user.introduce();
userBuyFood(foodList, user, input);
user.introduce();
}
public static ArrayList generateMenu(){
ArrayList foodList = new ArrayList<>();
Food pizza1 =new Food(1,"pizza","Seafood",11,12);
Food pizza2 =new Food(2,"pizza","Beef",9,10);
Food Friedrice =new Food(3,"fried rice","Seafood",5,12);
Food Noodles =new Food(4,"noodles","Beaf",6,14);
foodList.add(pizza1);
foodList.add(pizza2);
foodList.add(Friedrice);
foodList.add(Noodles);
return foodList ;
}
public static void getMenu(ArrayList foodlist){
for (int i =0;i
System.out.println(foodlist.get(i));
}
}
}
Q1: generateUser(Scanner in) that generates a user whose account
and money are added by using the Scanner parameter. ?
Q2: userBuyFood(ArrayList, User user, Scanner in) to invoke the getMenu(), ask the user to selects the foods in the menu, compute the cost and invoke the addExpense() from the User class?
Q3: Invoke the method introduce() of the User object to show his/her balance ?
public class Food {
private int id;
private String name;
private String type;
private int size;
private double price;
public Food(int id, String name,String type,int size,double
price){
this.id= id;
this.name= name;
this.type= type;
this.size= size;
this.price= price;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setType(String type) {
this.type = type;
}
public void setSize(int size) {
this.size = size;
}
public void setPrice(double price) {
this.price = price;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public double getPrice() {
return price;
}
public int getSize() {
return size;
}
@Override
public String toString(){
return " [Id] "+id + " [Name] "+ name+ " [Type] "+size+" [Size]
"+type+" [Type] "+price+" [Price] ";
}
}
public class FoodTest {
public static void main(String[] args) {
ArrayList foodList = new ArrayList<>();
Food pizza1 =new Food(1,"pizza","Seafood",11,12);
Food pizza2 =new Food(2,"pizza","Beef",9,10);
Food Friedrice =new Food(3,"fried rice","Seafood",5,12);
Food Noodles =new Food(4,"noodles","Beaf",6,14);
foodList.add(pizza1);
foodList.add(pizza2);
foodList.add(Friedrice);
foodList.add(Noodles);
for (int i =0;i
System.out.println(foodList.get(i));
}
}
}
--------------
package arraylists;
import java.util.Scanner;
/**
*
*
*/
public class User {
private String accountName;
private String password ;
private double money;
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public void setPassword(String password) {
this.password = password;
}
public void setMoney(double money) {
this.money = money;
}
public String getAccountName() {
return accountName;
}
public String getPassword() {
return password;
}
public double getMoney() {
return money;
}
public void introduce() {
System.out.println(" The account Name is "+accountName+" The balance is "+money+" $ ");
}
public void addExpense(double value, Scanner in){
if (value > money)
System.out.println(" Plan to expence "+value+" $ but no sufficient ");
else {
System.out.println(" Plan to expence "+value+" $ ");
System.out.println(" please enter password ");
String password1 = in.nextLine();
if (password.equals(password1))
{
money =money-value;
System.out.println(" expence "+value+" $ and balance "+money+" $ ");
}
}
}
public void addMoney(double value){
money += value;
System.out.println(" Got "+value+" $ as income , balance is "+money+" $ ");
//System.out.println(accountName+"has a balance of "+money);
}
}
In: Computer Science
Question 1: What is For Loop? Explain with 2 Examples. You can write code in any programming language.
In: Computer Science
I have a problem with my code. It does not run. Please can someone check the code and tell me where I went wrong?
This is the question:
Program Specification: Write a C program that takes the length and width of a rectangular yard, and the length and width of a rectangular house (that must be completely contained in the yard specified) as input values. Assuming that the yard has grass growing every where that the house is not covering, and you own a lawn mower can mow one square foot per second, on average. Compute the time (in minutes) needed to mow the yard.
Requirements: 1. Use conditional logic to display an error message (instead of erroneous output) only if neither the specified house nor the same house rotated 90 degrees does not fit on the specified yard. 2. Otherwise - display all of the user’s inputs and the computed result in a reasonable report like format.
This is the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float Length_y;
float Width_y;
float Length_h;
float Width_h;
float Area_y;
float Area_h;
float Area_G;
float Time;
printf("Enter the length of the yard: \n");
scanf("%f", &Length_y);
printf("Enter the width of the yard: \n");
scanf("%f", &Width_y);
printf("Enter the length of the house: \n");
scanf("%f", &Length_h);
printf("Enter the width of the house: \n");
scanf("%f", &Width_h);
if
((Length_h>=Length_y)||(Width_h>=Width_y))
{
Length_h= Width_h;
Width_h= Length_h;
Area_y= Length_y*Width_y;
Area_h= Length_h*Width_h;
Area_G= Area_y-Area_h;
Time= Area_G/60;
printf("Length of the yard is %f
\n", Length_y );
printf("Width of the yard is %f
\n", Width_y );
printf("Length of the house is %f
\n", Length_h );
printf("Width of the house is %f
\n", Width_h);
printf("Area of the yard is %f \n",
Area_y);
printf("Area of the house is %f
\n", Area_h);
printf("Area with grass is %f \n",
Area_G);
printf("Time to mow lawn is %f \n",
Time);
}
else
{
printf("House does not fit in
yard.\n");
}
return 0;
}
In: Computer Science
//This is an ArrayReverser Problem..
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read in the list of numbers
int[] numbers;
String input = sc.nextLine();
if (input.equals("")) {
numbers = new int[0];
} else {
String[] numberStrings = input.split(" ");
numbers = new int[numberStrings.length];
for (int i = 0; i < numberStrings.length; i++) {
numbers[i] = Integer.parseInt(numberStrings[i]);
}
}
// Reverse the list
int[] resultArray = reverseArray(numbers);
// Print the reversed list
StringBuilder resultSb = new StringBuilder();
for (int i = 0; i < resultArray.length; i++) {
resultSb.append(new Integer(resultArray[i]).toString());
if (i < resultArray.length - 1) {
resultSb.append(" ");
}
}
System.out.println(resultSb.toString());
}
public static int[] reverseArray(int[] originalArray) {
// TODO implement this function
throw new UnsupportedOperationException();
//put code here
}
}
//Thanks.
In: Computer Science
Question 2: How can we find the real root of a polynomial with one variable? Also discuss the Newton-Raphson method.
In: Computer Science
you may not use the Python ord() or chr() functions
you may not use the Python ord() or chr() functions
you may not use the Python ord() or chr() functions
You will write a total of four functions, each of which will take two inputs and return a string:
The first argument will be a string containing the plaintext (or clear text) message to be encrypted for the two encrypt functions, and a string containing a ciphertext to be decrypted. The second argument will be the key.
For this assignment, you will always leave all characters in plaintext or ciphertext that are not letters (i.e., spaces and punctuation marks) unchanged.
Plaintext message letters may be either upper or lower case, but you should output only upper case ciphertext.
Remember the string function upper() you used in lab.
Note that you are writing two functions for each cryptosystem, an encrypt and a decrypt, so one partial test of the correctness of your work is whether first encrypting and then decrypting returns the original string (except that you may have converted some lower case letters to upper case).
Caesar Cipher
Caesar part of the homework: Write c_encrypt() and c_decrypt(), both of which take two arguments, the first one a string and the second one an integer key.
Both should return a string.
This will be much easier if both functions use the cencrypt() shift function you wrote for the lab.
As with the lab, you may not use the Python ord() or chr() functions
Vigenère Cipher
The Vigenère Cipher was more or less completely unbreakable from its introduction sometime in the 1500s until well into the 1800s.
The key in Vigenère is a key word that is used over and over again to give a different key to the Caesar cipher for each letter of the encryption (and decryption), with 'A', in good Python form, representing a rotation of 0. (We Pythonistas start at 0, not 1!)
So if the key is ABACUS, then we encrypt:
Back in the 1800s people wanting to use this system would make use of a Vigenère square, also known as the tabula recta, shown in the middle of the Wikipedia entry for the Vigenère cipher, but we can use Python.
Vigenère part of the homework: Write vig_encrypt() and vig_decrypt() functions. Each takes two strings as inputs, with the first being the plaintext/ciphertext, and the second being the key. Both should be calling functions you wrote earlier to help make the work easier.
The key will be a string consisting only of letters, but the letters might be in upper, lower, or mixed case. Important: If the plaintext to be encrypted has non-alphabetic characters (e.g., spaces or punctuation):
One check on your work: vig_encrypt('ATTACKATDAWN', 'LEMON') should return the string LXFOPVEFRNHR; another is that vig_encrypt('Hi Mom!', 'LEMON') should return the string SM YCZ!
you may not use the Python ord() or chr() functions
you may not use the Python ord() or chr() functions
you may not use the Python ord() or chr() functions
In: Computer Science
Question 3: What is Function? Explain with examples. Provide at least 2 program examples.
In: Computer Science
C++ programming interest using for loops.
I'm fairly new to C++ programming. I really don't get for loops, and wanted help with this question. How do I go about it?
1a.
Write a program to ask the user for the starting balance of their savings account, what interest rate they are earning, and how many years they are planning to keep the account open. To calculate the new balance, including compounded interest: use a for loop to loop through the number of years the user specifies (1, 2, 3, 4, … years) and each time through the loop update the account balance using the following formula:
balance = balance * (1 + interest rate / 100.0) //
this adds one year’s interest to the account
balance = initialBalance * (1 + interest rate / 100.0) // this will
only calculate one year’s interest no matter how
many times you repeat it.
1b.
Now write the code to show the user how much money they would have after ONE year, depending on the different interest rates. Ask the user for a minimum and maximum interest rate (e.g. 3.0 and 8.5 … note you may need to swap the values if the user enters them out of order). Use a for loop to loop through the possible interest rates at 0.5 increments (3.0, 3.5, 4.0, 4.5, … 8.5) and each time through the loop calculate the user’s account balance after one year at the specified interest rate:
balance = initialBalance * (1 + interest rate / 100.0) // this time you want the initial balance
In: Computer Science
Write a class encapsulating the concept of a student, assuming a student has the following attributes: a name, a Social Security number, and a GPA (for instance, 3.5). Include a constructor, the accessors and mutators, and methods toString and equals. Write a client class (test driver with main method) to test all the methods in your class (create 2 student objects, print the name, social security number and GPA of the 2 students, check if the two student’s GPA is the same or equal, change the name of the first student).
In: Computer Science
FOR JAVA (ZYBOOK) Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}.
I can't modify/change any of the code. I can only add code to implement this where it says /* Your solution goes here */.
This is the code:
import java.util.Scanner;
public class ModifyArray {
/* Your solution goes here */
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int numElem = 4;
int[] sortArray = new int[numElem];
int i;
int userNum;
for (i = 0; i < sortArray.length; ++i) {
sortArray[i] = scnr.nextInt();
}
swapArrayEnds(sortArray);
for (i = 0; i < sortArray.length; ++i) {
System.out.print(sortArray[i]);
System.out.print(" ");
}
System.out.println("");
}
}
In: Computer Science
You are the IT director at Big Ten University. As part of a training program, you decide to draw a DFD that includes some obvious mistakes to see whether your newly hired junior analysts can find them. You came up with the diagram 0 DFD shown in Figure 5-19. Based on the rules explained in this chapter, how many problems should the analysts find?
In: Computer Science
A cubic polynomial is of the form: f(x) = Ax^3 + Bx^2 + Cx + D
A root of the polynomial is a value, x, such that f(x)=0.
Write a program that takes in the coefficients of a cubic polynomial: A, B, C, and D. The program finds and reports all three roots of the polynomial.
Hint: First use bisection method to determine a single root of the polynomial. Then divide the polynomial by its factor to come up with a quadratic equation. You may use the procedure described here: https://www.purplemath.com/modules/synthdiv.htm. Subsequently, solve the quadratic equation.
The code should be written in python.
In: Computer Science
In Java
The Problem
In his book Irreligion, the mathematician John Allen Paulos tells an amusing story about the Dutch astronomer Cornelis de Jager, "who concocted the following algorithm for personalized physical constants, [and] used it to advance a charming theory about the metaphysical properties of Dutch bicycles." First select any positive real-valued universal physical or mathematical constant that seems interesting to you, e.g., π, e, Planck's constant, the atomic weight of molybdenum, the boiling point of water in Kelvin, whatever you like. Call this constant μ. Then select any four positive real numbers not equal to 1 that have personal meaning to you, e.g., your favorite number, day or month or year of birth, age in fortnights or seconds, weight in stones or grams, height in furlongs or millimeters, number of children, house number, apartment number, zip code, last four digits of SSN, whatever you like. Call these four personal numbers w, x, y, and z.
Now consider the de Jager formula waxbyczd, where each of a, b, c, and d is one of the 17 numbers {-5, -4, -3, -2, -1, -1/2, -1/3, -1/4, 0, 1/4, 1/3, 1/2, 1, 2, 3, 4, 5}. The "charming theory" asserts that the de Jager formula with your four personal numbers can be used to approximate μ within a fraction of 1% relative error. For example, suppose you choose to approximate the mean distance from the earth to the moon in miles: μ = 238,900. And suppose you are an OSU sports fan, so your personal numbers are the number of wins in OSU's last national championship season (14), the seating capacity of Ohio Stadium (102,329), the year of Jesse Owens' four gold medals in Berlin (1936), and your jersey number when you played high school field hockey (13). Then the value of 14-5102329119361/2134 is about 239,103, which is within about 0.08% of μ.
Your job is to create a Java program that asks the user what constant μ should be approximated, and then asks in turn for each of the four personal numbers w, x, y, and z. The program should then calculate and report the values of the exponents a, b, c, and d that bring the de Jager formula as close as possible to μ, as well as the value of the formula waxbyczd and the relative error of the approximation to the nearest hundredth of one percent (see SimpleWriter print(double, int, boolean) for a method you may find useful for this). Note that your program must find the combination of exponents that minimizes the error of the approximation of μ and then print the exponents, best approximation, and corresponding relative error. (Essentially this program could be used to disprove the "charming theory" by finding μ, w, x, y, and z such that the best approximation of μ results in a relative error that is greater than 1%.)
Method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/** * Repeatedly asks the user for a positive real number until the user enters * one. Returns the positive real number. * * @param in * the input stream * @param out * the output stream * @return a positive real number entered by the user */ private static double getPositiveDouble(SimpleReader in, SimpleWriter out) {...}
/** * Repeatedly asks the user for a positive real number not equal to 1.0 * until the user enters one. Returns the positive real number. * * @param in * the input stream * @param out * the output stream * @return a positive real number not equal to 1.0 entered by the user */ private static double getPositiveDoubleNotOne(SimpleReader in, SimpleWriter out) {...} |
In: Computer Science