Question 6 (lab 07)
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lab07;
/**
*
* @author ckandjimi
*/
public class Lab07 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int outcome = methodX(5);
System.out.printf("Result from Method X= %d",outcome);
String [] studentNames =
{"Kingston","John","Nangula","Daniela"};
int Test01[] = {59,72,70,66};
int Test02[] = {80,65,55,49};
/**TASKS
* 1. Implement the 2 methods below assessment and highestMark
* 2. Using the 3 arrays declared above invoke or make a method call
to assessment
* 3. Invoke highestMark using Test01 or Test02 arrays and store the
results in test01Highest,
* test02Highest respectively
* 4. methodX has been fully implemented and Line 19 above makes a
call to that function,
* create a table and record the outcomes when the function is
called with the following
* arguments : methodX(-5) and methodX(0)
*
*/
}
public static void assessment(/*ADD YOUR PARAMETERS HERE*/){
/**
* This Function takes in 3 arrays one for student names, and 2 for
the respective test marks
* We would like to print a list of students names,Test 01,Test 02
and final marks for each
* students(See sample), The final mark is 40% Test 01 and 60% Test
02.
* In the end we would like to print the sub total of all marks and
average
* Use the below format for you print out:
* Name Test 01 Test 02 Final
* -------- ------- ------- -------
* Kingston 59 80 72
* John 72 65 68
* ----------------------------------------
* Sub-total 140
* Average 70
* ----------------------------------------
*/
}
public static int highestMark(/*ADD YOUR PARAMETERS HERE*/){
/**
* This Functions takes in an array of Marks and return the highest
mark
*/
return 0; //Change this statement
}
public static int methodX(int n){
/**
* This function uses recursion to do some interesting
calculations
* if the given number(n) is equal or less then 1 the functions
returns 1(Stopping case)
* other wise the number(n) is multiplied by the result of the
function methodX(n-2)
*/
if (n <= 1 )
return 1;
else
return n * methodX(n-2);
}
}
Question 4
1. 4 + 2 = 42
2. Runtime error because this is not a comaptible format for
"printf" function.
3. runtime error because %d is missing in the statement and thus
there is no variable to assign a value 350 to.
4. The given statement is correct and hence True.
5. false
6. 4+2 = 4+2
Q5. int[] evenNumbers = {2,4,6,8,"Ten"} is NOT VALID in Java as we declared an array of integer data type (namely evenNumbers) but assigning a string "Ten" in it is invalid.
Question 6 (lab 07) /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. *...
Java Programming Lab 07 coding /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package lab07; /** * * @author ckandjimi */ public class Lab07 { /** * @param args the command line arguments */ public static void main(String[] args) { int outcome = methodX(5); System.out.printf("Result from Method X= %d",outcome); String [] studentNames = {"Kingston","John","Nangula","Daniela"}; int Test01[]...
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package checkingaccounttest; // Chapter 9 Part II Solution public class CheckingAccountTest { public static void main(String[] args) { CheckingAccount c1 = new CheckingAccount(879101,3000); c1.deposit(350); c1.deposit(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.withdraw(350); c1.withdraw(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.deposit(1000); System.out.println(c1); System.out.println("After calling computeMonthlyFee()"); c1.computeMonthlyFee(); System.out.println(c1); } } class BankAccount { private int...
Question 1 Not yet answered Marked out of 1.00 Flag question Question text Which of the following keywords is useful for skipping to the next iteration of a loop? Select one: a. do b. break c. switch d. continue e. while Clear my choice Question 2 Not yet answered Marked out of 1.00 Flag question Question text Consider the following line of Java code. System.out.println("Hello, World!"); "out" is which of the following? Select one: a. a statement b. a class...
Question 1 Question 2: Question 3: Question 4: Question 5: Question 6: Question 7: Question 8: Please number each question. Thank you Question 1 Not yet answered Marked out of 4.00 Flag question If the number density of electrons in a wire is n 1.00 x 1028 m-3, at what drift velocity must they travel through a wire of diameter d 0.560 mm to deliver a current of 7.20 A? Give your answer in mm s1 to 3 significant figures...
This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...
Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...
Question 1 Not yet answered Marked out of 100.00 P Flag question Analyzing Transactions and Adjustments Using the Financial Statement Effects Template On March 1, S. Penman launched AniFoods Inc., an organic foods retailing company. Following are the transactions for its first month of business. 1. S. Penman contributed $220,000 cash to the company in return for common stock. Penman also lent the company $121,000. This $121,000 note is due one year hence. 2. The company purchased equipment in the...
Question 2 - Programming Exercise 1. Make a directory for this lab and change into it. 2. Copy files using the following command: cp/net/data/ftp/pub/class/115/ftp/cpp/Inheritance/Exercise.cpp Exercise.cpp Finish the program so that it compiles and runs. The instructions are contained in the C++ file. Your completed program should generate output similar to the following: TwoD default constructor This program asks for the coordinates of two points in 3D space and calculates their distance. Please enter the xyz coordinates for the first point:...
Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...