Java
Q: Create a program that will ask the user to enter a string Your task is replace the elements in the…
A: Hello Student. Warm welcome from my side. Hope you are doing great. I will try my best to answer…
Q: 1. What is wrong with the following condition? Correct it. if (grade > 70 || grade <= 80)
A: Conditions in java are used to pass through certain conditions.
Q: Clickzone Copy Center charges Php 15 for the first 10 copies, plus 0.75 per copy for the next 10…
A: The program is written in java import java.util.*;public class Main{ public static void…
Q: 2. Create a program that will display the following output using for(), while() and do-while()…
A: Import the java utility In main Class declare the variables m and n Get the m and n value from the…
Q: If class Apple extends class Fruit, which of the following is also true? O Fruit is the super class…
A: Correct Answer: - All of the above For Fruit is the super class of Apple It is correct because…
Q: You run four computer labs. Each lab contains computer stations that are numbered as shown in the…
A: JAVA PROGRAM: //Import the required package.import java.util.*; //Define the class.public class LAB…
Q: 1. Write a nested loop that displays 15 rows of '*' characters. There should be 30.'*' characters in…
A: As per the requirement program first program is developed. Note: As per our guidelines we are…
Q: Input: Operation to be made N number of inputs based on the operation Output: The calculator should…
A: First print all the menus. Read the choice of user and store in a character variable. If choice is…
Q: Software Requirements: Latest version of NetBeans IDE • Java Development Kit (JDK) 8 Procedure: 1.…
A: Program: import java.util.*;import java.io.*; public class Main{ public static void main(String[]…
Q: Draw a flowchart to sum the even numbers between 0 and 59.
A: Initialize a variable sum to zero.Iterate through numbers from 0 to 59.For each number, check if it…
Q: 1. Create a program that will display the following output using for(), while() and do-while()…
A: public class pattern { public static void main(String[] args) // main function {…
Q: Construct a class named TestCirde whose main() method dedares THREE (3) Cirde objects. Using the…
A:
Q: Write an application that catches and throws an ArithmeticException when you attempt to take the…
A:
Q: Create a program that will compute for the area and perimeter of a rectangle using classes. You must…
A: length and width will be the variables of Rectangle class getArea() and getPerimeter() will be the…
Q: 15.7 (Telephone-Number Word Generator) Standard telephone keypads contain the digits zero through…
A: Introduction Inheritance: Inheritance is a crucial OOP concept (Object-Oriented Programming). The…
Q: Question Print Daily Company (PDC) needs a program that displays weekly salary. PDC has five…
A: Code with the OOP approach in JAVA is given below along with output
Q: Create a program that will ask the user to enter the elements of a 3 x 4 matrix. Your task is to…
A: Algorithm: Start Read a 3×4 matrix 'a' Initialize sum to 0 and count to 0 Iterate through the…
Q: The lucky number is the sequence number generated by the filter algorithm: if the number in the…
A: Step 1: Generate a list from 1 to size. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,…
Q: Write an application that displays the multiplication table for numbers from 1 to 9. The table…
A: Java code: public class Main { //class public static void main(String[] args) { //main…
Q: Java programming
A: Program: //import the header file import java.util.Scanner; import java.text.DecimalFormat;…
Q: 10.14 (Project: Shape Hierarchy) Implement the Shape hierarchy shown in Fig. 9.3. Each Two-…
A: Solution: Given,
Q: Every cylinder has a base and height, where the base is a circle. Design the class Cylinder that can…
A: Actually, java is a object oriented programming language. It is a platform independent.
Q: Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid, as…
A: import java.util.*;import java.lang.*;import java.io.*; class Codechef{ public static void main…
Q: In this chapter, the class Date was designed to implement the date in a program, but the method…
A: /* Java program to test class */ public class Date { // Instance variables int day;…
Q: Every circle has a center and a radius. Given the radius, we can determine the circle's area and…
A: public class Point{ double x, y;public Point(){setPoint( 0, 0 );}public Point(double x, double y…
Q: Write a method with the following header that returns a pentagonal number: public static int…
A: The nth pentagonal number pn is given by the formula: pn = (3n2 - n) / 2 for n >= 1.
Q: Implement a program that can input an expression in postfix notation (see Exer- cise C-6.19) and…
A: The program is written in Java. Check the program screenshot for the correct indentation. Please…
Q: FOR ALL PARTS, MAKE SURE YOUR METHODS ARE STATIC O PART 1: Method with Output O Define a method…
A: class MethodPractice{ public static void printHelloworld() {…
Q: Given the following: public class Beta extends Alpha{ Java syntax requires class Beta to have a…
A: False
Q: Write a method LinkedList joinLists (LinkedList list1, LinkedList list2) to join two linked lists…
A: Solution: Java code: import java.util.*; public class Test { /** * This method take two…
Q: Create a folder named LastName_FirstName in your local drive. (ex. Reyes_Mark) Using NetBeans,…
A: The program is written in Java. Please find the source code and output in the below steps.
Q: In this exercise, you will design various classes and write a program to computerize the billing…
A: Actually, java is a object oriented programming language. It is a platform independent.
Q: 14.13 (Tokenizing and Comparing Strings) Write an application that reads a line of text, tokeniz- es…
A: Code Sample Output
Step by step
Solved in 2 steps
- function myChoice(items) {if (!this.value && !this.items) {this.items = items[0];} else if (!this.value || (params.length > 0 && params[0] == "rechoose")) {let index = Math.floor(Math.random() * (this.items.length - 0)) + 0;this.value = this.items[index];return this.value;}return this.value;} var a = myChoice([1, "a", 3, false]);console.log(myChoice(3, 12));console.log(myChoice(51, -2));console.log(myChoice("happy", false));console.log(myChoice([1, 2, 3]));console.log(myChoice("rechoose"));console.log(myChoice(a, a)); these are directions and examples myChoice( items ) This function accepts a list of items as input and creates a function that returns a randomly-chosen item. After choosing a random item, that same item will be always be returned, regardless of the functions input, with one exception. If the first input is the string 'rechoose', then a new random item will be chosen and therafter returned. this is KEYYYY!! Examples var a = myChoice( [1, "a", 3, false]…let petsData = ; let categories = ['Length', 'Height', 'Weight']); let canvasWidth = 800; let canvasHeight = 600; function setup()) { createCanvas(canvasWidth, canvasHeight); // Generate random pet data (30 data points) for (let i = 0; i < 30; i++) { let pet = {Length: random(20, 50), Height: random(10, 30), Weight: random(5, 20)}; petsData.push(pet); } // Draw axes and labels drawAxes(); drawLabels(); // Plot data points plotData(); } function drawAxes() { // Draw X and Y axes stroke(0); line(50, canvasHeight - 50, canvasWidth - 50, canvasHeight -50); line(50, canvasHeight 50, 50, 50); } function drawLabels() { // Draw category labels textSize(16); textAlign(CENTER); for (let i = 0; i < categories.length; i++) { let x = map(1, 0, categories.length ■1, 100, canvasWidth 100); text(categories[i], x, canvasHeight - 20);}} function plotData() { // Plot data points as circles noStroke(); fill(66, 135, 245, 150); // Blue with transparency for (let i = 0; i < petsData.length; i++) { let x =…double tab1[5] = {2,3,4,5,6}; double tab2[5] = {6,5,4,3,2}; for(int i = 0;i<5;i++) { tab1[i] = tab1[i]*tab2[i]; cout<<tab1[i]<<" "; } 12 15 16 15 16 15 15 16 15 12 12 15 16 15 12 12 15 12 15 12
- 1. An array is a container that holds a group of values of a 2. Each item in an array is called an 3. Each element is accessed by a numerical 4. The index to the first element of an array is 0 and the index to the last element of the array is the length of the 5. Given the following array declaration, determine which of the three statements below it are true. int [] autoMobile = new int [13]; i. autoMobile[0] is the reference to the first element in the array. ii. autoMobile[13] is the reference to the last element in the array. ii. There are 13 integers in the autoMobile array. 6. In java new is a which is used to allocate memory 7. Declare a one-dimensional array named score of type int that can hold9 values. 8. Declare and initialize a one-dimensional byte array named values of size 10 so that all entries contain 1. 9. Declare and initialize a one-dimensional array to store name of any 3 students. 10. Declare a two-dimensional array named mark of type double that can hold 5x3…For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a comma (no spaces). Ex: If the input is: 32 105 101 35 10 20 30 40 the output is: 20,30, 1 #include 2 3 int main(void) { const int SIZE_LIST = 4; int keysList[SIZE_LIST]; int itemsList[SIZE_LIST]; int i; 4 6 7 8 scanf("%d", &keysList[0]); scanf ("%d", &keysList[1]); scanf("%d", &keysList[2]); scanf("%d", &keysList[3]); 10 11 12 13 scanf ("%d", &itemsList[0]); scanf ("%d", &itemsList[1]); scanf("%d", &itemsList[2]); scanf ("%d", &itemsList[3]); 14 15 16 17 18 19 /* Your code goes here */ 20 21 printf("\n"); 22 23 return 0; 24 }X42: frontPiece Given an int array of any length, return a new array of its first 2 elements. If the array is smaller than length 2, use whatever elements are present. Examples: frontPiece ({1, 2, 3}) -> {1, 2} frontPiece ({1, 2}) -> {1, 2} Your Answer: Feedback Your feedback will appear here when you check 1 public int[] frontPiece(int[] nums) 2 { your answer. 3 4 }
- Shift Left k Cells Consider an array named source. Write a method/function named shiftLeft( source, k) that shifts all the elements of the source array to the left by 'k' positions. You must execute the method by passing an array and number of cells to be shifted. After calling the method, print the array to show whether the elements have been shifted properly. Example: source=[10,20,30,40,50,60] shiftLeft(source,3) After calling shiftLeft(source,3), printing the array should give the output as: [ 40, 50, 60, 0, 0, 0 ]!!int a[ 10] = {1,5,3,8,4,2,6,9,7}; int *p; p = &a[2]; p[0] = 10; p[1] = 15; What are the values of a? Select one: O a. {10,15,3,8,4,2,6,9,7} O b. {1,15,10,8,4,2,6,9,7} O c. {1,5,10,15,4,2,6,9,7} O d. {1,10,15,8,4,2,6,9,7}
- Below is code which defines and creates an Array, myList: int [] myList = new int [5]; //define and create The loop below stores the values 1 to 5 in myList: for (int i = 0; i< 5; i++) { myList [i] =i+1; //store values using a loop The loop below prints the values from first to last in myList: for (int i = 0; i< myList.length; i++) { System.out.print(myList [i]+""); The code below is used to get user from the user and calculate the sum: import java.util."; public class WhileWithInput { public static void main(String[] args) { Scanner reader = new Scanner (System.in); int count = 1; double total = 0; while (count <= 5) { System.out.println("Enter a decimal number"); double number = reader.nextDouble(); total = total + number; count = count + 1; System.out.printlin("The total is "+ total); } System.out.println("The total is "+ total); } 1 CPS 2231 Chapter 7- lab 2 Fall 2019 Use the examples on page 1 to complete the lab below. Please submit a screen print of the Eclipse editor showing…interface IResit { int row = 5; int col = 3; int upperBound = 10; public int[][] initTable(); // initialize 5x3 table with random (upper bound is:10) integer // numbers. “table” is class variable public int[] convertTwoToOne(int[][] a); // convert a two dimensional array into one dimensional // array /* * for example: * a= 1 3 5 * 6 9 -6 * 2 7 4 * * Your method should return: * 4 7 2 -6 9 6 5 3 1 * */ public double averageOfOddElements(int[] a); public double averageOfEvenElements(int[][] a); }// end of the interface /* Write a class that implements the given interface above. 1. Your class should have two constructors: 1. Default constructor: In this case, row, column and upper bound are same as the data that defined in the interface. 2. Overloaded constructor: in this case it should get three parameters, row, column, upper bound respectively. 2. Your constructor parameters are…Doctor -signature:String -doctorID:int - medicine:Arraylist +Doctor(signature:String,doctorID:int) +PrescribeMedicine():void + salary () +checkRecords():void Medicine Pharmacist -medName:String -startTime:int -dosage :int -endTime:int -date_prescribed:int - medicine:Arraylist +Medicine(medName:String,-dosage :int,date_prescribed:int) +Pharmacist (startTime:int,endTime:int) +checkForConflict():double +confirm_prescription():String +getStartTime():int +getEndTime():int +setStartTime(time:int):void +setEndTime(time1:int).void