HarrJ

Day 14

Aug 15th, 2023 (edited)
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 KB | None | 0 0
  1. public class Day14B {
  2.     public static void main(String[] args) {
  3.         String message = "Vdpsoh Whaw";//"Sample Text";
  4.         char[] charArray = message.toCharArray();
  5.         int shiftAmount = 3;
  6.         for (int i = 0; i < charArray.length; i++) {
  7.             if (Character.isLetter(charArray[i])) {
  8.                 char shifted = (char) (charArray[i] + shiftAmount);
  9.                 if ((Character.isUpperCase(charArray[i]) && shifted > 'Z')
  10.                     || (Character.isLowerCase(charArray[i]) && shifted > 'z') ) {
  11.                     shifted -= 26;
  12.                 }
  13.                 charArray[i] = shifted;
  14.             }
  15.         }
  16.         String encMsg = new String(charArray);
  17.         System.out.println("Original String: " + message);
  18.         System.out.println("Caesar Cipher: " + encMsg);
  19.     }
  20.    
  21.     String encryptMsg() {
  22.         String result="";
  23.        
  24.         return result;
  25.     }
  26. }
  27.  
  28. //-------------------------------------------------------
  29. package week3;
  30.  
  31. public class Day14D extends SampleParent { // 1 parent class only
  32.     public static void main(String[] args) {
  33.         Day14D callMe = new Day14D();
  34.        
  35.         System.out.println("12 + 9.82 = " + callMe.sum(12, 9.82));
  36.         callMe.printLorem();
  37.         System.out.println("4.22 + 6.7 + 12.86 = " + callMe.sum(4.22, 6.7, 12.86));
  38.         System.out.println("4.25 + 19.50 + 15.75 + 42.75 = "
  39.                 + callMe.sum(4.25, 19.50, 15.75, 42.75));
  40.         System.out.println("-------------");
  41.         double[] numArray = {28.01, 23.56, 25.64, 20.11, 17.55, 5.36, 10.46};
  42.         System.out.println(callMe.sum(numArray));
  43.     }
  44.  
  45.     @Override
  46.     void printLorem() {
  47.         super.printLorem();
  48.         System.out.print("Donec mollis ex id ipsum imperdiet,");
  49.         System.out.print(" ultricies euismod metus facilisis. ");
  50.         System.out.println("Aliquam nec ullamcorper dui. ");
  51.     }
  52.  
  53.     // method overloading
  54.     Double sum(double n1, double n2, double n3) {
  55.         double result = super.sum(n1, n2) + n3;
  56.        
  57.         return result;
  58.     }
  59.  
  60.     Double sum(double n1, double n2, double n3, double n4) {
  61.         double result = sum(n1, n2, n3) + n4;
  62.        
  63.         return result;
  64.     }
  65.    
  66.     double sum(double[] numList) {
  67.         double result = 0;
  68.         // add a formula here that will compute the total of all the numbers in an array
  69.         return result;
  70.     }
  71. }
  72.  
  73. class SampleParent {
  74.     Double sum(double n1, double n2) {
  75.         double result = n1 + n2;
  76.        
  77.         return result;
  78.     }
  79.    
  80.     void printLorem() {
  81.         System.out.print("Lorem ipsum dolor sit amet,");
  82.         System.out.print("consectetur adipiscing elit, ");
  83.         System.out.print("sed do eiusmod tempor incididunt ");
  84.         System.out.println("ut labore et dolore magna aliqua.");
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment