Commit 9d253063 authored by Sully Khalifa's avatar Sully Khalifa

Test

parents
/.metadata/
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ATM</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Exportrep</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
public class Repexport {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MyApp01</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
module MyApp01 {
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MyApp1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
module MyApp1 {
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Week07</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>boolean</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
import java.util.*;
class Main {
public static void main(String[] args) {
Set<String> hashSet = new HashSet<String>();
hashSet.add("My element");
System.out.println(hashSet.contains("My element"));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>exercisesMenu</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package exercisesMenu;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int input;
System.out.println("Please select which exercise you want to run - \n 1. Fizzbang - \n 2. Populate - \n 3. Print Backwards - \n 4. Factorial");
input = scan.nextInt();
switch(input) {
case 1: fizzBang();
break;
case 2: populate();
int[] bobby = populate();
for(int i = 0; i < bobby.length; i++) {
System.out.println(bobby[i]);
}
break;
case 3 :
String word = "Glasses";
printBackwards(word);
break;
case 4:
int num = 3;
System.out.println(factorial(num));
}
}
private static void fizzBang() {
for (int i = 0; i < 100; i++) {
//Check if I is both
if (i %3 == 0 && i % 5 == 0 ) {
System.out.println("Fizzbang");
continue;
}
//Check if i is a multiple of 3
if (i % 3 == 0) {
System.out.println("Fizz");
continue;
}
//Check if i is a multiple of 5
if (i % 5 == 0) {
System.out.println("Bang");
continue;
} else {
System.out.println(i);
//otherwise print
}
}
}
private static int[] populate() {
// create an array. loop through it, and populate it with random number.
int[] array = new int[10];
Random randy = new Random();
for (int i = 0; i < array.length; i++) {
array[i] = randy.nextInt(100)+1;
}
return array;
}
private static void printBackwards(String unoReverseCard) {
//print this reverse
System.out.println(unoReverseCard);
for (int i = unoReverseCard.length()-1; i >= 0; i--) {
System.out.print(unoReverseCard.charAt(i));
}
}
private static int factorial(int num) {
if(num == 1) {
return num;
}else {
return factorial(num-1) * num;
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>menu</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package menu;
public class byValue {
public static void main(String[] args) {
int [] a = {2};
System.out.println("Before " + a[0]);
System.out.println("Update " + update(a[0]));
System.out.println("After " + a[0]);
int n = 10;
System.out.println();
System.out.println("Before " + n);
System.out.println("Update " + update(n));
System.out.println("After " + n);
}
static int update(int [] a) {
a[0]= 9 * a[0];
return a[0];
}
static int update(int n) {
n = 9 *n;
return n;
}
}
\ No newline at end of file
package menu;
public class ex3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(method(4 ));
}
public static int method(int n) {
if (n <= 0) { return 0;
}
return n + method(n - 1) * 2;}
}
package menu;
public class expandingPattern {
public static void main(String[] args){
pattern(13);
}
public static void pattern(int n){
//base case
if(n<0){
return;
}
pattern(n - 1);
//recursive behaviour
for (int i = 0; i < n; i++){
System.out.print("*.^^.");
}
System.out.println();
}
}
package menu;
import java.util.Scanner;
public class menu {
//Shared sources
static double balance = 990;
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int options;
while(true) {
// Display options
System.out.println(" ----------------------------------------------------");
System.out.println("Main menu \n 1 Check balance"
+ "\n 2 Deposit \n 3 Withdraw \n 4 Quit ");
// Ask for options
System.out.println();
System.out.println("Press which option you would like > ");
// Get the options
options = input.nextInt();
switch(options) {
// 1 check balance
case 1 : checkBalance();
break;
// 2 deposit
case 2 : deposit();
break;
// 3 Withdraw
case 3 : withdraw();
break;
// 4 Quit
case 4 : break;
default:
System.out.println("Invalid option, valid options are 1-4");
}
}
} // ending of main method
private static void withdraw() {
// Ask the user how much they need
System.out.print("Please, how much do you need?");
double amount = input.nextDouble();
if(balance >= amount ) {
// update the balance
//notification
balance = balance - amount;
System.out.println("Completed succuessfully, the new balance is " + balance);
}else
System.out.println("Insufficient funds.");
}
// Display balance method
public static void checkBalance() {
System.out.println("The account balance is " + balance);
}
//Deposit method
public static void deposit() {
//Ask the user, how much they want deposit
System.out.println("How much would you like to deposit? ");
double amount = input.nextDouble();
//Update the balance
balance = balance + amount;
}
}
package menu;
public class overloading2 {
public static void main(String[] args) {
System.out.println( add(3, 7) );
System.out.println( add(1, 2 ,3));
System.out.println( add(1.3 ,3 ,2 ));
} // main
public static int add(int n1, int n2) {
return n1 + n2;
}
public static int add(int n1, int n2, int n3) {
return n1 + n2 + n3;
}
public static double add(double n1, int n2, int n3) {
return n1 + n2 + n3;
}
}
package menu;
public class recursion {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public static int digitSum(int n){
// A base case for termination
if (n == 0) return 0;
// General case for recursion
return digitSum(n / 10) + (n % 10);
}
public static int sum(int n) {
if ( n <= 0) {
return 0;
}
return n + sum(n - 1);
}
}
package menu;
public class recursion2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print(" sum " + sum(9999) + " \n digit " + digitSum(9999) );
}
public static int digitSum(int n){
// A base case for termination
if (n == 0) return 0;
// General case for recursion
return digitSum(n / 10) + (n % 10);
}
public static int sum(int n) {
if ( n <= 0) {
return 0;
}
return n + sum(n - 1);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myATM</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package myATM;
import java.util.Scanner;
public class ATM {
public static void main(String[] args) {
// TODO Auto-generated method stub
float balance = 750, amount;
Scanner input = new Scanner(System.in);
System.out.print("Please, how you would you like to withdraw? ");
amount = input.nextFloat();
if(amount <= balance) {
System.out.println("Please take your card" + " and wait for the cash.");
}
else
System.out.print("Insufficient funds in your account.");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myApp003</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package myApp003;
import javax.swing.JOptionPane;
public class app003 {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Welcome to Java. \n Java is cool!");
System.out.println("Welcome to Java");
System.out.print("This is great!");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myApp02</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package myApp02;
import java.util.Scanner;
public class App02 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String text;
System.out.print("Please enter your name: ");
text = input.nextLine();
System.out.print("Good afternoon, " + text);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myApp03</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
module myApp03 {
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myApp04</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package myApp04;
import java.util.Scanner;
public class App04 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String text;
//This is what the program does.
System.out.println("Please enter your name");
text = input.nextLine();
System.out.println(text + " ,Welcome to Jave!");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myApp05</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package myApp05;
import java.util.Scanner;
public class App05 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String n1, n2;
System.out.println("Please enter your account balance:");
n1 = input.next();
System.out.println("Please enter the interest rate:");
n2 = input.next();
//Convert the input into two numbers.
float number1, number2;
number1 = Float.parseFloat(n1);
number2 = Float.parseFloat(n2);
System.out.println("Your new balance would be" + number1 + " + " + number2 + " = " + (number1 + (number2*100)));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myApp06</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package myApp06;
import javax.swing.JOptionPane;
public class basicCalc {
public static void main(String[] args) {
String n1, n2;
n1 = JOptionPane.showInputDialog("Please enter the first number:");
n2 = JOptionPane.showInputDialog("Please enter the second number");
//Covert the input text into values
float number1, number2;
number1 = Float.parseFloat(n1);
number2 = Float.parseFloat(n2);
JOptionPane.showMessageDialog(null, number1 + " + " + number2 + " = " + (number1+number2));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myApp07</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package myApp07;
public class Exercise1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myApp08</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package myApp08;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("number\t" + "binary\t" + "octal\t" + "hex");
Main.printNumbers(0b110);
Main.printNumbers(077);
Main.printNumbers(0xAF);
Main.printNumbers(Integer.parseInt("110", 2));
}
private static void printNumbers(int n)
{
String decimal = String.valueOf(n);
String binary = Integer.toBinaryString(n);
String oct = Integer.toOctalString(n);
String hex = Integer.toHexString(n);
System.out.println(decimal + "\t" + binary + "\t" + oct + "\t" + hex);
}
}
package myApp08;
public class Mealmenu {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("number\t" + "binary\t" + "octal\t" + "hex");
Main.printNumbers(0b110);
Main.printNumbers(077);
Main.printNumbers(0xAF);
Main.printNumbers(Integer.parseInt("110", 2));
}
private static void printNumbers(int n)
{
String decimal = String.valueOf(n);
String binary = Integer.toBinaryString(n);
String oct = Integer.toOctalString(n);
String hex = Integer.toHexString(n);
System.out.println(decimal + "\t" + binary + "\t" + oct + "\t" + hex);
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>newArrays</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package newArrays;
public class newArrays {
public static void main(String[] args) {
// TODO Auto-generated method stub
int board [] [] = new int [9][9];
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board.length; j++) {
board[i][j] = i * j;
}
}
for (int i=0; i<board.length; i++) {
for (int j=0; j< board.length; j++) {
System.out.print(board[i][j] + ", ");
}
System.out.println();
}
/*int counter = 0;
int values[] = {1, 3, -2, -4, 9, 11, 5, 0, -1, -2, -21, 7, 13};
for (int element : values) {
if (element > 0 ) {
counter++; }
}
System.out.println(counter);
}
/*
int[] scores = new int[100];
int total = 0;
for(int i=7; i<scores.length; i+=7) {
scores[i] = i;
}
for(int e : scores) {
total +=e;
System.out.println(e);
}
System.out.println("total = " + total);
/*
for(int j=7; j<scores.length; j+=7) {
System.out.println(scores[j]);
total = total + j;
}
System.out.println("Total = " + total);
/*
scores[0] = 90;
scores[1] = 99;
scores[2] = 100;
System.out.println()
*/
}
}
package newArrays;
import java.util.Scanner;
public class tictocToe {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Algorithm or Flowchart
// create input facility
Scanner input = new Scanner(System.in);
// Create the board
char[] [] board = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
//String [][] board = new String [3][3];
// board = {{" ", " ", " "}, {" ", " ", " "}, {" ", " ", " "}};
//**? while
while(true) {
//Display board
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
System.out.print(board[i][j] + " : ");
}
System.out.println();
}
//Ask P1 to choose a position
//Assign the position to P1
//Display the board again
//Ask P2 to choose a position
//Assign the position to P2
//Display the board again
//Repeat steps
//**? do-while
//termination condition
//??
break;
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>newMethods</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package newMethods;
public class method {
public static void main(String[] args) {
System.out.print(add(9,45));
} //Closing parenthesis of the main method.
//This method add two numbers.
public static int add(int n1, int n2) {
int sum = n1 + n2;
return sum;
}
} // closing the class
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>pluralArrays</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package pluralArrays;
import java.util.ArrayList;
import java.util.Scanner;
public class ShoppingSystem {
// A facility for getting input
static Scanner input = new Scanner(System.in);
// Generic description of the items: name, code, price, quantity and description
// Database for the products/items: has to reflects all these components of the items
// An array or list to represent the database, from Week 04
static ArrayList<String> itemName = new ArrayList<String>(); // name
static ArrayList<Integer> itemCode = new ArrayList<Integer>(); // code
static ArrayList<Float> itemPrice = new ArrayList<Float>(); // price
static ArrayList<Integer> itemQty = new ArrayList<Integer>(); // Quantity
static ArrayList<String> itemDescription = new ArrayList<String>(); // Description
// Table for the cart, where a customer can store selected item before payment
// Also the cart has to capture these components of the items.
static ArrayList<String> basketName = new ArrayList<String>(); // name
static ArrayList<Integer> basketCode = new ArrayList<Integer>(); // code
static ArrayList<Float> basketPrice = new ArrayList<Float>(); // price
static ArrayList<Integer> basketQty = new ArrayList<Integer>(); // Quantity
static ArrayList<String> basketDescription = new ArrayList<String>(); // Description (optional)
// Create a variable option that you can use in multiple methods.
public static void main(String[] args) {
// Variable
String username = "aaa", password = "123", tempUsername, tempPwd;
int tempItemCode, tempItemQty;
// Exercise 06: create a method for adding items, to eliminate redundant code.
// There is something interesting, depending on how you approach it.
// Give it a go, we will discuss this next week in discussing object and class.
// Add some items into the store, like: shirt, pen, book, hat
itemName.add("Shirt");
itemCode.add(01);
itemPrice.add((float) 9.99);
itemQty.add(15);
itemDescription.add("A nice shirt");
itemName.add("Pen");
itemCode.add(02);
itemPrice.add((float) 0.99);
itemQty.add(30);
itemDescription.add("A good for writing");
itemName.add("Book");
itemCode.add(03);
itemPrice.add((float) 1.99);
itemQty.add(20);
itemDescription.add("Excellent book");
itemName.add("Hat");
itemCode.add(04);
itemPrice.add((float) 3.99);
itemQty.add(20);
itemDescription.add("Good hat");
//-----------------------------------------------------------------------------
// Exercise 01: create sing-up system. It could be another method.
//Start
// -0- Sign-up system (Optional)
// -1- Login system
// Ask user enter username and password
// Exercise 02: convert the login system into a method.
while(true) {
System.out.print("Please enter your username and password" );
// Take the username and password
tempUsername = input.nextLine();
tempPwd = input.nextLine();
// Management login details
if( tempUsername.equals( "mgnt") && tempPwd.equals("0000") ) {
managementSection();
}
// Check if it is correct login
// else show a message that invalid username or password.
else if( (username.equals(tempUsername)) && (password.equals(tempPwd) ) ) {
break;
}
else {
System.out.println("Invalid name or password");
}
}
//-----------------------------------------------------------------------------
// Exercise 03: convert this into another method.
// -2- List of products: -method
// Name Code Price Quantity Description
System.out.println( "Code \t: Name \t: Price \t: Qty\t: Description" );
for( int i=0; i< itemName.size(); i++ ) {
System.out.println(itemCode.get(i) + " \t: " + itemName.get(i) + "\t: "
+ itemPrice.get(i) + " \t\t:" + itemQty.get(i) + "\t: " + itemDescription.get(i));
}
while(true) {
// -3- Select a product
// Ask the user to enter item code
System.out.println("Please enter an item code to select the item, or 0 for payment ");
// Entering item code
tempItemCode = input.nextInt() ; // To fix???
if(tempItemCode-- == 0) { // Not a good software engineering? Think of a better way of addressing this?
paymentMethod();
// termination point
break;
}
else {
// ???
// Ask for the quantity
System.out.println("How many do you need? > ");
tempItemQty = input.nextInt();
// Check if it is available in the stock
if(itemQty.get(tempItemCode) >= tempItemQty ) {
// if available add it to the cart
addToBasket(tempItemCode, tempItemQty);
}
// else show a message out of stock
else{
System.out.println("Out of stock");
// Exercise 05: display the available quantity/
}
// -4- Show cart with the total
displayBox();
// -- Expand this as a method
}
}
// --------------------------------------------------------------------------
} // Ending of main method
private static void displayBox() {
// Name Code Price
System.out.println( "Code \t: Name \t: Price \t: Qty\t: Description" );
for( int i=0; i< basketName.size(); i++ ) {
System.out.println(basketCode.get(i) + " \t: " + basketName.get(i) + "\t: "
+ basketPrice.get(i) + " \t\t:" + basketQty.get(i) );
}
} // Ending of displaying box
// Add the specification of an item into a box
private static void addToBasket(int tempItemCode, int tempItemQty) {
basketCode.add(tempItemCode);
basketName.add( itemName.get(tempItemCode) );
basketQty.add( tempItemQty);
basketPrice.add( tempItemQty * itemPrice.get(tempItemCode));
} // Ending of thwe payment method
// A method for the payment
private static void paymentMethod() {
float cost = 0, amount;
for( int i=0; i< basketName.size(); i++ ) {
cost += basketPrice.get(i);
}
// Display the total cost
System.out.println("The total cost is " + cost );
// Exercise 04: check if the cost > 00
System.out.println("Please, enter an amount for the payment > ");
amount = input.nextFloat();
if(amount > cost ) {
System.out.println("Your change is " + (amount - cost ) );
}
System.out.println("Thank you for shopping, please take your stuff.");
// Exercise 07: reduce the quantity of the sold items?
} // Ending of the payment method
private static void managementSection() {
int option;
do{
// Create an interface for the following operations
System.out.println(" Menu \n 1 for adding an item \n 2 for removing an item"
+ " \n 3 for adding promotion \n 4 for adding vouchers "
+ " \n 0 for Exit ");
System.out.print("Please enter an option : > ");
option = input.nextInt();
switch(option) {
// Add new item
case 1:
addingItem();
break;
// Remove an item
case 2:
romovingItem();
break;
// - discount/promotion/ - managements
case 3:
addindDiscount();
break;
// - vouchers -- management
case 4:
addingVouchers();
break;
case 0:
// Exit
break;
default:
System.out.println("Invalid option, please enter a valid option");
}
}while( option != 0 );
} // Ending of the management section
private static void addingVouchers() {
// TODO Auto-generated method stub
// Exercise
}
private static void addindDiscount() {
// TODO Auto-generated method stub
// Exercise
}
private static void romovingItem() {
// TODO Auto-generated method stub
// Exercise
}
private static void addingItem() {
String tempName, tempDescription;
int tempItemCode, tempItemQty;
float tempPrice;
// Ask item name
System.out.println("Please, enter item name > ");
tempName = input.next();
// Ask item code
System.out.println("Please, enter item code > ");
tempItemCode = input.nextInt();
// Ask item price
System.out.println("Please, enter item price > ");
tempPrice = input.nextFloat();
// Ask item Qty
System.out.println("Please, enter item Qty ");
tempItemQty = input.nextInt();
// Ask item description
System.out.println("Please, enter item description ");
tempDescription = input.nextLine();
// Add the item specifications
itemName.add( tempName );
itemCode.add( tempItemCode );
itemPrice.add( tempPrice );
itemQty.add( tempItemQty );
itemDescription.add( tempDescription );
// ---------------
// Display the stocks, there should be a method but I will use the code for now.
// Name Code Price Quantity Description
System.out.println( "Code \t: Name \t: Price \t: Qty\t: Description" );
for( int i=0; i< itemName.size(); i++ ) {
System.out.println(itemCode.get(i) + " \t: " + itemName.get(i) + "\t: "
+ itemPrice.get(i) + " \t\t:" + itemQty.get(i) + "\t: " + itemDescription.get(i));
}
// ---------------
} // Ending of adding item
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>setTheory</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package setTheory;
import java.util.*;
public class set1 {
public static void main(String[] args) {
Set<String> hashSet = new HashSet<String>();
hashSet.add("My element");
System.out.println(hashSet.contains("My element"));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>shortCuts</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package shortCuts;
public class shortCut {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = -1;
int b = 11;
System.out.println(a % b);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>training</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package ysj.training;
public class first {
public static void main(String[] args) {
double value1 = 100.0d;
double value2 = 0.0d;
double result = 0.0d;
char opCode = 'd';
/* if(opCode == 'a')
result = value1 + value2;
else if(opCode == 's')
result = value1 - value2;
else if(opCode == 'm')
result = value1 * value2;
else if(opCode == 'd') {
if(value2 != 0)
result = value1 / value2;
}
else {
System.out.println("Invalid opCode: " + opCode);
result = 0.0d;
}
System.out.println(result); */
switch(opCode) {
case 'a':
result = value1 + value2;
break;
case 's':
result = value1 - value2;
break;
case 'm':
result = value1 * value2;
break;
case 'd':
result = value2 != 0 ? value1 / value2 : 0.0d;
break;
default:
System.out.println("Invalid opCode: " + opCode);
result = 0.0d;
break;
}
System.out.println(result);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>week06</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
/* This is a demo developing a shopping system (prototype)
*
* Requirement of a shopping system:
* 0- Generic description of the items:
* -name
* -code
* -price
* -quantity
* -description
* -discount/promotion -- management
* -vouchers -- management
*
* 1- List of products and cost
* 2- Cart
* 3- Search/Browsing
* 4- Payment system
* 5- Delivery options
* 6- Order confirmation
* --------------------------------------------------------------------------------------
*
* Algorithm
*
*
* Generic description of the items: name, code, price, quantity
*
* Database for the products/items: has to reflect all these components for the items
*
* Table for the cart, where a customer can store selected item before payment
* Also the cart has to capture these components of the items.
*
*
*
*
*
* Start
*-1- Login System
* Ask user enter username and password
* take username and password
* check if its correct login
* else show a message that invalid username or password
*-2- List of products: -method
* Ask the user to enter item code
* Entering item code
* Take item code
* Ask for the quantity
* Check if it is available in the stock
* if available add it to the cart
* else show a message out of stock
*-4- Show cart with the total
* --Expand this as a method
*
*/
package week06;
import java.util.ArrayList;
import java.util.Scanner;
// create a class item
class item {
//a constructor
String name;
int code;
float price;
int qty;
String description;
//Method 1
String getName() {
return name;
}
//method 2: display details of an object
String details () {
System.out.println( code + " \t: " + name + " \t: " + price + " \t: " + qty + " \t: " + description );
}
}
public class shoppingSystem {
//facility for getting input
// An object of item
// Definition of stocks
// Basket
static Scanner input = new Scanner(System.in);
//Generic description of the items: name, code, price, quantity
// Database for the products/items: has to reflect all these components for the items
// An array list to represent the database. (week 04)
static ArrayList<String> itemName = new ArrayList<String>(); //name
static ArrayList<Integer> itemCode = new ArrayList<Integer>(); //code
static ArrayList<Float> itemPrice = new ArrayList<Float>(); //price
static ArrayList<Integer> itemQty = new ArrayList<Integer>(); //quantity
static ArrayList<String> itemDescription = new ArrayList<String>(); //Description
// Table for the cart, where a customer can store selected item before payment
// Also the cart has to capture these components of the items.
static ArrayList<String> basketName = new ArrayList<String>(); //name
static ArrayList<Integer> basketCode = new ArrayList<Integer>(); //code
static ArrayList<Float> basketPrice = new ArrayList<Float>(); //price
static ArrayList<Integer> basketQty = new ArrayList<Integer>(); //quantity
static ArrayList<String> BasketDescription = new ArrayList<String>(); //Description
public static void main(String[] args) {
//Variable
String username = "aaa", password = "123", tempUsername, tempPwd;
int tempItemCode, tempItemQty;
//Exercise: create a method for adding items, to eliminate redundant code.
//Add some items into the store like: Tshirt, pen, book, hat
itemName.add("Tshirt");
itemCode.add(01);
itemPrice.add((float) 9.99);
itemQty.add(15);
itemDescription.add("A nice shirt");
itemName.add("Pen");
itemCode.add(02);
itemPrice.add((float) 0.99);
itemQty.add(30);
itemDescription.add("Perfect for writing");
itemName.add("Book");
itemCode.add(03);
itemPrice.add((float) 1.99);
itemQty.add(20);
itemDescription.add("Excellent Read");
itemName.add("Hat");
itemCode.add(04);
itemPrice.add((float) 3.99);
itemQty.add(20);
itemDescription.add("Very stylish");
// Exercise: create sign-up system, it could be another method
//Start
// 0- Sign-up system (Optional)
// 1- Login system
//Ask user to enter username and password
//check if login is correct
//else show a message displaying invalid username or password
Scanner input = new Scanner(System.in);
while(true) {
System.out.print("Please enter your username and password");
//take the username and password
tempUsername = input.nextLine();
tempPwd = input.nextLine();
//Management login details
if (tempUsername.equals ("mgnt") && tempPwd.equals("0000")) {
managementSection();
}
if( (username == tempUsername) && (password == tempPwd) ) {
break;
}
else {
System.out.println("Invalid username or password");
}
}
// -2- List of products: -method
// Name code price
System.out.println( "Code \t: Name \t: Price \t: Qty \t: Description ");
for( int i = 0; i <itemName.size(); i++) {
System.out.print(itemCode.get(i) + " : " + itemName.get(i) + " : "
+ itemPrice.get(i) + " : " + itemQty.get(i) + " : " +itemDescription.get(i));
}
// 3 select a product
//Ask user to enter an item code
System.out.println("Please enter an item code to select the item, or 0 for payment");
//entering the code
tempItemCode = input.nextInt();
if(tempItemCode == 0 ) {
paymentMethod();
//termination point
break;
}
else {
//aSK FOR QUANTITY
System.out.println("How many items do you need? >");
tempItemQty = input.nextInt();
}
//Check if it is available in the stock
if(itemQty.get(tempItemCode) == tempItemQty ) {
//If available in the stock
addToBasket(tempItemCode, tempItemQty);
//else show a message out of stock
} else {
System.out.println("Out of stock");
//exercise: display the available quantity
}
// 4 show cart with the total
paymentMethod();
}
private static void displayBox() {
System.out.println( "Code \t: Name \t: Price \t: Qty \t: Description ");
for( int i = 0; i <basketName.size(); i++) {
System.out.print(basketCode.get(i) + " : " + basketName.get(i) + " : "
+ basketPrice.get(i) + " : " + basketQty.get(i) + " : " );
}
}
//Add the specification of an item into a box
private static void addToBasket(int tempItemCode, int tempItemQty) {
basketCode.add(tempItemCode);
basketName.add( itemName.get(tempItemCode) );
basketQty.add(tempItemQty);
basketPrice.add( tempItemQty * itemPrice.get(tempItemCode));
}
private static void paymentMethod() {
float cost = 0, amount;
for (int i=0; i< basketName.size(); i++) {
cost += basketPrice.get(i);
}
//display the total cost
System.out.println("The total cost is " + cost);
System.out.println(" Please, enter an amount for the payment >");
if( amount > cost) {
System.out.print("Your change is " + (amount - cost) );
}
}
private static void managementSection() {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>whileLoop</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
package ysj.training.whileLoop;
public class whileLoop {
public static void main(String[] args) {
/*int value = 4, factorial = 1;
while(value > 1) {
factorial *= value;
value--;
}
System.out.println(factorial); */
/*int iVal = 5;
do {
System.out.print(iVal);
System.out.print(" * 2 = ");
iVal *= 2;
System.out.println(iVal);
} while(iVal < 25); */
int i, j=1;
for (i = 1; i < 100; i++) {
for(j=1; j < 100; j++);
System.out.println(i);
}
System.out.println(" + " + j);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment