I have one error and it encounters my split array and it should
output true or false
public class Main
{
private static int[] freq;
static boolean doubleOrNothing(int[] array, int size, int
i)
{
if (size <= 1)
return false;
if (2 * array[i] == array[i+1])
return true;
return doubleOrNothing(array, size - 1, i++);
}
/**
*
* @param word
* @param sep
*
*
* @param count
* @return
*/
public static String wordSeparator(String word, String sep, int
count)
{
if (count <= 0)
return "";
String new_word="";
if (count == 1)
return word;
return word + sep + wordSeparator(word, sep, count - 1);
}
static boolean mcNuggetNumber(int n) //checks for 3 or 7 piece
chicken nugget
{
boolean l = false, r = false;
if (n == 3 || n == 7)
return true;
if (n >= 3)
l = mcNuggetNumber(n - 3);
if (n >= 7)
r = mcNuggetNumber(n - 7);
return l || r;
}
static boolean splitArray(int arr[], int n, int k)
{
// An odd length array cannot be divided into pairs
if (n == 1)
return false;
// Create a frequency array to count occurrences
// of all remainders when divided by k.
// map freq = null;
// Count occurrences of all remainders
for (int i = 0; i < n; i++)
freq[arr[i] % k]++;
// Traverse input array and use freq[] to decide
// if given array can be divided in pairs
for (int i = 0; i < n; i++)
{
// Remainder of current element
int rem = arr[i] % k;
// If remainder with current element divides
// k into two halves.
if (2 * rem == k)
{
// Then there must be even occurrences of
// such remainder
if (freq[rem] % 2 != 0)
return false;
}
// If remainder is 0, then there must be two
// elements with 0 remainder
else if (rem == 0)
{
if (1 & freq[rem])
{
return false;
}
else
{
}
}
// Else number of occurrences of remainder
// must be equal to number of occurrences of
// k - remainder
else if (freq[rem] != freq[k - rem])
return false;
}
return true;
}
public static void main(String[] args) {
int a1[] ={1};
int a2[] = { 1,2 };
int a3[] = { 0,0,1 };
int a4[] = { 2,3,4 };
int a5[] = { 1,3,5,10 };
int a6[] = { 1,3,5,11 };
int a7[] = { 9,8,7,6,5,4,3,2,1 };
int a8[] = { 9,8,7,6,12,4,3,2,1 };
int i1[] = { 7 };
int i2[] = { 3,4 };
int i3[] = { 3,4,5 };
int i4[] = { 9,10,11 };
int o1[] = { 3,4 };
int o2[] = { 2,3,4 };
int o3[] = { 3,4,5,6 };
int o4[] = { 1,2,3,4,5,6 };
int s1[] = { 2, 2 };
int s2[] = { 2, 3 };
int s3[] = { 5, 2, 3 };
int s4[] = { 5, 2, 2 };
int s5[] = { 1, 1, 1, 1, 1, 1 };
int s6[] = { 1, 1, 1, 1, 1 };
int s8[] = { 1 };
int s9[] = { 3, 5 };
int s10[] = { 5, 3, 2 };
int s11[] = { 2, 2, 10, 10, 1, 1 };
int s12[] = { 1, 2, 2, 10, 10, 1, 1 };
int s13[] = { 1, 2, 3, 10, 10, 1, 1 };
System.out.println("Jones Robert ");
System.out.println("Assignment 3");
System.out.println("Recursion.");
System.out.println("All calls must result in true or
false.");
System.out.println();
System.out.println("Double Or Nothing." );
System.out.println("1. " + doubleOrNothing(a1, 1,0) );
System.out.println( "2. " + doubleOrNothing(a2, 2,0) );
System.out.println("3. " + doubleOrNothing(a3, 3,0) );
System.out.println("4. " + doubleOrNothing(a4, 3,0));
System.out.println("5. " + doubleOrNothing(a5, 4,0) );
System.out.println("6. " + doubleOrNothing(a6, 4,0) );
System.out.println("7. " + doubleOrNothing(a7, 9,0) );
System.out.println("8. " + doubleOrNothing(a8, 9,0) );
System.out.println();
System.out.println();
System.out.println("Word Separator.");
System.out.println("1. " + wordSeparator("Y", "X", 4));
System.out.println("2. " + wordSeparator("Y", "X", 2));
System.out.println("3. " + wordSeparator("Y", "X", 1));
System.out.println("4. " + wordSeparator("Y", "X", 0));
System.out.println();
System.out.println("McNugget Numbers" );
System.out.println(" 1. " + mcNuggetNumber(0));
System.out.println(" 2. " + mcNuggetNumber(1) );
System.out.println(" 3. " + mcNuggetNumber(2) );
System.out.println(" 4. " + mcNuggetNumber(3) );
System.out.println(" 5. " + mcNuggetNumber(4) );
System.out.println(" 6. " + mcNuggetNumber(5) );
System.out.println(" 7. " + mcNuggetNumber(6) );
System.out.println(" 8. " + mcNuggetNumber(7) );
System.out.println(" 9. " + mcNuggetNumber(8) );
System.out.println("10. " + mcNuggetNumber(9) );
System.out.println("11. " + mcNuggetNumber(10) );
System.out.println("12. " + mcNuggetNumber(11) );
System.out.println("13. " + mcNuggetNumber(12) );
System.out.println("14. " + mcNuggetNumber(13));
System.out.println("15. " + mcNuggetNumber(14));
System.out.println("16. " + mcNuggetNumber(15));
System.out.println("17. " + mcNuggetNumber(16));
System.out.println();
System.out.println ("Split the Array");
System.out.println ("1. " + splitArray (1));
System.out.println ("2. " + splitArray (2));
System.out.println ("3. " + splitArray (3));
System.out.println ("4. " + splitArray (4));
System.out.println ("5. " + splitArray (5));
System.out.println ("6. " + splitArray (6));
System.out.println ("7. " + splitArray (7));
System.out.println ("8. " + splitArray (8));
System.out.println ("9. " + splitArray (9));
System.out.println ("10. " + splitArray (10));
System.out.println ("11. " + splitArray (11));
System.out.println ("12. " + splitArray (12));
System.out.println ("13. " + splitArray (13));
System.out.println ("14. " + splitArray (14));
System.out.println ("15. " + splitArray (15));
System.out.println ("16. " + splitArray (16));
System.out.println();
}
private static String splitArray(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To
change body of generated methods, choose Tools | Templates.
}
}
I have an error
In: Computer Science
Consider the following schema:
Suppliers(sid, sname, address)
Parts(pid, pname, color)
Catalog(sid, pid, cost)
In a plain text file, write the following queries in SQL:
1.Find the names of all suppliers who supply a green part.
2.Find the names of all suppliers who are from Illinois.
3.Find the names of all suppliers who sell a red part costing less than $100.
4.Find the names and colors of all parts that are green or red.
In writing these (basic) queries you may make the following assumptions:
a. Each part has only
one color.
b. The cost field is a real number with two decimal places (e.g.,
100.25, 93.00).
c. The sid field in Suppliers and the sid field in Catalog refer to
the same field.
d. The pid field in Parts and the pid field in Catalog refer to the
same field.
In: Computer Science
Convert the following decimal number to eight (8) binary bits: 21, 200, 105, 144, 183, 199, 88, 100, 19, 204
In: Computer Science
Question:
Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user to enter the name of a field (other than Date), and then outputs the highest and lowest values recorded in that field for the month of August.
The file climate_data_2017_numeric.csv contains the following fields:
Expected print out output (Make sure your output looks exactly like the output shown):
Note: there are 2 space in front of the last line.
Available field names:
Minimum temperature (C)
Maximum temperature (C)
Rainfall (mm)
Speed of maximum wind gust (km/h)
9am Temperature (C)
9am relative humidity (%)
3pm Temperature (C)
3pm relative humidity (%)
Please enter a field name: Minimum temperature (C)
Statistics for field 'Minimum temperature (C)':
Min: 1.0 Max: 14.6
Dataset:
https://docs.google.com/spreadsheets/d/1MjyOSUrm2Nazo9vpan_4E6fAhQlr8Ok2PXu9c8syXqY/edit?usp=sharing
In: Computer Science
create a genetic algorithm for knapsack problem in c++
In: Computer Science
C++ requirements
All values must be read in as type double and all calculations need to be done using type double.
For part 2 you MUST have at least 4 functions, including main. The main function will be the driver of the program. It needs to either do the processing or delegate the work to other functions.
Failure to follow the C++ requirements could reduce the points received from passing the tests.
General overview
This program will convert a set of temperatures from Fahrenheit to Celsius.
Your program will be reading in three double values. The first values are starting and ending temperatures. The third value is the increment value. There is no prompt for the input. There is an error message that can be displayed. This is discussed later.
You need to display output for all of the values between the starting and ending values. First two values are temperatures in Fahrenheit. You need to display all of the values from the first temperature to the last temperature. You increment from one temperature to the next by the increment value (the third value you read in). You need to convert these temperatures to Celsius. You need to output the temperatures as both Fahrenheit and Celsius. The numbers should be 15 characters wide with 3 digits of precision and need to be in fixed format. Do not use tab characters (\t) to output the values.
For part 2 you MUST have at least 4 functions, including main. The main function will be the driver of the program. It needs to either do the processing or delegate the work to other functions.
Obviously the main function will have the same function that you have been using for all of your labs. In addition to need to have a function with the following signature:
double convert(double fahrenheit)
Other functions that you may want to have are:
A function to read in the values
A display function
A display heading function
The headings are also required (see the sample output below).
The conversion from Fahrenheit to Celsius is:
celsius = (fahrenheit - 32) / 1.8
Here is a sample run with valid input:
-30 100 20
The output would be:
Fahrenheit Celsius -30.000 -34.444 -10.000 -23.333 10.000 -12.222 30.000 -1.111 50.000 10.000 70.000 21.111 90.000 32.222
For data validation you need to make sure the first number read in is less than or equal to the second number. The third number read in must be greater than 0. If this is not the case you need to output the following message and read in three new values:
Starting temperature must be <= ending temperature and increment must be > 0.0
The above message is all one line of output.
You need to keep reading in values and outputting messages until the values are all valid.
Using the following input :
40 30 5 30 40 -5 30 40 5
We get the output:
Starting temperature must be <= ending temperature and increment must be > 0.0 Starting temperature must be <= ending temperature and increment must be > 0.0 Fahrenheit Celsius 30.000 -1.111 35.000 1.667 40.000 4.444
Depending on the value for the increment the ending temperature may not be reached. You need to display the temperatures where the value of the Fahrenheit temperature is less than or equal to the ending temperature.
Consider this input:
100.5 110.4 5
The valid output will be:
Fahrenheit Celsius 100.500 38.056 105.500 40.833
The last Fahrenheit temperature output is 105.5. The next one would have been 110.5, but this is more than the ending temperature of 100.4. This is not an error condition. The output would be as above.
Think about what other tests cases are needed? Do we cover all possible input problems or valid types of input values?
Expected output
There are eight tests. Each test will have a new set of input data. You must match, exactly, the expected output.
You will get yellow highlighted text when you run the tests if your output is not what is expected. This can be because you are not getting the correct result. It could also be because your formatting does not match what is required. The checking that zyBooks does is very exacting and you must match it exactly. More information about what the yellow highlighting means can be found in course "How to use zyBooks" - especially section "1.4 zyLab basics".
Finally, do not include a system("pause"); statement in your program. This will cause your verification steps to fail.
In: Computer Science
I have a recursive Tower of Hanoi program and would like to get the index numbers to be in correct sequence: 1,2,3,4,5,6,7. How can I do this?
Main.java
import java.io.*;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
/**There is a stack of N disks on the first of three poles (call them A, B and C) and your job is to move the disks from pole A to pole C without ever putting a larger disk on top of a smaller disk.*/
System.out.println("\nW7L1 Tower of Hanoi");
System.out.println("Program by Quang Pham\n");
char startingrod = ' ';
char endingrod = ' ';
Scanner sc = new Scanner(System.in);
System.out.println("Enter the starting rod letter (A, B, or C).");
startingrod = sc.next().charAt(0);
System.out.println("Enter the ending rod letter (A, B, C).");
endingrod = sc.next().charAt(0);
if (startingrod == endingrod)
{
System.out.println("Sorry. Starting rod and ending rod cannot be the same.");
System.out.println("Enter ending rod letter (A, B, C)");
endingrod = sc.next().charAt(0);
}
else if ((startingrod=='A' && endingrod=='C')||(startingrod=='C' && endingrod=='A'));
{
char other = (char)('A' + 'B' + 'C' - startingrod - endingrod) ;
System.out.println("OK. Starting with disks 1, 2, 3, on rod " + startingrod + "." + "\n");
System.out.println("Moves are as follows:");
int count = playHanoi (3,startingrod,other,endingrod);
System.out.println();
System.out.printf("All disks 1, 2, 3 are on rod %c.\n", endingrod);
System.out.println("All done.");
System.out.println("Took a total of " + count + " moves.");
sc.close();
System.out.println();
}
}
private static int playHanoi( int n, char from , char other, char to)
{
int index = 1;
int count = 1;
if (n == 0)
return 0;
else if(n == 1)
{
System.out.printf("%d.", index);
System.out.printf(" Move disk "+ n +" from rod %c to rod %c \n", from, to);
index++;
return count;
}
else
{
count+= playHanoi(n - 1, from, to, other);
System.out.printf("%d.", index);
System.out.printf(" Move disk " + n + " from rod %c to rod %c \n", from, to);
index++;
count+= playHanoi(n - 1, other, from, to);
index++;
return count;
}
}
}
The program is at: https://repl.it/@quangnvpham1/W7L1-Recursive-Tower-of-Hanoi-Program#Main.java .
Any help with this problem is greatly appreciated. Yours truly, Quang Pham
In: Computer Science
Python/Thonny - In an office chair store, 3 types are sold: basic, standard and luxury. In addition there are normal customers and frequent customers. The price of the chairs is: Basic $ 700.00 each Standard $ 900.00 each Luxury $ 1,500.00 each The store owner has decided to give a 20% discount to frequent customers. In addition, it has decided to apply the following wholesale discount policy to normal customers: If your purchase is> = $ 10,000 and <$ 20,000 a 10% discount if your purchase is> = $ 20,000 a 15% discount Write a program that asks the type of chair, the type of customer and the quantity to buy (suppose that only one type of chair is to be purchased) and calculate and show: the price before applying discount, the amount of money granted by discount and The total to be paid by the customer.
In: Computer Science
JAVA !!!
EX 8.1Implementing a Menu Class
Problem StatementIn this Worked Example, our task is to write a class for displaying a menu. An object of this class can display a menu such as
1) Open new account
2) Log into existing account
3) Help
4) Quit
Reimplement the Menu class of Worked Example 8.1 so that it stores all menu items in one long string. Hint: Keep a separate counter for the number of options. When a new option is added, append the option count, the option, and a newline character.
In: Computer Science
In: Computer Science
In: Computer Science
In: Computer Science
NC3A-
3.1 List three approaches to message authentication.
3.2 What is a message authentication code?
3.4 What properties must a hash function have to be useful for message authentication?
3.5 In the context of a hash function, what is a compression function
In: Computer Science
In c++
Write a function that:
In: Computer Science
We are working with a circular linked list that is referenced by a tail reference, i.e., a reference to the last node of the linked list. There is no head or size information about the linked list.
Node is declared as:
Node {
int value;
Node next;
}
There are four parts in this problem. Don't forget to deal with special cases for each part.
In: Computer Science