This document contains the code for an integration project that provides a menu-driven program for completing various Java exercises related to variables, operators, arithmetic, flow control, methods, repetition, exceptions, OOP, arrays, strings, collections, and other Java topics. The code displays a menu, gets user input to select an exercise, and contains implementation code for 41 different exercises that is executed based on the user's selection.
This talk is a look into some of the surprising performance cases in Java -- with the goal of illustrating a few simple truths about the nature of compilers.
Checking Intel IPP Samples for Windows - ContinuationPVS-Studio
The progress keeps on going. My favorite static code analyzer PVS-Studio is developing too. It has occurred to me recently that those projects we already checked, we can well check again. It would be strange if we wrote articles on this topic, and they would hardly be interesting. But I think we can write one: it will become one more argument for the idea that you can get real benefit from static analysis only using it regularly and not from time to time. So, let's see what new interesting things we have managed to find in the Intel IPP Samples project.
An overview of the inner-workings of OpenJDK - with emphasis on...
- what triggers the just-in-time compiler (JIT)
- types of speculative optimizations performed by the JIT
- aspects of the Java language & ecosystem that make ahead-of-time (AOT) compilation challenging
This talk is a look into some of the surprising performance cases in Java -- with the goal of illustrating a few simple truths about the nature of compilers.
Checking Intel IPP Samples for Windows - ContinuationPVS-Studio
The progress keeps on going. My favorite static code analyzer PVS-Studio is developing too. It has occurred to me recently that those projects we already checked, we can well check again. It would be strange if we wrote articles on this topic, and they would hardly be interesting. But I think we can write one: it will become one more argument for the idea that you can get real benefit from static analysis only using it regularly and not from time to time. So, let's see what new interesting things we have managed to find in the Intel IPP Samples project.
An overview of the inner-workings of OpenJDK - with emphasis on...
- what triggers the just-in-time compiler (JIT)
- types of speculative optimizations performed by the JIT
- aspects of the Java language & ecosystem that make ahead-of-time (AOT) compilation challenging
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
In this talk, we'll walkthrough how the JIT optimizes a piece Java code step-by-step. In doing so, you'll learn some of the amazing feats of optimization that JVMs can perform, but also some surprisingly simple things that prevent your code from running fast.
The slides from the talk I gave at Oracle III #JuevesTecnológicos in Madrid.
A review of how the ParallelStreams Work in Java 8 and some considerations we must know in order to get the better performance from the concurrent data processing in #Java8
Intel IPP Samples for Windows - error correctionPVS-Studio
This is one of my posts on how PVS-Studio makes programs safer. That is where and what types of errors it detects. This time it is samples demonstrating handling of the IPP 7.0 library (Intel Performance Primitives Library) we are going to examine.
Intel IPP Samples for Windows - error correctionAndrey Karpov
This is one of my posts on how PVS-Studio makes programs safer. That is where and what types of errors it detects. This time it is samples demonstrating handling of the IPP 7.0 library (Intel Performance Primitives Library) we are going to examine.
Concurrent Programming in Java provides a brief overview of the following topics:
• Java language support for concurrency
• Concurrency utilities (java.util.concurrent package)
• Java collections for multithreading (java.util package)
• Parallel streams in Java 8.
Try out the examples. Source code here: https://github.com/CodeOpsTech/ConcurrentJava
Java 8 Stream API. A different way to process collections.David Gómez García
A look on one of the features of Java 8 hidden behind the lambdas. A different way to iterate Collections. You'll never see the Collecions the same way.
These are the slides I used on my talk at the "Tech Thursday" by Oracle in June in Madrid.
I am Irene. I am a Computer Science Assignment Help Expert at programminghomeworkhelp.com. I hold a Ph.D. in Computer Science from, California Institute of Technology. I have been helping students with their homework for the past 8 years. I solve assignments related to Computer Science.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with Computer Science assignments.
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
In this talk, we'll walkthrough how the JIT optimizes a piece Java code step-by-step. In doing so, you'll learn some of the amazing feats of optimization that JVMs can perform, but also some surprisingly simple things that prevent your code from running fast.
The slides from the talk I gave at Oracle III #JuevesTecnológicos in Madrid.
A review of how the ParallelStreams Work in Java 8 and some considerations we must know in order to get the better performance from the concurrent data processing in #Java8
Intel IPP Samples for Windows - error correctionPVS-Studio
This is one of my posts on how PVS-Studio makes programs safer. That is where and what types of errors it detects. This time it is samples demonstrating handling of the IPP 7.0 library (Intel Performance Primitives Library) we are going to examine.
Intel IPP Samples for Windows - error correctionAndrey Karpov
This is one of my posts on how PVS-Studio makes programs safer. That is where and what types of errors it detects. This time it is samples demonstrating handling of the IPP 7.0 library (Intel Performance Primitives Library) we are going to examine.
Concurrent Programming in Java provides a brief overview of the following topics:
• Java language support for concurrency
• Concurrency utilities (java.util.concurrent package)
• Java collections for multithreading (java.util package)
• Parallel streams in Java 8.
Try out the examples. Source code here: https://github.com/CodeOpsTech/ConcurrentJava
Java 8 Stream API. A different way to process collections.David Gómez García
A look on one of the features of Java 8 hidden behind the lambdas. A different way to iterate Collections. You'll never see the Collecions the same way.
These are the slides I used on my talk at the "Tech Thursday" by Oracle in June in Madrid.
I am Irene. I am a Computer Science Assignment Help Expert at programminghomeworkhelp.com. I hold a Ph.D. in Computer Science from, California Institute of Technology. I have been helping students with their homework for the past 8 years. I solve assignments related to Computer Science.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with Computer Science assignments.
7º Curso-Taller de Casos Clínicos para Farmacéuticos de Hospital 2014. Actualización en la Farmacoterapia de las enfermedades víricas: VIH, VHB y VHC.
Tratamiento Antiretroviral de Inicio. Fernando Lozano
BioTech Journey through the Phases of Commercializing a ProductCBG Benefits
This presentation was delivered by Breck Arnzen of the ArnzenGroup and Susan Nemetz of The NemetzGroup at the HR BioTech Connect Group meeting in January 2013.
They shared a variety of guidance to help companies navigate the process of commercializing a product in the BioTech industry.
Budget Allocation for a Successful Bio-Pharma Product LaunchBest Practices
Bio-Pharma companies can no longer afford to rely solely on past experiences when budgeting for a new product launch in today's fast-changing, highly competitive market. This comprehensive benchmark study by Best Practices, LLC investigates current costs as well as budget and staffing allocations required for a successful drug launch.
This study can help bio-pharma leaders to develop competitive launch and pre-launch activity budgets to ensure successful U.S. market entry for new products.
Download Full Report: http://bit.ly/2aMYron
The basics of launching a pharmaceutical drug-
Based on studies done on the practices of 13 top pharmaceutical companies in the world.
For more, write to info@markivmedical.com
Elettronica Industriale: Outsourcing o Produzione Interna?Giulia Monti
Il settore dell'elettronica industriale è articolato ed estremamente dinamico: in questa presentazione affrontiamo la differenza che intercorre tra scegliere di auto-produrre o affidare le proprie produzioni elettroniche in outsourcing ad aziende specializzate.
Q3 GIVEN THE TREND EQUATION NO OF STUDENTS-3000+200 YEAR BASE: 2003-0
1.INTERPRET EQUATION RESULTS 2.FORECAST FOR 2020 3.WHEN WILL THE NO OF
STUDENTS REACH 6000
Solution
x no of years from 2003 y no of students y = 3000+200x 1) The regression
equation has a positive slope of 200 y intercept is 3000 i.e. no of students in the year 2000
Thus for every year 200 students increase 2) For 2020, x = 17, y = 3000+200(17) = 6400
3) When y =6000, 6000 = 3000+200x or x = 15 Hence in year 2018 students reach 6000
B Regression C D. All the above.
week3_src/DoWhileLoopFactorial.javaweek3_src/DoWhileLoopFactorial.javapackage edu.drexel.ct290;
import java.util.Scanner;
publicclassDoWhileLoopFactorial{
/**
* A factorial is calculated by multiplying a number by
* every integer less than itself except zero. For example the
* factorial of 4, written 4!, is 4*3*2*1 = 24.
*/
publiclong calculateFactorial(int number){
// declare and initialize a variable to hold the answer
long factorial=number;
// the do while loop will run the block of code between the braces
// as long as the condition in the while statement is true.
// The different between this and the while loop is that
// here, the code will always execute at least once.
do{
// the print statement can help debug errors is in the code
System.out.println("Fact: "+ factorial +", number: "+ number);
// calculate the next factor
factorial = factorial *(number-1);
// decrement the number so that the next iteration of the loop
// will have the correct value to multiply
number--;
}
while( number >1);
// return the answer to the caller.
return factorial;
}
publicstaticvoid main(String[] args){
// Get the user input
Scanner reader =newScanner(System.in);
System.out.print("What number do you want a factorial for: ");
int number = reader.nextInt();
// Create a DoWhileLoopFactorial class
DoWhileLoopFactorial loopFactorial =newDoWhileLoopFactorial();
// call calculateFactorial to compute the answer
long factorial = loopFactorial.calculateFactorial( number );
// Show the user the answer
System.out.println("The answer is: "+ factorial);
}
}
__MACOSX/week3_src/._DoWhileLoopFactorial.java
week3_src/ForLoopFactorial.javaweek3_src/ForLoopFactorial.javapackage edu.drexel.ct290;
import java.util.Scanner;
publicclassForLoopFactorial{
/**
* A factorial is calculated by multiplying a number by
* every integer less than itself except zero. For example the
* factorial of 4, written 4!, is 4*3*2*1 = 24.
*/
publiclong calculateFactorial(int number){
// declare and initialize a variable to hold the answer
long factorial = number;
// The for loop has three parts:
// initialization: int i=number;
// condition: i>1;
// increment/decrement: i--;
// The variable in the initialization is called the control variable
// The initialization happens once when the loop starts.
// The loop will execute as long as the condition is true.
// The decrement will happen automatically after each iteration.
for(int i=number; i>1; i--){
// the print statement can help debug errors is in the code
System.out.println("Fact: "+ factorial +", i: "+ i);
// calculate the next factor
factorial = factorial *(i-1);
}
// return the answer to the caller.
return factorial;
}
publicstaticvoid main(String[] args){
// Get the user input
Scanner reader =newScanner(System.in);
System.out.print("What number do you want a factorial for: ");
int number = reader.nextInt();
// Create a WhileLoopFactoria.
1. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
import java.util.*;
import java.io.*;
import java.util.AbstractCollection;
public class sampleExercise {
public static void main(String[] args) {
// Primitive Data Types
// byte - 8 bit signed two’s complement integer
// Min value of -128 and max value of 127
// Useful for saving memory in large arrays
// Can be used in place of int
// short - 16 bit signed two’s complement integer
// Min value of -32,768 and max value of 32,767
// Can save memory the same way a byte can
// int - 32 bit signed two’s complement integer
// Min value of -2^31 and a Max value of 2^31 - 1
// long - 64 bit two’s complement integer
// Min value of -2^63 and Max value of 2^63
// Use when you need a range of values wider than what int can provide
// float - Single-precision 32 bit IEEE 754 floating point
// Range of values are beyond the scope of discussion
// Use if you need to save memory in large arrays of floating point
// numbers
// double - Double-precision 64 bit IEEE 754 floating point
// Range of values are also beyond the scope of discussion
// Usually the default choice for decimal values
// Never should be used to represent currency
// boolean - Has only two possible values: true and false
// Use for simple flags that track true and false conditions
// Represents one bit of information
// char - Single 16 bit Unicode character
// Min value of 0 and Max value of 65,535
int exercise;
Scanner keyboard = new Scanner(System.in);
System.out.println("1. First Variables Exercise.");
System.out.println("2. Second Variables Exercise.");
System.out.println("3. Third Variables Exercise.");
System.out.println("4. First Operators Exercise.");
System.out.println("5. Second Operators Exercise.");
System.out.println("6. Third Operators Exercise.");
System.out.println("7. First Arithmetic Exercise.");
System.out.println("8. Second Arithmetic Exercise.");
System.out.println("9. Third Arithmetic Exercise.");
System.out.println("10. First Flow Control Exercise.");
System.out.println("11. Second Flow Control Exercise.");
System.out.println("12. Third Flow Control Exercise");
System.out.println("13. First Methods Exercise");
-1-
2. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
System.out.println("14. Second Methods Exercise");
System.out.println("15. Third Methods Exercise");
System.out.println("16. First Repetition Exercise ");
System.out.println("17. Second Repetition Exercise");
System.out.println("18. Third Repetition Exericise");
System.out.println("19. First Exceptions Exercise");
System.out.println("20. Second Exceptions Exercise");
System.out.println("21. First OOP Exercise");
System.out.println("22. Second OOP Exercise");
System.out.println("23. Third OOP Exercise");
System.out.println("24. First Array Exercise");
System.out.println("25. Second Array Exercise");
System.out.println("26. Third Array Exercise");
System.out.println("27. First Strings Exercise");
System.out.println("28. Second Strings Exercise");
System.out.println("29. Third Strings Exercise");
System.out.println("30. First Collections Exercise");
System.out.println("31. Second Collections Exercise");
System.out.println("32. Third Collections Exercise");
System.out.println("33. First Miscellaneous Exercise");
System.out.println("34. Second Miscellaneous Exercise");
System.out.println("35. Third Miscellaneous Exercise");
System.out.println("36. First Polymorphism Exercise");
System.out.println("37. Second Polymorphism Exercise");
System.out.println("38. Third Polymorphism Exercise");
System.out.println("39. First Abstract Class Exercise");
System.out.println("40. Second Abstract Class Exercise");
System.out.println("41. Third Abstract Class Exercise");
System.out.println("rn");
System.out.println("Enter your selection:");
exercise = keyboard.nextInt();
if (exercise < 1 || exercise > 41) {
System.out.println("Your selection is invalid.");
System.out.println("Enter any number between 1 and 41.");
-2-
3. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
exercise = keyboard.nextInt();
}
switch (exercise) {
// Variable - a variable is, depending on its data type, a word,
// partial
// word, acronym,etc., that allows the user to store values to
// utilize
// in his/her program in order to save space and make the program
// more
// efficient as well as more organized.
case 1:
// First Variable Exercise
String greeting;
greeting = "Hello Martians";
int age = 21; // Variable "age" has an integer value
System.out.println(greeting + " I am " + age + " years old");
break;
case 2:
// Second Variable Exercise
boolean isGood = true; // "isGood" is a boolean value that =
// true
// "pMartian is a string
String pMartian = "This universe is basically good";
System.out.println(pMartian + " - " + isGood);
break;
case 3:
// Third Variable Exercise
boolean affirmative = true;
System.out.println(affirmative);
break;
case 4:
try {
// First Operators Exercise - arithmetic operators
int a, b; // Integer values will be stored in "a" and "b"
int resulta;
int results;
int resultm;
float resultd; // Result for resultd will not be an integer, but
// a
// decimal value
System.out.print("Enter a:"); // Asks user for input
a = keyboard.nextInt(); // User input stored in "a"
System.out.print("Enter b:");
-3-
4. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
b = keyboard.nextInt(); // User input stored in "b"
resulta = a + b;
results = a - b;
resultm = a * b;
resultd = (float) a / b; // float needed to get correct
// quotient.
// Integer Division will give you an integer answer, however, if
// your
// numerator happens to not be equally divisible by the
// denominator,
// you
// will need to cast the process using the appropriate data type
// to
// get
// the correct answer
// Now all calculations using "a" and "b" are printed below
System.out.println("The result of adding is " + resulta);
System.out.println("The result of subtracting is " + results);
System.out.println("The result of multiplying is " + resultm);
System.out.println("The result of dividing is " + resultd);
} catch (InputMismatchException e2) {
System.out.println("Please enter an integer.");
}
break;
case 5:
try {
// Second Operators Exercise - Celsius to Farhenheit Converter
System.out.println("Enter a temperature in Celsius: ");
double Fahrenheit = 0;// Gives Fahrenheit an initial value of 0
// keyboard.nextDouble() being included after = makes Celsius
// take
// value
// of user
// input
double Celsius = keyboard.nextDouble();
// Now below you have to use a formula for the temp conversion
Fahrenheit = ((Celsius * 9 / 5) + 32);
System.out.println("The temperature in Fahrenheit is: " + Fahrenheit);
} catch (InputMismatchException e2) {
System.out.println("Please enter a number.");
}
break;
case 6:
-4-
5. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
try {
// Third Operators Exercise - Largest of Three Numbers
int x, y, z;// variables declared
System.out.println("Enter three integers:");// user input is
// stored
// in 3
// separate
// variables
x = keyboard.nextInt();
y = keyboard.nextInt();
z = keyboard.nextInt();
if (x > y && x > z && z != y) { // if statements sort through
// all of
// the
// possible values the user can
// enter
// and gives an output based on
// what
// is
// entered
System.out.println("First number is largest.");
}
if (y > x && y > z && x != z) {
System.out.println("Second number is largest.");
}
if (z > x && z > y && x != y) {
System.out.println("Third number is largest.");
}
else {
System.out.println("Entered numbers are not distinct.");// If
// none
// of
// these
// conditions
// are
// true,
// then
// this
// will
// be
// the
// output
}
} catch (InputMismatchException e2) {
System.out.println("Please enter an integer.");
}
break;
case 7:
try {
// First Arithmetic Exercise - Absolute Equals
-5-
6. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
boolean equal = true; // boolean value can only take the value
// of
// true
// or false
System.out.println("Enter the 1st number:");
int num1 = keyboard.nextInt(); // num1 takes value of whatever
// the
// user
// entered first
System.out.println("Enter the 2nd number:");
int num2 = keyboard.nextInt(); // num2 takes value of whatever
// the
// user
// entered second
if (((Math.abs(num1)) != (Math.abs(num2)))) {// Math.abs finds
// the
// absolute value
// of
// the
// user input
equal = false;
System.out.println("Result is:" + equal);
}
equal = true;// same as having an else statement, if the other
// conditions above are not met, this will be the
// output
System.out.println("Result is:" + equal);
} catch (InputMismatchException e2) {
System.out.println("Please enter an integer.");
}
break;
case 8:
try {
// Second Arithmetic Exercise - Floor and Ceiling of a Number
System.out.println("Enter a number:");
double dob = keyboard.nextDouble(); // double means the value
// will
// not be
// an integer, but a decimal
// value
// instead
System.out.print((int) Math.ceil(dob)); // Math.ceil will find
// the
// ceiling of a number
System.out.println("rn"); // Another way to space between
// outputs
System.out.print((int) Math.floor(dob)); // Math.floor will find
// the
// floor of a number
} catch (InputMismatchException e2) {
-6-
7. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
System.out.println("Please enter an integer.");
}
break;
case 9:
try {
// Third Arithmetic Exercise - Square Root, Quadratic Root
Scanner scan = new Scanner(System.in);
System.out.println("Enter a number:");
double s = scan.nextDouble();
System.out.printf("%.5f", Math.sqrt(s));// Math.sqrt takes the
// square
// root of a number
System.out.print("rn");
System.out.printf("%.5f", Math.pow(s, .25));// Math.pow and the
// value
// .25 takes the
// quadratic
// root of a number
System.out.println("rn");
} catch (InputMismatchException e2) {
System.out.println("Please enter an integer.");
}
break;
case 10:
try {
// First Flow Control Exercise - Right or Wrong
System.out.println("What is 12+12?");
boolean correct = false;
System.out.println();
int answer = keyboard.nextInt();
if (answer == 24) { // Only if the user input equals 24 will the
// variable correct be equal to true
correct = true;
}
System.out.println(correct);// Otherwise, the output will be
// false
} catch (InputMismatchException e2) {
System.out.println("Please enter an integer.");
}
break;
case 11:
try {
// Second Flow Control Exercise - Sleep
System.out.print("Is it a weekday today?(true or false):");
-7-
8. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
boolean w = keyboard.nextBoolean(); // w takes the value of the
// user
// input, but has to be
// eiter
// true or
// false
System.out.print("Are you on a vacation?(true or false):");
boolean v = keyboard.nextBoolean();
if (w == true && v == false) {
System.out.println("You cannot sleep.");// If you are ever
// on
// vacation, you can
// sleep
}
else if (w == false && v == true) {
System.out.println("You can sleep.");
}
else if (w == true && v == true) {
System.out.println("You can sleep.");
}
else {
System.out.println("You can sleep.");
}
} catch (InputMismatchException e2) {
System.out.println("Please enter true or false.");
}
break;
case 12:
try {
// Third Flow Control Exercise - Lucky Sum
int d, e, f, g;
System.out.println("Enter 3 values:");
d = keyboard.nextInt();
e = keyboard.nextInt();
f = keyboard.nextInt();
g = d + e + f;
if (d == 13) {
System.out.println("Lucky sum:" + 0);// If any value entered
// equals
// 13, then that number
// as
// well
// as all numbers to
// the
// right
// of it will not count
// towards
// the sum
}
else if (d != 13 && e == 13) {
-8-
9. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
System.out.println("Lucky sum:" + d);
}
else if (d != 13 && e != 13 && f == 13) {
System.out.println("Lucky sum:" + (d + e));
}
else {
System.out.println("Lucky sum:" + g); // If not numbers
// entered
// are
// equal to 13, then
// the
// sum
// will be calculated
// normally
}
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 13:
try {
// First Methods Exercise
System.out.println("Enter a Number:");
double number = keyboard.nextDouble();
number = (Math.sqrt(number));
int sqrt = ((int) Math.round(number));
System.out.println("The square root is:" + sqrt);
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 14:
try {
// Second Methods Exercise
System.out.println("Enter first number:");
int x1 = keyboard.nextInt();
System.out.println("Enter second number:");
int y1 = keyboard.nextInt();
boolean result = false;
if (y1 % x1 == 0) {
result = true;
System.out.println(result);
}
else {
System.out.println(result);
}
} catch (InputMismatchException e) {
-9-
10. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
System.out.println("Please enter an integer.");
}
break;
case 15:
try {
// Third Methods Exercise
System.out.println("Enter the radius:");
int r = keyboard.nextInt();
double pi = 3.14;
double area = (pi * (r * r));
System.out.println("Area of circle is:" + area);
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 16:
try {
// First Repetition Exercise
int num;
int sum = 0;
int count = 1;
while (count < 6) {
System.out.println(" Enter Number " + count);
num = keyboard.nextInt();
sum = num + sum;
count++;
}
System.out.println(sum);
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 17:
try {
// Second Repetition Exercise
System.out.println("Enter a number:");
int n = 0;
for (int lsum = 0; n != 0; lsum++) {
n = keyboard.nextInt();
lsum = lsum + n;
System.out.println("The total is:" + lsum);
-10-
11. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
}
} catch (InputMismatchException e) {
System.out.println("Please enter any integer but zero.");
}
break;
case 18:
try {
// Third Repetition Exercise
int factorial = 1;
int currentValue = 1;
System.out.println("Enter a Number.");
int input = keyboard.nextInt();
while (currentValue <= input) {
factorial *= currentValue;
currentValue++;
}
System.out.println("The Factorial of " + input + " is " + factorial);
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 19:
// First Exceptions Exercise
String id = "";
int idnum;
System.out.println("Enter the ID number:");
id = keyboard.next();
try {
idnum = Integer.parseInt(id);
if (id.length() != 10) {
throw new NumberFormatException();
}
System.out.println("correct");
}
catch (NumberFormatException e1) {
System.out.println("incorrect");
} catch (Exception e1) {
System.out.println("incorrect");
}
break;
case 20:
-11-
12. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
// Second Exceptions Exercise
try {
System.out.println("Enter a number:");
int value = keyboard.nextInt();
if (value % 5 == 0 && value % 2 == 0) {
// This relational operator between two numerical values
// relates them with the equals operator
// Also, the && is a conditional operator that signifies
// that if both of the conditions mentioned aren't true,
// then its false
// A conditional operator pretty much combines
// conditions to
// further modify an if statement
System.out.println("Correct");
}
else if (value == 5) {
Exception e1 = new Exception();
throw e1;
}
}
catch (Exception e1) {
System.out.println("wrong");
}
break;
case 21:
// First OOP Exercise
Person person1 = new Person();
person1.setInfo("Test", 25);// this is an example of a method
// call
System.out.println(person1.getInfo());
break;
case 22:
// Second OOP Exercise
try {
System.out.println("Enter name:");
String somename = keyboard.nextLine();
System.out.println("Enter email:");
String semail = keyboard.nextLine();
System.out.println("Enter book name:");
String sbook = keyboard.nextLine();
Author author1 = new Author();
author1.setStuff(somename, semail, sbook);// What is in
// parenthesis
// after
-12-
13. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
// the method name here are
// considered arguments
System.out.println(author1.getName());
System.out.println(author1.getEmail());
System.out.println(author1.getBook());
} catch (InputMismatchException e) {
System.out.println("Please enter a string.");
}
break;
case 23:
try {
// Third OOP Exercise
System.out.println("Enter radius:");
double rad = keyboard.nextDouble();
System.out.println("Enter color:");
String col = keyboard.next();
Area mc = new Area();
mc.setArea(rad);
mc.setColor(col);
System.out.println(mc.getArea());
System.out.println(mc.getColor());
} catch (InputMismatchException e) {
System.out.println("Please enter an integer for radius and a string for color.");
}
break;
case 24:
try {
System.out.print("Enter a string:");
String con = keyboard.next();
char[] str = con.toCharArray();
int len = str.length;
for (int i = len - 1; i >= 0; i--) {
System.out.print(str[i]);
}
} catch (InputMismatchException e) {
System.out.println("Please enter a string.");
}
break;
case 25:
try {
int summ = 0;
int sumElements[];
sumElements = new int[10];
System.out.println("Enter elements of array :");
for (int i = 0; i < 10; i++) {
sumElements[i] = keyboard.nextInt();
summ = summ + sumElements[i];
}
System.out.println("Sum of elements of the array:" + summ);
-13-
14. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
} catch (InputMismatchException e) {
System.out.println("Please enter integers.");
}
break;
case 26:
try {
int productArray[];
int max = 0;
int min = 0;
productArray = new int[10];
System.out.println("Enter elements of array :");
for (int i = 0; i < 10; i++) {
productArray[i] = keyboard.nextInt();
for (int j = 0; j < i; j++) {
if (productArray[j] > productArray[j + 1]) {
int temp = productArray[j];
productArray[j] = productArray[j + 1];
productArray[j + 1] = temp;
max = productArray[9];
min = productArray[0];
}
}
}
System.out.println("Result is :" + (max * min));
} catch (InputMismatchException e) {
System.out.println("Please enter integers.");
}
break;
case 27:
try {
System.out.println("Enter an Uppercase letter:");
String userInput = keyboard.next();
String low = userInput.toLowerCase();
System.out.println(low);
} catch (InputMismatchException e) {
System.out.println("Please enter a string.");
}
break;
case 28:
try {
System.out.println("Enter a string:");
String input1 = keyboard.next();
char[] inputArray = input1.toCharArray();
int input1Length = inputArray.length;
System.out.println("Length of the string is:" + input1Length);
} catch (InputMismatchException e) {
System.out.println("Please enter a string.");
}
-14-
15. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
break;
case 29:
try {
System.out.print("Enter a line of text: ");
String line = keyboard.nextLine();
String upperCa = line.toUpperCase();
System.out.println(upperCa);
} catch (InputMismatchException e) {
System.out.println("Please enter a string.");
}
break;
case 30:
try {
System.out.println("Enter the number of integers in your list.");
int numb = keyboard.nextInt();
int[] bubbleArray = new int[numb];
for (int i = 0; i < numb; i++) {
bubbleArray[i] = keyboard.nextInt();
for (int j = 0; j < i; j++) {
if (bubbleArray[j] > bubbleArray[j + 1]) {
int val = bubbleArray[j];
bubbleArray[j] = bubbleArray[j + 1];
bubbleArray[j + 1] = val;
}
}
}
System.out.println(bubbleArray[bubbleArray.length - 1]);
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 31:
try {
System.out.println("Enter the 1st number:");
int numm1 = keyboard.nextInt();
System.out.println("Enter the 2nd number:");
int numm2 = keyboard.nextInt();
System.out.println("Enter the 3rd number:");
int numm3 = keyboard.nextInt();
Stack<Integer> list1 = new Stack<Integer>();
System.out.println("Stack:[]");
list1.push(numm1);
System.out.println(list1);
list1.push(numm2);
System.out.println(list1);
list1.push(numm3);
System.out.println(list1);
list1.pop();
System.out.println(list1);
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
-15-
16. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
case 32:
try {
ArrayList<Integer> al = new ArrayList<Integer>();
System.out.println("Enter the number of integers that will be inserted: ");
int size = keyboard.nextInt();
System.out.println("Enter some integers to insert to the ArrayList: ");
while (size-- > 0) {
al.add(keyboard.nextInt());
}
int maxim = Collections.max(al);
int maxindex = al.lastIndexOf(maxim);
System.out.println("The largest value is " + maxim + "; which " + "is in slot " +
maxindex);
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 33:
try {
String u1 = keyboard.next();
char[] pal = u1.toCharArray();
Palindrome goTo = new Palindrome();
if (goTo.isItPalindrome(pal)) {
System.out.println("palindrome");
}
else {
System.out.println("not a palindrome");
}
} catch (InputMismatchException e) {
System.out.println("Please enter a string.");
}
break;
case 34:
try {
System.out.println("Enter a number:");
String possibleBiNumber = keyboard.next();
int n1 = possibleBiNumber.charAt(0);
if (possibleBiNumber.matches("[01]+") == true) {
System.out.println("binary");
}
else {
System.out.println("not binary");
}
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
-16-
17. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
case 35:
try {
String ones[] = { "one", "two", "three", "four", "five", "six", " seven", "eight",
"nine", "ten", "eleven",
"twelve", "thirteen", "forteen", "fifteen", "sixteen", "seventeen", "eighteen",
"ninteen" };
String tens[] = { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
"eighty", "ninety" };
int digitInput;
System.out.println("Enter the number:");
digitInput = keyboard.nextInt();
char[] digitArray = String.valueOf(digitInput).toCharArray();
int tensNumber = Character.getNumericValue(digitArray[0]);
int onesNumber = Character.getNumericValue(digitArray[1]);
if (digitInput >= 1 && digitInput <= 19) {
System.out.println("Entered number is:" + ones[digitInput - 1]);
}
else if (digitInput >= 20) {
if (onesNumber == 0) {
System.out.println("Entered number is:" + tens[tensNumber - 2]);
}
else {
System.out.println("Entered number is:" + tens[tensNumber - 2] + " " +
ones[onesNumber - 1]);
}
}
else {
System.out.println("Your input was invalid, please enter an" + " integer");
}
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 36:
try {
Box mybox1 = new Box();
Box mybox2 = new Box();
Box mycube = new Box();
int vol;
vol = mybox1.volume(10, 20, 15);
System.out.println("Volume of mybox1 is " + vol);
vol = mybox2.volume();
System.out.println("Volume of mybox2 is " + vol);
vol = mycube.volume(7);
-17-
18. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
System.out.println("Volume of mycube is " + vol);
} catch (InputMismatchException e) {
System.out.println("Please enter an integer.");
}
break;
case 37:
Overload overload = new Overload();
int endResult;
String endResult2;
char endResult3;
endResult = overload.test(10);
System.out.println("a" + " " + endResult);
endResult2 = overload.test("10 20");
System.out.println("a and b" + " " + endResult2);
endResult3 = overload.test('a');
System.out.println("char" + " " + endResult3);
endResult = 97;
System.out.println("Result" + " " + endResult);
break;
case 38:
Animal movement = new Animal();
Dog typeOfMovement = new Dog();
movement.move();
System.out.println("n");
typeOfMovement.move();
break;
case 39:
Counter loopIncrement = new Counter();
loopIncrement.increment();
loopIncrement.increment();
loopIncrement.increment();
loopIncrement.print();
break;
case 40:
System.out.println("Enter the radius:");
double radius = keyboard.nextDouble();
Circle myCircle = new Circle();
myCircle.setArea(radius);
System.out.println("Radius is:" + radius + "and Area is:" + myCircle.getArea());
break;
case 41:
Scanner scanner = new Scanner(System.in);
System.out.println("Enter name:");
String name1 = scanner.nextLine();
System.out.println("Enter unit price:");
double up = scanner.nextDouble();
System.out.println("Enter weight:");
-18-
19. C:Userslildg_000OneDriveN++ CodeIntegration Project.java Saturday, April 16, 2016 12:09 AM
double w = scanner.nextDouble();
WeighedItem item1 = new WeighedItem(name1, up, w);
item1.setPrice(up, w);
scanner.nextLine();
System.out.println("Enter name:");
String name2 = scanner.nextLine();
System.out.println("Enter unit price:");
double up1 = scanner.nextDouble();
System.out.println("Enter quantity:");
int q = scanner.nextInt();
CountedItem item2 = new CountedItem(name2, up1, q);
item2.setPrice(up);
System.out.println(item1);
System.out.println(item2);
break;
}
}
}
-19-
20. C:Userslildg_000OneDriveN++ CodeIntegration Project Method References.java Saturday, April 16, 2016 12:10 AM
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
public class Person {
private String name;
private int age;
public void setInfo(String n, int a) {
name = n;
age = a;
}
public String getInfo() {
return "Name=>" + name + " and Age=>" + age;
}
}
class Author {
private String name;
private String email;
private String book;
public void setStuff(String n, String e, String b) {
name = n;
email = e;
book = b;
}
public String getName() {
return name + "n";
}
public String getEmail() {
return email + "n";
}
public String getBook() {
return book + "n";
}
}
class Area {
private double area;
private String color;
private double pi = 3.141592653589793;
private double radius;
public void setArea(double r) {
radius = r;
}
public void setColor(String c) {
color = c;
}
public double getArea() {// A parameter is what is located
// inside of
// the parenthesis after the method name
-1-
21. C:Userslildg_000OneDriveN++ CodeIntegration Project Method References.java Saturday, April 16, 2016 12:10 AM
double area = (pi * (Math.pow(radius, 2)));
return area;
}
public String getColor() {
return color;
}
}
class Palindrome {
public boolean isItPalindrome(char[] userIn) {
int endLetter = userIn.length - 1;
int beginningLetter = 0;
while (endLetter > beginningLetter) {
if (userIn[endLetter] != userIn[beginningLetter]) {
return false;
}
--endLetter;
++beginningLetter;
}
return true;
}
}
class Box {
int width;
int height;
int depth;
public int volume(int w, int h, int d) {
width = w;
height = h;
depth = d;
return width * height * depth;
}
public int volume() {
width = -1;
height = 1;
depth = 1;
return width * height * depth;
}
public int volume(int w) {
width = w;
height = 49;
depth = 1;
return width * height * depth;
}
}
class Overload {
int output;
String output2;
-2-
22. C:Userslildg_000OneDriveN++ CodeIntegration Project Method References.java Saturday, April 16, 2016 12:10 AM
char output3;
public int test(int o) {
output = o;
return output;
}
public String test(String n) {
output2 = n;
return output2;
}
public char test(char a) {
output3 = a;
return output3;
}
}
class Animal {
public void move() {
System.out.println("Animals can move");
}
}
class Dog extends Animal {
public void move() {
System.out.println("Dogs can walk and run");
}
}
class Counter {
int i = 0;
Counter increment() {
i++;
return this;
}
void print() {
System.out.println("i = " + i);
}
}
class Circle extends Area {
}
-3-
23. C:Userslildg_000OneDriveN++ CodePurchaseItem Class.java Saturday, April 16, 2016 12:10 AM
class PurchaseItem {
private String name;
private double unitPrice;
public PurchaseItem(String n, double up) {
name = n;
setPrice(up);
}
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
public void setPrice(double up) {
unitPrice = (up > 0) ? up : 0;
}
public double getPrice() {
return unitPrice;
}
public String toString() {
return getName() + "@ " + getPrice();
}
}
-1-
24. C:Userslildg_000OneDriveN++ CodeWeighedItem Class.java Saturday, April 16, 2016 12:10 AM
public class WeighedItem extends PurchaseItem {
private double Kg;
private double actualPrice;
public WeighedItem(String n, double up, double kg) {
super(n, up);
this.Kg = kg;
}
public void setPrice(double up, double kg) {
actualPrice = up * Kg;
}
public String toString() {
return super.getName() + " @ "+ super.getPrice() + " " + Kg + " Kg " + actualPrice + " $";
}
}
-1-
25. C:Userslildg_000OneDriveN++ CodeCountedItem Class.java Saturday, April 16, 2016 12:10 AM
public class CountedItem extends PurchaseItem {
private int quantity;
private double actualPrice;
public CountedItem(String n, double up, int quantity) {
super(n, up);
this.quantity = quantity;
}
public void setPrice(double up, int quantity) {
actualPrice = up * quantity;
}
public String toString() {
return super.getName() + " @ " + super.getPrice() + " " + quantity + " units " +
actualPrice + " $";
}
}
-1-