From 2614ccf0432d97d8e5e1c3474ff20a6d331cf379 Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Wed, 9 Jan 2019 20:42:31 -0600 Subject: [PATCH 01/13] Calculator App --- Calculator/.classpath | 6 ++ Calculator/.project | 17 +++++ .../.settings/org.eclipse.jdt.core.prefs | 11 +++ Calculator/bin/Calculator.class | Bin 0 -> 377 bytes Calculator/bin/Test_Calculator.class | Bin 0 -> 1546 bytes Calculator/src/Calculator.java | 26 +++++++ Calculator/src/Test_Calculator.java | 68 ++++++++++++++++++ 7 files changed, 128 insertions(+) create mode 100644 Calculator/.classpath create mode 100644 Calculator/.project create mode 100644 Calculator/.settings/org.eclipse.jdt.core.prefs create mode 100644 Calculator/bin/Calculator.class create mode 100644 Calculator/bin/Test_Calculator.class create mode 100644 Calculator/src/Calculator.java create mode 100644 Calculator/src/Test_Calculator.java diff --git a/Calculator/.classpath b/Calculator/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Calculator/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Calculator/.project b/Calculator/.project new file mode 100644 index 0000000..afb56be --- /dev/null +++ b/Calculator/.project @@ -0,0 +1,17 @@ + + + Calculator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Calculator/.settings/org.eclipse.jdt.core.prefs b/Calculator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Calculator/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/Calculator/bin/Calculator.class b/Calculator/bin/Calculator.class new file mode 100644 index 0000000000000000000000000000000000000000..a646719eb11855bc306413751f5962219447116e GIT binary patch literal 377 zcmZutu};H441G@1hK4{&ix4YY0f`Q<6|q!eieM<}!sLWgxaxY5j)ebWLSo`Jq#1{F(9Oww(73gtS#Ya z`j~aj%i3vM&RaKjrLZRdjOF-c)wn|4YHyl$x))vwCyLz$#ofpfuLfI70*29Ey_$~xuK)&AS3l#Q)p{gK{DHBDM$mzJgdYFs` zD(uODrvzp@fg`=X3|%dcFAMRJ8ws56yyA9;$dPn?f%*Ekor(Ky9J>DDPNP4C^O!R* z`%-Y-r%|j%CN7}Lz=DKvR(T|@N#EJteK2nww_)*}g4Fi{1 zg49zIyI!;FNZ(hXPVrq6SFk3K)1{c?V*AI*f4Nj(;hL^`U0`t>2?IWD(&%fW>n7H5 zgMs_%r`Yyc9QMxEnhg_8-L#_P1rggQuxVlo?+cXWaOlQvK<~x6ZEN!-e4s1PVu$Ls zCJStv_)uFT=4onTLE@3joAHK?6Lx5o&8S^A#C4F9AWs+^E{ ztYHBSEaE2nwvA=nrRFoX?;%#v$3=XHOHeF@&g$zda(s&Wlxp|_ZQ2TQ+V~tc>#&A< zc)(MhycYE~3M5`bho>T$i};djiPR}P;+?^r1DVx^j9gmq(sJ#G-IZVHBdctMJIF5J zY8r=?S*1RyAW!>b?`e0yQ;t*)?pf;5S?W4p-FPGQt1*>Re3m*qOWh=O>wi=ECyl8( nc0F>&a?RUa`T18KPnV!Y?Cn!n<3$OK7bVCe3s$gQ`gQkT?7a{- literal 0 HcmV?d00001 diff --git a/Calculator/src/Calculator.java b/Calculator/src/Calculator.java new file mode 100644 index 0000000..ece430a --- /dev/null +++ b/Calculator/src/Calculator.java @@ -0,0 +1,26 @@ +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +public class Calculator { + + /** + * + */ + public Calculator() { + // TODO Auto-generated constructor stub + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} diff --git a/Calculator/src/Test_Calculator.java b/Calculator/src/Test_Calculator.java new file mode 100644 index 0000000..8c27c5d --- /dev/null +++ b/Calculator/src/Test_Calculator.java @@ -0,0 +1,68 @@ +import java.util.Scanner; + +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ + +public class Test_Calculator { + + /** + * @param args + */ + public static void main(String[] args) { + System.out.println("This is a Java Calculator"); + System.out.println("Please type a number to the console."); + Scanner reader = new Scanner(System.in); + int num1 = reader.nextInt(); + int num2 = reader.nextInt(); + reader.close(); + int sum = addition(num1 , num2); + System.out.println(sum); + int mult = multiplication(num1, num2); + System.out.println(mult); + float div = division(num1, num2); + System.out.println(div); + int sub = substraction(num1, num2); + System.out.println(sub); + // TODO Auto-generated method stub + } + + + public static int addition(int num1, int num2) { + int Total = num1 + num2; + return Total; + // TODO Auto-generated method stub + } + + public static int multiplication(int num1, int num2) { + int result = (num1 * num2); + return result; + // TODO Auto-generated method stub + } + + public static int substraction(int num1, int num2) { + int result = (num1 - num2); + return result; + // TODO Auto-generated method stub + } + public static float division(int num1, int num2) { + int result = (num1 / num2); + return result; + // TODO Auto-generated method stub + } + +// public static int addition(num1, num2 ) { +// int num1 = 1; +// int num2 = 2; +// int result = num1 + num2; +// +// // TODO Auto-generated method stub +// +// } + +} From ac40c05f5ea33ba407ce860264b4eeecf02794b5 Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Thu, 10 Jan 2019 22:38:04 -0600 Subject: [PATCH 02/13] Rock Paper Scissors --- Rock Paper Scissors game/.classpath | 6 ++ Rock Paper Scissors game/.gitignore | 1 + Rock Paper Scissors game/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ .../src/RockPaperScissor.java | 100 ++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 Rock Paper Scissors game/.classpath create mode 100644 Rock Paper Scissors game/.gitignore create mode 100644 Rock Paper Scissors game/.project create mode 100644 Rock Paper Scissors game/.settings/org.eclipse.jdt.core.prefs create mode 100644 Rock Paper Scissors game/src/RockPaperScissor.java diff --git a/Rock Paper Scissors game/.classpath b/Rock Paper Scissors game/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/Rock Paper Scissors game/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Rock Paper Scissors game/.gitignore b/Rock Paper Scissors game/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Rock Paper Scissors game/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Rock Paper Scissors game/.project b/Rock Paper Scissors game/.project new file mode 100644 index 0000000..bbd7e59 --- /dev/null +++ b/Rock Paper Scissors game/.project @@ -0,0 +1,17 @@ + + + Rock Paper Scissors game + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Rock Paper Scissors game/.settings/org.eclipse.jdt.core.prefs b/Rock Paper Scissors game/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/Rock Paper Scissors game/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/Rock Paper Scissors game/src/RockPaperScissor.java b/Rock Paper Scissors game/src/RockPaperScissor.java new file mode 100644 index 0000000..19a042c --- /dev/null +++ b/Rock Paper Scissors game/src/RockPaperScissor.java @@ -0,0 +1,100 @@ +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ + + +import java.util.Scanner; +import java.util.Random; + +public class RockPaperScissor { + + /** + * + */ + + public RockPaperScissor() { + // TODO Auto-generated constructor stub + } + + public static void main(String args[]){ + + String choice; + int num = 0; + Random r = new Random(); + num = r.nextInt(3); + + System.out.println("Select: rock, paper or scissors."); + Scanner userChoice = new Scanner(System.in); + choice=userChoice.next().toLowerCase(); + + + + switch (num){ + case 0: + String num1 = "rock"; + System.out.println("System chose Rock"); + if (choice.matches(num1)){ + System.out.println("Its a tie!"); + + } + else if (choice.matches("paper")){ + System.out.println("You win!"); + + } + else if (choice.matches("scissors")){ + System.out.println("You lose!"); + } + else { + System.out.println(); + System.out.println("ERROR: Please choose Rock, Paper or Scissors"); + } + break; + case 1: + String num2 = "paper"; + System.out.println("System chose Paper"); + if (choice.matches(num2)){ + System.out.println("Its a tie!"); + + } + else if (choice.matches("scissors")){ + System.out.println("You win!"); + + } + else if (choice.matches("rock")){ + System.out.println("You lose!"); + } + else { + System.out.println(); + System.out.println("ERROR: Please choose Rock, Paper or Scissors"); + } + break; + case 2: + String num3 = "scissors"; + System.out.println("System chose Scissors"); + if (choice.matches(num3)){ + System.out.println("Its a tie!"); + + } + else if (choice.matches("rock")){ + System.out.println("You win!"); + + } + else if (choice.matches("paper")){ + System.out.println("You lose!"); + } + else { + System.out.println(); + System.out.println("ERROR: Please choose Rock, Paper or Scissors"); + } + break; + + + } + + } +} From 6e9931a3bef7e5ec295ddeceaefc2ebd28b9fd0f Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Fri, 11 Jan 2019 22:45:32 -0600 Subject: [PATCH 03/13] Rock Paper scissors using if else --- .../src/RockPaperScissor.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Rock Paper Scissors game/src/RockPaperScissor.java b/Rock Paper Scissors game/src/RockPaperScissor.java index 19a042c..6baaed7 100644 --- a/Rock Paper Scissors game/src/RockPaperScissor.java +++ b/Rock Paper Scissors game/src/RockPaperScissor.java @@ -32,13 +32,11 @@ public static void main(String args[]){ Scanner userChoice = new Scanner(System.in); choice=userChoice.next().toLowerCase(); - - - switch (num){ - case 0: - String num1 = "rock"; - System.out.println("System chose Rock"); - if (choice.matches(num1)){ + if (num==0) + { + String num1 = "rock"; + System.out.println("System chose Rock"); + if (choice.matches(num1)){ System.out.println("Its a tie!"); } @@ -53,9 +51,11 @@ else if (choice.matches("scissors")){ System.out.println(); System.out.println("ERROR: Please choose Rock, Paper or Scissors"); } - break; - case 1: - String num2 = "paper"; + + } + else if (num==1) + { + String num2 = "paper"; System.out.println("System chose Paper"); if (choice.matches(num2)){ System.out.println("Its a tie!"); @@ -72,9 +72,10 @@ else if (choice.matches("rock")){ System.out.println(); System.out.println("ERROR: Please choose Rock, Paper or Scissors"); } - break; - case 2: - String num3 = "scissors"; + } + else if (num==2) + { + String num3 = "scissors"; System.out.println("System chose Scissors"); if (choice.matches(num3)){ System.out.println("Its a tie!"); @@ -91,10 +92,9 @@ else if (choice.matches("paper")){ System.out.println(); System.out.println("ERROR: Please choose Rock, Paper or Scissors"); } - break; - - } + + } } From 76bb6f3e0d646067044f4e32b84e8f29530a239d Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Sat, 12 Jan 2019 10:27:28 -0600 Subject: [PATCH 04/13] PigLatin translation from English --- PigLatin/.classpath | 6 + PigLatin/.gitignore | 1 + PigLatin/.project | 17 +++ PigLatin/.settings/org.eclipse.jdt.core.prefs | 11 ++ PigLatin/src/PigLatinString.java | 112 ++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 PigLatin/.classpath create mode 100644 PigLatin/.gitignore create mode 100644 PigLatin/.project create mode 100644 PigLatin/.settings/org.eclipse.jdt.core.prefs create mode 100644 PigLatin/src/PigLatinString.java diff --git a/PigLatin/.classpath b/PigLatin/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/PigLatin/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/PigLatin/.gitignore b/PigLatin/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/PigLatin/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/PigLatin/.project b/PigLatin/.project new file mode 100644 index 0000000..1221824 --- /dev/null +++ b/PigLatin/.project @@ -0,0 +1,17 @@ + + + PigLatin + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/PigLatin/.settings/org.eclipse.jdt.core.prefs b/PigLatin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/PigLatin/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/PigLatin/src/PigLatinString.java b/PigLatin/src/PigLatinString.java new file mode 100644 index 0000000..20b2765 --- /dev/null +++ b/PigLatin/src/PigLatinString.java @@ -0,0 +1,112 @@ +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +//public class PigLatinString { +// +// /** +// * +// */ +// public PigLatinString() { +// // TODO Auto-generated constructor stub +// } +// +// /** +// * @param args +// */ +// public static void main(String[] args) { +// // TODO Auto-generated method stub +// +// } +// +//} + + + +import java.util.Scanner; + + + +public class PigLatinString + +{ + + public static void main(String[] args) + + { + + Scanner stdIn=new Scanner(System.in); + + String word; + String newWord = ""; + + + + String repeatAgain = "y"; + + + + while (repeatAgain.equals("Y") || repeatAgain.equals("y")) + + { + + System.out.print("\f"); + + System.out.print("Enter a word: "); + + word=stdIn.nextLine().toLowerCase(); + + + + + if (!word.contains("a") || !word.contains("e") || !word.contains("i") || !word.contains("o") || !word.contains("u")) + { + newWord= word + "ay"; + } + + if ((word.charAt(0) =='a' || word.charAt(0)=='e' || word.charAt(0)=='i' || word.charAt(0)=='0' || word.charAt(0)=='u')) + { + newWord= word + "yay"; + } + + else + { + int index = 0; + for (int i=1;i Date: Tue, 22 Jan 2019 19:17:22 -0600 Subject: [PATCH 05/13] Collect Stats --- CollectStatistics/.classpath | 6 + CollectStatistics/.gitignore | 1 + CollectStatistics/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ CollectStatistics/src/CollectStats.java | 111 ++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 CollectStatistics/.classpath create mode 100644 CollectStatistics/.gitignore create mode 100644 CollectStatistics/.project create mode 100644 CollectStatistics/.settings/org.eclipse.jdt.core.prefs create mode 100644 CollectStatistics/src/CollectStats.java diff --git a/CollectStatistics/.classpath b/CollectStatistics/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/CollectStatistics/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/CollectStatistics/.gitignore b/CollectStatistics/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/CollectStatistics/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/CollectStatistics/.project b/CollectStatistics/.project new file mode 100644 index 0000000..b68cefa --- /dev/null +++ b/CollectStatistics/.project @@ -0,0 +1,17 @@ + + + CollectStatistics + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CollectStatistics/.settings/org.eclipse.jdt.core.prefs b/CollectStatistics/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/CollectStatistics/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/CollectStatistics/src/CollectStats.java b/CollectStatistics/src/CollectStats.java new file mode 100644 index 0000000..fdc60ca --- /dev/null +++ b/CollectStatistics/src/CollectStats.java @@ -0,0 +1,111 @@ +import java.util.ArrayList; +import java.util.Scanner; +public class CollectStats { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + Scanner in = new Scanner(System.in); + System.out.println("Please enter a list of numbers"); + + String[] numarray= in.nextLine().split(","); + + FindNumberofElements(numarray); + + Average (numarray); + + FindMinValue(numarray); + + FindMaxValue(numarray); + + Sum(numarray); + + } + private static void FindMinValue(String[] intArray) + { + + int min = Integer.parseInt(intArray[0]); + for(int i=1;i< intArray.length;i++){ + + if (min > Integer.parseInt(intArray[i])) + { + min = Integer.parseInt(intArray[i]); + } + } + System.out.println("Minimum Value is " + min); + + } + + private static void FindMaxValue(String[] intArray) + { + int max = Integer.parseInt(intArray[0]); + for(int i=1;i< intArray.length;i++){ + + if (max < Integer.parseInt(intArray[i])) + { + max = Integer.parseInt(intArray[i]); + } + } + System.out.println("Maximum Value is " + max); + + } + + private static void FindNumberofElements(String[] intArray) + { + int cnt=intArray.length; + System.out.println("Count is:" + cnt); + + } + + + + private static void Average(String[] intArray) + { + ArrayList numbers= new ArrayList(); + int sum=0; + double average; + for (int i=0;i numbers= new ArrayList(); + int sum=0; + double average; + for (int i=0;i Date: Tue, 22 Jan 2019 19:24:23 -0600 Subject: [PATCH 06/13] Rick paper scissors using try catch --- .../src/RockPaperScissor.java | 66 ++++++++++++++----- .../src/TryCatchRockPaper.java | 59 +++++++++++++++++ 2 files changed, 107 insertions(+), 18 deletions(-) create mode 100644 Rock Paper Scissors game/src/TryCatchRockPaper.java diff --git a/Rock Paper Scissors game/src/RockPaperScissor.java b/Rock Paper Scissors game/src/RockPaperScissor.java index 6baaed7..4cf0c77 100644 --- a/Rock Paper Scissors game/src/RockPaperScissor.java +++ b/Rock Paper Scissors game/src/RockPaperScissor.java @@ -24,19 +24,43 @@ public RockPaperScissor() { public static void main(String args[]){ String choice; - int num = 0; + int num1 = 0; Random r = new Random(); - num = r.nextInt(3); + num1 = r.nextInt(3); System.out.println("Select: rock, paper or scissors."); + try + { Scanner userChoice = new Scanner(System.in); choice=userChoice.next().toLowerCase(); - - if (num==0) + switch (num1) { - String num1 = "rock"; + case 0: + ChoosePlayer1(choice); + break; + case 1: + ChoosePlayer2 (choice); + break; + case 2: + ChoosePlayer3(choice); + break; + } + } + catch (Exception e) + { + System.out.println("Exception:" + e.toString()); + } + + + + } + + private static void ChoosePlayer1(String choice) { + // TODO Auto-generated method stub + + String num2 = "rock"; System.out.println("System chose Rock"); - if (choice.matches(num1)){ + if (choice.matches(num2)){ System.out.println("Its a tie!"); } @@ -52,12 +76,14 @@ else if (choice.matches("scissors")){ System.out.println("ERROR: Please choose Rock, Paper or Scissors"); } - } - else if (num==1) - { - String num2 = "paper"; + + } + private static void ChoosePlayer2(String choice) + { + + String num3 = "paper"; System.out.println("System chose Paper"); - if (choice.matches(num2)){ + if (choice.matches(num3)){ System.out.println("Its a tie!"); } @@ -72,9 +98,11 @@ else if (choice.matches("rock")){ System.out.println(); System.out.println("ERROR: Please choose Rock, Paper or Scissors"); } - } - else if (num==2) - { + + } + private static void ChoosePlayer3(String choice) + { + String num3 = "scissors"; System.out.println("System chose Scissors"); if (choice.matches(num3)){ @@ -92,9 +120,11 @@ else if (choice.matches("paper")){ System.out.println(); System.out.println("ERROR: Please choose Rock, Paper or Scissors"); } - } - - - + } + + + + + } diff --git a/Rock Paper Scissors game/src/TryCatchRockPaper.java b/Rock Paper Scissors game/src/TryCatchRockPaper.java new file mode 100644 index 0000000..8ff6fcd --- /dev/null +++ b/Rock Paper Scissors game/src/TryCatchRockPaper.java @@ -0,0 +1,59 @@ +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +import java.util.Arrays; +public class TryCatchRockPaper { + + + public static void main(String[] args) { + + try { + + String message = "Hello World"; + System.out.println("Message Length:" + message.length()); + char myChar = message.charAt(15); + System.out.println(myChar); + throw new NullPointerException("message to user"); + + }catch (Exception e) { + + System.out.println("Your code therew an exception:" + e.toString()); + + +}finally { + + +} + } + + + // TODO Auto-generated method stub + +public static void helpermethod() { + +} +} + + + + + +//class Main { +// public static void main(String args[]) { +// int a[] = new int[2]; +// try { +// System.out.println("Access element three :" + a[3]); +// }catch(ArrayIndexOutOfBoundsException e) { +// System.out.println("Exception thrown :" + e); +// }finally { +// a[0] = 6; +// System.out.println("First element value: " + a[0]); +// System.out.println("The finally statement is executed"); +// } +// } +// } \ No newline at end of file From 51447e19dff8b406503c9f05b2b984aa51181d9a Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Tue, 22 Jan 2019 19:29:21 -0600 Subject: [PATCH 07/13] Tic Tac Toe Java --- TicTacToe/.classpath | 6 + TicTacToe/.gitignore | 1 + TicTacToe/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ TicTacToe/src/TicTacToe.java | 176 ++++++++++++++++++ 5 files changed, 211 insertions(+) create mode 100644 TicTacToe/.classpath create mode 100644 TicTacToe/.gitignore create mode 100644 TicTacToe/.project create mode 100644 TicTacToe/.settings/org.eclipse.jdt.core.prefs create mode 100644 TicTacToe/src/TicTacToe.java diff --git a/TicTacToe/.classpath b/TicTacToe/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TicTacToe/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TicTacToe/.gitignore b/TicTacToe/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TicTacToe/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TicTacToe/.project b/TicTacToe/.project new file mode 100644 index 0000000..d6bf9b5 --- /dev/null +++ b/TicTacToe/.project @@ -0,0 +1,17 @@ + + + TicTacToe + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TicTacToe/.settings/org.eclipse.jdt.core.prefs b/TicTacToe/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TicTacToe/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/TicTacToe/src/TicTacToe.java b/TicTacToe/src/TicTacToe.java new file mode 100644 index 0000000..98022f4 --- /dev/null +++ b/TicTacToe/src/TicTacToe.java @@ -0,0 +1,176 @@ +import java.util.Scanner; + + +public class TicTacToe +{ + private int counter; + private char posn[]=new char[10]; + private char player; + + + public static void main(String args[]) + { + String ch; + TicTacToe Toe=new TicTacToe(); + do{ + Toe.newBoard(); + Toe.play(); + System.out.println ("Would you like to play again (Enter 'yes')? "); + Scanner in =new Scanner(System.in); + ch=in.nextLine(); + System.out.println("ch value is "+ch); + }while (ch.equals("yes")); + + + } + public void newBoard() + { + + char posndef[] = {'0','1', '2', '3', '4', '5', '6', '7', '8', '9'}; + int i; + counter = 0; + player = 'X'; + for (i=1; i<10; i++) posn[i]=posndef[i]; + currentBoard(); + + + } + public String currentBoard() + { + System.out.println( "\n\n" ); + System.out.println( "\n\n" ); + System.out.println( "\n\n\t\t" + posn [1] + " | " +posn [2]+ " | " +posn [3]); + System.out.println( " \t\t | | " ); + System.out.println( " \t\t ___|____|___ " ); + System.out.println( "\n\n\t\t" +posn [4]+ " | " +posn [5]+ " | " +posn [6]); + System.out.println( " \t\t | | " ); + System.out.println( " \t\t ___|____|___ " ); + System.out.println( "\n\n\t\t" +posn [7]+ " | " +posn [8]+ " | " +posn [9]); + System.out.println( " \t\t | | " ); + System.out.println( " \t\t | | " ); + System.out.println( "\n\n" ); + return "currentBoard"; + } + + public void play() + { + int spot; + char blank = ' '; + + System.out.println( "Player " + getPlayer() +" will go first and be the letter 'X'" ); + + do { + currentBoard(); // display current board + + System.out.println( "\n\n Player " + getPlayer() +" choose a posn." ); + + boolean posTaken = true; + while (posTaken) { + // System.out.println( "position is taken, please enter a valid space"); + Scanner in =new Scanner (System.in); + spot=in.nextInt(); + posTaken = checkPosn(spot); + if(posTaken==false) + posn[spot]=getPlayer(); + } + + System.out.println( "Nice move." ); + + currentBoard(); // display current board + + nextPlayer(); + }while ( checkWinner() == blank ); + + } + + public char checkWinner() + { + char Winner = ' '; + + // Check if X wins + if (posn[1] == 'X' && posn[2] == 'X' && posn[3] == 'X') Winner = 'X'; + if (posn[4] == 'X' && posn[5] == 'X' && posn[6] == 'X') Winner = 'X'; + if (posn[7] == 'X' && posn[8] == 'X' && posn[9] == 'X') Winner = 'X'; + if (posn[1] == 'X' && posn[4] == 'X' && posn[7] == 'X') Winner = 'X'; + if (posn[2] == 'X' && posn[5] == 'X' && posn[8] == 'X') Winner = 'X'; + if (posn[3] == 'X' && posn[6] == 'X' && posn[9] == 'X') Winner = 'X'; + if (posn[1] == 'X' && posn[5] == 'X' && posn[9] == 'X') Winner = 'X'; + if (posn[3] == 'X' && posn[5] == 'X' && posn[7] == 'X') Winner = 'X'; + if (Winner == 'X' ) + {System.out.println("Player1 wins the game." ); + return Winner; + } + + // Check if O wins + if (posn[1] == 'O' && posn[2] == 'O' && posn[3] == 'O') Winner = 'O'; + if (posn[4] == 'O' && posn[5] == 'O' && posn[6] == 'O') Winner = 'O'; + if (posn[7] == 'O' && posn[8] == 'O' && posn[9] == 'O') Winner = 'O'; + if (posn[1] == 'O' && posn[4] == 'O' && posn[7] == 'O') Winner = 'O'; + if (posn[2] == 'O' && posn[5] == 'O' && posn[8] == 'O') Winner = 'O'; + if (posn[3] == 'O' && posn[6] == 'O' && posn[9] == 'O') Winner = 'O'; + if (posn[1] == 'O' && posn[5] == 'O' && posn[9] == 'O') Winner = 'O'; + if (posn[3] == 'O' && posn[5] == 'O' && posn[7] == 'O') Winner = 'O'; + if (Winner == 'O' ) + { + System.out.println( "Player2 wins the game." ); + return Winner; } + + // check for Tie + for(int i=1;i<10;i++) + { + if(posn[i]=='X' || posn[i]=='O') + { + if(i==9) + { + char Draw='D'; + System.out.println(" Game is stalemate "); + return Draw; + } + continue; + } + else + break; + + } + + return Winner; + } + + public boolean checkPosn(int spot) + { + + + if (posn[spot] == 'X' || posn[spot] == 'O') + { + System.out.println("That posn is already taken, please choose another"); + return true; + } + else { + return false; + } + + // counter++; + // return false; + } + + + + public void nextPlayer() + { + if (player == 'X') + player = 'O'; + else player = 'X'; + + } + + public String getTitle() + { + return "Tic Tac Toe" ; + } + + public char getPlayer() + { + return player; + } + +} \ No newline at end of file From df7fc04ec4a0788c3efe863e712d43fea2cc1181 Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Tue, 29 Jan 2019 13:56:55 -0600 Subject: [PATCH 08/13] Grade Book Assignment --- GradeBook/.classpath | 6 ++ GradeBook/.gitignore | 1 + GradeBook/.project | 17 ++++ .../.settings/org.eclipse.jdt.core.prefs | 11 +++ GradeBook/src/GradeBookAssignment.java | 92 +++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 GradeBook/.classpath create mode 100644 GradeBook/.gitignore create mode 100644 GradeBook/.project create mode 100644 GradeBook/.settings/org.eclipse.jdt.core.prefs create mode 100644 GradeBook/src/GradeBookAssignment.java diff --git a/GradeBook/.classpath b/GradeBook/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/GradeBook/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/GradeBook/.gitignore b/GradeBook/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/GradeBook/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/GradeBook/.project b/GradeBook/.project new file mode 100644 index 0000000..53d01ac --- /dev/null +++ b/GradeBook/.project @@ -0,0 +1,17 @@ + + + GradeBook + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/GradeBook/.settings/org.eclipse.jdt.core.prefs b/GradeBook/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/GradeBook/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/GradeBook/src/GradeBookAssignment.java b/GradeBook/src/GradeBookAssignment.java new file mode 100644 index 0000000..e3d013f --- /dev/null +++ b/GradeBook/src/GradeBookAssignment.java @@ -0,0 +1,92 @@ +import java.util.Scanner; +import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map.Entry; +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +public class GradeBookAssignment { + + /** + * + */ + public GradeBookAssignment() { + // TODO Auto-generated constructor stub + } + + /** + * @param args + */ + public static void main(String[] args) { + + + + System.out.println("Enter total number of students"); + Scanner reader = new Scanner(System.in); + String totStudents = reader.nextLine(); + int intNoofStudents= Integer.parseInt(totStudents); + HashMap Studentgrades = new HashMap(); + + /* double Average =0;*/ + //Loop to enter the name of the student with comma separated grades and inserting into the + for (int i=0;i< intNoofStudents; i++) + { + + System.out.println("Please enter name of student"); + String name=reader.nextLine(); + System.out.println("Please enter comma separated grades of student"); + String grades= reader.nextLine(); + Studentgrades.put(name, grades); //Storing the value in the HashMap + String[] splitLine = grades.split(",");//Split the grades from the comma separated values + int[] ints = new int[splitLine.length]; + double sum=0; + //Loop to parse the splitline array and calculate the sum + for (int j=0;j< splitLine.length;j++) + { + ints[j]=Integer.parseInt(splitLine[j]); + sum = sum + ints[j]; //Summation of grades + } + //Helper method to calculate the Average + CalculateAverage(Studentgrades,sum,splitLine); + + } + + + reader.close(); + } + + //Calculates the Average from the HashMap StudentGrades. Prints the Name of the student with the Average from the + //MapStudentAverage - Stores the Name and the Average and prints the same from the Map. + //Sum is the value of adding the grades calculated above in the main method + //splitline is an array to store the grades + public static void CalculateAverage (HashMap Studentgrades, double sum,String[] splitLine) + { + double Average =0; + String CurrentName=""; + + ArrayList Studentnames = new ArrayList(Studentgrades.keySet()); + for (int ii = 0; ii < Studentnames.size(); ii++) { + CurrentName = Studentnames.get(ii); + String grade = Studentgrades.get(CurrentName); + } + + Average = sum/splitLine.length; + //Map to store the name and the average + Map StudentAverage = new HashMap(); + StudentAverage.put(CurrentName, Average); + //Print the Map + System.out.println(StudentAverage); + + } + + + + +} From 40b32fb71a3f15e072523701d567818ed74d6a39 Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Wed, 6 Feb 2019 15:31:27 -0600 Subject: [PATCH 09/13] Grade book assignment --- GradeBook/src/GradeBookAssignment.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/GradeBook/src/GradeBookAssignment.java b/GradeBook/src/GradeBookAssignment.java index e3d013f..7dea524 100644 --- a/GradeBook/src/GradeBookAssignment.java +++ b/GradeBook/src/GradeBookAssignment.java @@ -47,14 +47,17 @@ public static void main(String[] args) { String[] splitLine = grades.split(",");//Split the grades from the comma separated values int[] ints = new int[splitLine.length]; double sum=0; - //Loop to parse the splitline array and calculate the sum + //Loop to parse the splitline array and calculate t he sum for (int j=0;j< splitLine.length;j++) { ints[j]=Integer.parseInt(splitLine[j]); sum = sum + ints[j]; //Summation of grades } //Helper method to calculate the Average - CalculateAverage(Studentgrades,sum,splitLine); + double Average = CalculateAverage(Studentgrades,sum,splitLine); + + + } @@ -66,7 +69,7 @@ public static void main(String[] args) { //MapStudentAverage - Stores the Name and the Average and prints the same from the Map. //Sum is the value of adding the grades calculated above in the main method //splitline is an array to store the grades - public static void CalculateAverage (HashMap Studentgrades, double sum,String[] splitLine) + public static double CalculateAverage (HashMap Studentgrades, double sum,String[] splitLine) { double Average =0; String CurrentName=""; @@ -82,7 +85,11 @@ public static void CalculateAverage (HashMap Studentgrades, doubl Map StudentAverage = new HashMap(); StudentAverage.put(CurrentName, Average); //Print the Map + System.out.println(StudentAverage); + + return Average; + } From 136b711d4ee4e0ecef19d829efb97d8d1764d0a8 Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Wed, 6 Feb 2019 15:37:25 -0600 Subject: [PATCH 10/13] Drivers lincense --- DriverLicense/.classpath | 6 + DriverLicense/.gitignore | 1 + DriverLicense/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ DriverLicense/src/DriverLicense.java | 116 ++++++++++++++++++ DriverLicense/src/LicenseProgram.java | 88 +++++++++++++ 6 files changed, 239 insertions(+) create mode 100644 DriverLicense/.classpath create mode 100644 DriverLicense/.gitignore create mode 100644 DriverLicense/.project create mode 100644 DriverLicense/.settings/org.eclipse.jdt.core.prefs create mode 100644 DriverLicense/src/DriverLicense.java create mode 100644 DriverLicense/src/LicenseProgram.java diff --git a/DriverLicense/.classpath b/DriverLicense/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/DriverLicense/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/DriverLicense/.gitignore b/DriverLicense/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/DriverLicense/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/DriverLicense/.project b/DriverLicense/.project new file mode 100644 index 0000000..64f7fa1 --- /dev/null +++ b/DriverLicense/.project @@ -0,0 +1,17 @@ + + + DriverLicense + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/DriverLicense/.settings/org.eclipse.jdt.core.prefs b/DriverLicense/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/DriverLicense/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/DriverLicense/src/DriverLicense.java b/DriverLicense/src/DriverLicense.java new file mode 100644 index 0000000..95116b8 --- /dev/null +++ b/DriverLicense/src/DriverLicense.java @@ -0,0 +1,116 @@ +import java.sql.Date ; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.Period; +import java.util.Calendar; +import java.util.Scanner; + +public class DriverLicense { + + //Attributes for the Drivers License + public String firstName; + public String lastName; + public String dob; + public String height; + public String Gender; + + public DriverLicense() { + + + } + + //get property for first name + public String getFirstName () + { + return firstName; + + } + //set property for first name + public void setFirstName(String DriversFirstName) { + firstName = DriversFirstName; + } + + + //get property for Last name + public String getLastName() + { + return lastName; + } + + //set property for Last name + public void setLastName(String DriversLastName) { + lastName = DriversLastName; + } + + //get property for DOB + public String getDateofBirth() + { + return dob; + + } + //set property for DOB + public void setDateofBirth(String DriversDateofBirth) { + dob = DriversDateofBirth; + } + + public String getHeight() + { + return height; + + } + + public void setHeight(String DriversHeight) { + height = DriversHeight; + } + + public String getGender() + { + return Gender; + + } + + public void setGender(String DriversGender) { + Gender = DriversGender; + } + + + + //Concatenates the first name and Last Name to give Full Name + public String getFullName(String FirstName, String LastName) + { + String FullName= String.join(" ",FirstName,LastName); + + return FullName; + + + } + + //Calculates Age + public int getAge(LocalDate birthDate,LocalDate currentDate) + { + if ((birthDate !=null) && (currentDate!=null)) + { + return Period.between(birthDate, currentDate).getYears(); + } + else + { + return 0; + } + + } + + + + + + + + + + + + + + +} diff --git a/DriverLicense/src/LicenseProgram.java b/DriverLicense/src/LicenseProgram.java new file mode 100644 index 0000000..109cbd1 --- /dev/null +++ b/DriverLicense/src/LicenseProgram.java @@ -0,0 +1,88 @@ +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.Scanner; + + +public class LicenseProgram { + + public LicenseProgram() { + // TODO Auto-generated constructor stub + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + + //Driver 1 details + DriverLicense driver1 = new DriverLicense(); + driver1.firstName = "AB"; + driver1.lastName = "AC"; + driver1.dob = "05/20/1999"; + driver1.height = "5 ft"; + driver1.Gender = "Male"; + + //Driver 2 details + DriverLicense driver2 = new DriverLicense(); + driver2.firstName = "XY"; + driver2.lastName = "YZ"; + driver2.dob = "01/26/2000"; + driver2.height = "5 ft 3 inches"; + driver2.Gender = "Female"; + + //Driver 3 details + DriverLicense driver3 = new DriverLicense(); + driver3.firstName = "CD"; + driver3.lastName = "EF"; + driver3.dob = "06/11/2003"; + driver3.height = "5 ft 8 inches"; + driver3.Gender = "Male"; + + //Date formatter for converting date into mm/dd/yyyy format + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); + + + + //Full concatenated name of Driver 1 + String FullName1 = driver1.getFullName(driver1.firstName,driver1.lastName); + System.out.print("Full Name: " + FullName1); + LocalDate birthDate1 = LocalDate.parse(driver1.dob,formatter); + //Current Date + LocalDate currentDate1 = LocalDate.now(); + int Age1 = driver1.getAge(birthDate1, currentDate1); + System.out.println(" Age: " + Age1); + System.out.println(" Height: " + driver1.getHeight()); + System.out.println(" Gender: " + driver1.getGender()); + System.out.println(); + System.out.println("**********************************"); + System.out.println(); + + //Full concatenated name of Driver 2 + String FullName2 = driver2.getFullName(driver2.firstName,driver2.lastName); + System.out.println("Full Name: " + FullName2); + LocalDate birthDate2 = LocalDate.parse(driver2.dob,formatter); + //Current Date + LocalDate currentDate2 = LocalDate.now(); + int Age2 = driver1.getAge(birthDate2, currentDate2); + System.out.println(" Age: " + Age1); + System.out.println(" Height: " + driver1.getHeight()); + System.out.print(" Gender: " + driver1.getGender()); + System.out.println(); + System.out.println("**********************************"); + System.out.println(); + + //Full concatenated name of Driver 3 + String FullName3 = driver3.getFullName(driver3.firstName,driver3.lastName); + System.out.println("Full Name: " + FullName3); + LocalDate birthDate = LocalDate.parse(driver3.dob,formatter); + //Current Date + LocalDate currentDate = LocalDate.now(); + int Age3 = driver1.getAge(birthDate, currentDate); + System.out.println(" Age: " + Age3); + System.out.println(" Height: " + driver3.getHeight()); + System.out.println(" Gender: " + driver3.getGender()); + System.out.println(); + + + } + +} From e1e828785d7518c5c2aa362271b693490079dbca Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Fri, 8 Feb 2019 16:52:45 -0600 Subject: [PATCH 11/13] Timesheet App --- TimesheetApp/.classpath | 6 + TimesheetApp/.gitignore | 1 + TimesheetApp/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 + TimesheetApp/src/ConsoleUtils.java | 112 ++++++++ TimesheetApp/src/Controller.java | 246 ++++++++++++++++++ TimesheetApp/src/Main.java | 36 +++ TimesheetApp/src/Timesheet.java | 24 ++ TimesheetApp/src/TimesheetEntry.java | 89 +++++++ 9 files changed, 542 insertions(+) create mode 100644 TimesheetApp/.classpath create mode 100644 TimesheetApp/.gitignore create mode 100644 TimesheetApp/.project create mode 100644 TimesheetApp/.settings/org.eclipse.jdt.core.prefs create mode 100644 TimesheetApp/src/ConsoleUtils.java create mode 100644 TimesheetApp/src/Controller.java create mode 100644 TimesheetApp/src/Main.java create mode 100644 TimesheetApp/src/Timesheet.java create mode 100644 TimesheetApp/src/TimesheetEntry.java diff --git a/TimesheetApp/.classpath b/TimesheetApp/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/TimesheetApp/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/TimesheetApp/.gitignore b/TimesheetApp/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/TimesheetApp/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/TimesheetApp/.project b/TimesheetApp/.project new file mode 100644 index 0000000..c5b5e8c --- /dev/null +++ b/TimesheetApp/.project @@ -0,0 +1,17 @@ + + + TimesheetApp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TimesheetApp/.settings/org.eclipse.jdt.core.prefs b/TimesheetApp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/TimesheetApp/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/TimesheetApp/src/ConsoleUtils.java b/TimesheetApp/src/ConsoleUtils.java new file mode 100644 index 0000000..5553163 --- /dev/null +++ b/TimesheetApp/src/ConsoleUtils.java @@ -0,0 +1,112 @@ +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; + +public class ConsoleUtils { + + /* Member variables */ + + private Scanner scanner; + private DateTimeFormatter timeFormatter; + + /* Constructor */ + + public ConsoleUtils(){ + scanner = new Scanner(System.in); + timeFormatter = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm"); + } + + /* Methods */ + + /* + * Prints the menu of actions to the console + */ + public void printHelp(){ + System.out.println("Valid commands: "); + System.out.println(" list [PROJECT] [-a] list entries; project and/or active flag are optional"); + System.out.println(" add add an entry, and set the start time"); + System.out.println(" stop ID update the entry's end time"); + System.out.println(" delete ID delete entry with the ID"); + System.out.println(" help print help"); + System.out.println(" quit quit the app"); + System.out.println(); + + } + + /* + * Prints an informational message to the console + */ + public void info(String msg){ + System.out.println("["+msg+"]"); + System.out.println(); + } + + /* + * Prints an error message to the console + */ + public void error(String msg){ + System.out.println("[ERROR: "+msg+"]"); + System.out.println(); + } + + /* + * Prompts the user to enter input + * Returns the text entered by the user + */ + public String promptString(String label){ + System.out.print(label+" "); + return scanner.nextLine(); + } + + /* + * Prints a list of TimesheetEntry objects in a pretty table + */ + public void printList(List entries){ + int longestProject = 7; + int longestTask = 4; + + for(TimesheetEntry entry : entries){ + if(entry.getProjectName().length() > longestProject){ + longestProject = entry.getProjectName().length(); + } + if(entry.getTask().length() > longestTask) { + longestTask = entry.getTask().length(); + } + } + + String projectHeader = String.format("%"+longestProject+"s", "Project"); + String projectUnderline = ""; + for(int i=0;i "); + String[] actionParts = input.split(" "); + String action = actionParts[0].trim(); // Primary action + + // Figure out what to do depending on the user's primary action + if (action.equals("add")) { + + processAddAction(); + + } else if (action.equals("delete")) { + + processDeleteAction(actionParts); + + } else if (action.equals("stop")) { + + processStopAction(actionParts); + + } else if (action.equals("list")) { + + processListAction(actionParts); + + } else if (action.equals("quit")) { + + processQuitAction(actionParts); + + } else if (action.equals("help")) { + + processHelpAction(actionParts); + + } else if(action.length() ==0 ){ + + // do nothing. + + } else { + + quit = true; + + } + } + + } + + private void printProjectList(String projname2) { + // TODO Auto-generated method stub + + } + + /* + * The user requested that a given TimesheetEntry be stopped (marked as complete) + * This method conveys that request to the Timesheet + */ + public void processStopAction(String[] actionParts){ + + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to stop command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + // Your code here + } + + /* + * The user requested that a given TimesheetEntry be deleted + * This method conveys that request to the Timesheet + */ + public void processDeleteAction(String[] actionParts){ + + if(actionParts.length > 2){ + consoleUtils.error("Too many inputs to delete command"); + return; + } + + int id = Integer.parseInt(actionParts[1]); + + // Your code here + } + + /* + * The user wants to view a list of timesheet entries + * This method conveys that request to the Timesheet, + * along with any special options (active-only, filter by project name) + */ + public void processListAction(String[] actionParts){ + + if(actionParts.length > 3){ + consoleUtils.error("Too many inputs to list command"); + return; + } + + // Print the entire project list + private static void processListAction(Roster myController) { + List projectList = myController.getProjectList(); + for (int i = 0; i < projectList.size(); i++) { + TimesheetEntry currProj = projectList.get(i); + System.out.println("Id: " + currProj.getId() + + ", Name: " + currProj.getProjName() + + ", Task: " + currProj.getTask() + + ", Start Date: " + currProj.getStartDate() + + ", End Date: " + currProj.getEndDate()); + } + } + + // Given the employee id, find them in the list and print their info + private static void printProject(Roster myRoster, int id) { + List projectList = myRoster.getProjectList(); + for (int i = 0; i < projectList.size(); i++) { + Project currProj = projectList.get(i); + int currId = currProj.getId(); + if (currId == id) { + System.out.println("Id: " + currProj.getId() + + ", Name: " + currProj.getProjName() + + ", Task: " + currProj.getTask() + + ", Start Date: " + currProj.getStartDate() + + ", End Date: " + currProj.getEndDate()); + } + } + } + } + + /* + * The user wants to add a new entry to the Timesheet + * This method conveys that request to the Timesheet, along with + * the specified project name and task description + */ + public void processAddAction(){ + + String project = consoleUtils.promptString("Project Name (one word only):"); + String description = consoleUtils.promptString("Task:"); + + // Your code here + } + + +public void processHelpAction(String[] actionParts){ + + if(actionParts.length == 4){ + consoleUtils.error("Too many inputs to delete command"); + return; + } + + int id = Integer.parseInt(actionParts[4]); + + // Your code here +} + +public void processQuitAction(String[] actionParts){ + + if(actionParts.length == 0){ + consoleUtils.error("Too many inputs to delete command"); + return; + } + + int id = Integer.parseInt(actionParts[5]); + + else if (firstCommand.equals("quit")) { + quit = true; + } else { + System.out.println("Invalid input, please try again"); + } +} +} \ No newline at end of file diff --git a/TimesheetApp/src/Main.java b/TimesheetApp/src/Main.java new file mode 100644 index 0000000..b5a8fcc --- /dev/null +++ b/TimesheetApp/src/Main.java @@ -0,0 +1,36 @@ +import java.util.List; +import java.util.Scanner; + +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +public class Main { + + /** + * + */ + public Main() { + // TODO Auto-generated constructor stub + } + + /** + * @param args + */ + public static void main(String[] args) { + + Controller myController = new Controller(); + myController.start(); + } + + + + +} + + + diff --git a/TimesheetApp/src/Timesheet.java b/TimesheetApp/src/Timesheet.java new file mode 100644 index 0000000..e0f33c7 --- /dev/null +++ b/TimesheetApp/src/Timesheet.java @@ -0,0 +1,24 @@ +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +import java.util.ArrayList; +import java.util.List; + +public class Timesheet { + private List database; + + public Timesheet() { + database = new ArrayList<>(); + } + + public void add(String project, String task) { + String ProjectName = project; + String taskName = task; + } + +} \ No newline at end of file diff --git a/TimesheetApp/src/TimesheetEntry.java b/TimesheetApp/src/TimesheetEntry.java new file mode 100644 index 0000000..e13491a --- /dev/null +++ b/TimesheetApp/src/TimesheetEntry.java @@ -0,0 +1,89 @@ +import java.time.LocalDate; +import java.time.LocalDateTime; + +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +public class TimesheetEntry { + + private static int NEXTID = 1; + + private String projectName; + private String task; + private int id; + private LocalDateTime startTime; + private LocalDateTime endTime; + + + public TimesheetEntry(String myProject, String myTask) { + projectName = myProject; + task = myTask; + startTime = LocalDateTime.now(); + id = NEXTID; + NEXTID++;// increment + + // TODO Auto-generated constructor stub + } + + // Methods + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getProjName() { + return projectName; + } + + public void setProjName(String name) { + this.projectName = name; + } + + public String getTask() { + return task; + } + + public void setTask(String Task) { + this.task = Task; + } + + public LocalDateTime getStartDate () + { + return startTime; + } + + public void setStarttDate (LocalDateTime StartTime) + { + this.startTime= StartTime; + } + + + public LocalDateTime getEndDateTime () + { + return startTime; + } + + public void setEndDateTime (LocalDateTime EndDateTime) + { + this.endTime= EndDateTime; + } + + public void updateEndTime () { + startTime = LocalDateTime.now(); + } + + + +} + + + From 22025a6b81484a05d73a6558570af78994e58a17 Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Tue, 19 Feb 2019 23:00:11 -0600 Subject: [PATCH 12/13] Parking Garage assignment --- ParkingGarageManager/.classpath | 6 ++ ParkingGarageManager/.gitignore | 1 + ParkingGarageManager/.project | 17 ++++ .../.settings/org.eclipse.jdt.core.prefs | 11 +++ ParkingGarageManager/src/GarageManager.java | 83 +++++++++++++++++ ParkingGarageManager/src/ParkingGarage.java | 88 +++++++++++++++++++ ParkingGarageManager/src/car.java | 71 +++++++++++++++ 7 files changed, 277 insertions(+) create mode 100644 ParkingGarageManager/.classpath create mode 100644 ParkingGarageManager/.gitignore create mode 100644 ParkingGarageManager/.project create mode 100644 ParkingGarageManager/.settings/org.eclipse.jdt.core.prefs create mode 100644 ParkingGarageManager/src/GarageManager.java create mode 100644 ParkingGarageManager/src/ParkingGarage.java create mode 100644 ParkingGarageManager/src/car.java diff --git a/ParkingGarageManager/.classpath b/ParkingGarageManager/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/ParkingGarageManager/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/ParkingGarageManager/.gitignore b/ParkingGarageManager/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/ParkingGarageManager/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/ParkingGarageManager/.project b/ParkingGarageManager/.project new file mode 100644 index 0000000..d6b5bc8 --- /dev/null +++ b/ParkingGarageManager/.project @@ -0,0 +1,17 @@ + + + ParkingGarageManager + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ParkingGarageManager/.settings/org.eclipse.jdt.core.prefs b/ParkingGarageManager/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/ParkingGarageManager/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/ParkingGarageManager/src/GarageManager.java b/ParkingGarageManager/src/GarageManager.java new file mode 100644 index 0000000..5364546 --- /dev/null +++ b/ParkingGarageManager/src/GarageManager.java @@ -0,0 +1,83 @@ +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +public class GarageManager { + + /** + * + */ + public GarageManager() { + // TODO Auto-generated constructor stub + } + + /** + * @param args + */ + public static void main(String[] args) { + + //Instances of the Parking Garage + ParkingGarage pk1 = new ParkingGarage(1); + ParkingGarage pk2 = new ParkingGarage(2); + ParkingGarage pk3 = new ParkingGarage(3); + + + car c1 = new car(); + c1.color="blue"; + c1.license="KJ87"; + c1.model="civic"; + c1.make="Honda"; + + car c2 = new car(); + c2.color="brown"; + c2.license="JK87"; + c2.model="camry"; + c2.make="Toyota"; + + car c3 = new car(); + c3.color="gray"; + c3.license="HJ434"; + c3.model="camry"; + c3.make="Toyota"; + + car c4 = new car(); + c4.color="Silver"; + c4.license="MLK87"; + c4.model="Rav4"; + c4.make="Toyota"; + + pk1.Park(c1, 1); + System.out.println("Inventory for garage 1"); + pk1.printInventory(); + pk1.Park(c1, 2); + System.out.println("Inventory for garage 1"); + pk1.printInventory(); + + pk2.Park(c2, 1); + System.out.println("Inventory for garage 2"); + pk2.printInventory(); + pk2.Park(c2, 2); + System.out.println("Inventory for garage 2"); + pk2.printInventory(); + + pk3.Park(c3, 1); + System.out.println("Inventory for garage 3"); + pk3.printInventory(); + pk3.Park(c2, 2); + System.out.println("Inventory for garage 3"); + pk3.printInventory(); + + pk1.vacate(2); + System.out.println("Inventory for garage 2"); + pk1.printInventory(); + pk2.vacate(1); + + System.out.println("Inventory for garage 2"); + pk2.printInventory(); + } + +} diff --git a/ParkingGarageManager/src/ParkingGarage.java b/ParkingGarageManager/src/ParkingGarage.java new file mode 100644 index 0000000..e1ca149 --- /dev/null +++ b/ParkingGarageManager/src/ParkingGarage.java @@ -0,0 +1,88 @@ + + public class ParkingGarage { + + // the ParkingGarage class has + // 2 fields + public int chkspot; + public car[] chkcar; + + + // the ParkingGarage class has one constructor + public ParkingGarage(int chkspot) { + chkspot = chkspot; + chkcar= new car[chkspot]; + + } + + // This method will show if the parking spot is filled. + public void Park(car car, int spot) + { + + try { + if (chkcar[spot] == null) { + chkcar[spot] = car; + } else { + System.out.println("The spot is already filled in please choose another spot"); + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Parking Spot does not Exist. Please select from available spot"); + } + + + + } + //This method is used to vacate the car for the selected spot + public void vacate(int spot) + { + + try + { + if (chkcar[spot] == null) + { + + System.out.println("There is no car at the spot"); + + } + else + { + chkcar[spot] = null; + } + } + catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Parking Spot does not Exist.Please select from available spot "); + } + + + + } + // This method will print the inventory of the car. + //This also displays the empty spot and the details about the car. + public void printInventory() + { + + System.out.println("Spot number:" + chkcar); + + + for (int i=0; i< chkspot; i++) + { + if (chkcar[i]== null) + { + System.out.println ("Spot is empty:" + i); + } + else + { + System.out.println("License: " + chkcar[i].license + "Make: " + chkcar[i].make + "Color: " + chkcar[i].color + "Model: " + chkcar[i].model ); + + } + + + } + } + + + } + + + + + diff --git a/ParkingGarageManager/src/car.java b/ParkingGarageManager/src/car.java new file mode 100644 index 0000000..adf0b77 --- /dev/null +++ b/ParkingGarageManager/src/car.java @@ -0,0 +1,71 @@ +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +public class car { + //Attributes of the car + public String color; + public String make; + public String model; + public String license; + + + + /** + * + */ + public String getModel() { +// // TODO Auto-generated constructor stub + return model; +} + + +public void setModel(String myModel) +{ + + this.model = myModel; +} + + +public String getLicense() +{ + + return license; +} + +public void setLicense(String myLicense) { + this.license = myLicense; + +} + +public String getMake() { + return make; +} + + +public void setMake(String myMake) +{ + + this.make = myMake; +} + + +public String getcolor() { + + return make; +} + + +public void setcolor(String myColor) +{ + + this.color = myColor; +} + + +} + From 11bdf635f86f739f776c123884935946c2f636e3 Mon Sep 17 00:00:00 2001 From: Gurumoorthy Date: Tue, 19 Feb 2019 23:01:36 -0600 Subject: [PATCH 13/13] Car lot assignment --- CarLot/.classpath | 6 ++ CarLot/.gitignore | 1 + CarLot/.project | 17 ++++++ CarLot/.settings/org.eclipse.jdt.core.prefs | 11 ++++ CarLot/src/Car.java | 11 ++++ CarLot/src/CarLot.java | 45 +++++++++++++++ CarLot/src/CarLotProgram.java | 53 +++++++++++++++++ CarLot/src/Truck.java | 9 +++ CarLot/src/Vehicle.java | 63 +++++++++++++++++++++ 9 files changed, 216 insertions(+) create mode 100644 CarLot/.classpath create mode 100644 CarLot/.gitignore create mode 100644 CarLot/.project create mode 100644 CarLot/.settings/org.eclipse.jdt.core.prefs create mode 100644 CarLot/src/Car.java create mode 100644 CarLot/src/CarLot.java create mode 100644 CarLot/src/CarLotProgram.java create mode 100644 CarLot/src/Truck.java create mode 100644 CarLot/src/Vehicle.java diff --git a/CarLot/.classpath b/CarLot/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/CarLot/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/CarLot/.gitignore b/CarLot/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/CarLot/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/CarLot/.project b/CarLot/.project new file mode 100644 index 0000000..eb1d294 --- /dev/null +++ b/CarLot/.project @@ -0,0 +1,17 @@ + + + CarLot + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CarLot/.settings/org.eclipse.jdt.core.prefs b/CarLot/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/CarLot/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +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.source=1.8 diff --git a/CarLot/src/Car.java b/CarLot/src/Car.java new file mode 100644 index 0000000..dadfc65 --- /dev/null +++ b/CarLot/src/Car.java @@ -0,0 +1,11 @@ +//Car extends the Vehicle +public class Car extends Vehicle { + + public String Type; + public int Noofdoors; + + public Car() { + + } + +} diff --git a/CarLot/src/CarLot.java b/CarLot/src/CarLot.java new file mode 100644 index 0000000..ed75d5d --- /dev/null +++ b/CarLot/src/CarLot.java @@ -0,0 +1,45 @@ +import java.util.ArrayList; +import java.util.List; + +public class CarLot { + + public String Lotname; + public List listofVehicles; + public CarLot() { + // TODO Auto-generated constructor stub + listofVehicles= new ArrayList(); + } + + // Setting the lot Name + public void setLotName(String name) { + Lotname = name; + } + + public String getLotName() { + return Lotname; + } + // Adding the Vehicle + public void AddVehicle(Vehicle myvehicle) + { + listofVehicles.add(myvehicle); + } + //Printing the inventory of the vehicle + public void PrintInventory () + { + System.out.println("------------------------------------"); + System.out.println("Inventory of CarLot :"+ Lotname); + System.out.println("------------------------------------"); + int numberOfVehicles = listofVehicles.size(); + System.out.println("Total number of vehicles in the Lot are :"+ numberOfVehicles); + System.out.println("************List of vehicles********************"); + for (int i=0;i< listofVehicles.size();i++) { + System.out.println("Vehicle Number# "+(i+1)+" |License: "+listofVehicles.get(i).getLicenseNumber() + +"| Make: "+ listofVehicles.get(i).getMake() + +"| Model: "+ listofVehicles.get(i).getModel() + +"| Price: "+ listofVehicles.get(i).getPrice()); + } + + + } + +} diff --git a/CarLot/src/CarLotProgram.java b/CarLot/src/CarLotProgram.java new file mode 100644 index 0000000..2b7eae6 --- /dev/null +++ b/CarLot/src/CarLotProgram.java @@ -0,0 +1,53 @@ + +public class CarLotProgram { + + public CarLotProgram() { + + } + // Main program to print the Vehicle details + public static void main(String[] args) { + + CarLot CL1 = new CarLot(); + CarLot CL2 = new CarLot(); + + //Setting the name of the Parking lot + CL1.setLotName("PaidParking"); + CL2.setLotName("EventParking"); + //Initializing the cars with the license + Car car1 = new Car(); + car1.Type = "Sedan"; + car1.Noofdoors = 2; + car1.setLicenseNumber("REBT231"); + car1.setMake("Mercedes"); + car1.setModel("R320"); + car1.setPrice(60000); + + Car car2 = new Car(); + car2.Type = "SUV"; + car2.Noofdoors = 4; + car2.setLicenseNumber("FTRD4543"); + car2.setMake("Honda"); + car2.setModel("accord"); + car2.setPrice(25000); + + Truck tk = new Truck(); + tk.bedSize=2; + tk.setLicenseNumber("GHTY2345"); + tk.setMake("Dodge"); + tk.setModel("RAM"); + tk.setPrice(70000); + + //Adding the vehicle to the carlot + CL1.AddVehicle(car1); + CL1.AddVehicle(car2); + //Printing the inventory + CL1.PrintInventory(); + //Adding the truck to the car lot + CL2.AddVehicle(tk); + CL2.PrintInventory(); + + + + } + +} diff --git a/CarLot/src/Truck.java b/CarLot/src/Truck.java new file mode 100644 index 0000000..84f890d --- /dev/null +++ b/CarLot/src/Truck.java @@ -0,0 +1,9 @@ +//Truck extends Vehicle +public class Truck extends Vehicle { + + int bedSize; + public Truck() { + // TODO Auto-generated constructor stub + } + +} diff --git a/CarLot/src/Vehicle.java b/CarLot/src/Vehicle.java new file mode 100644 index 0000000..b21ee1a --- /dev/null +++ b/CarLot/src/Vehicle.java @@ -0,0 +1,63 @@ +/** + * + */ + +/** + * @author Laxmi_Gurumoorthy + * + */ +public abstract class Vehicle { + + public String licensenumber; + public String make; + public String model; + public int price; + + /** + * + */ + public Vehicle() { + // TODO Auto-generated constructor stub + } + + public void setLicenseNumber(String licenseNumber) { + this.licensenumber = licenseNumber; + } + + public String getLicenseNumber() { + return licensenumber; + } + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public void setModel(String model) { + this.model = model; + } + + public String getModel() { + return model; + } + + public void setPrice(int price) { + this.price = price; + } + + public int getPrice() { + return price; + } + //methods + //method to print details of the car + public void printDescription() { + System.out.println("License: "+licensenumber + +"Make: "+ make + +"Model: "+ model + +"Price: "+ price); + } + +}