-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/example/sping_portfolio/controllers/KiraLightSequence.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.example.sping_portfolio.controllers; | ||
|
||
public class KiraLightSequence { | ||
String sequence = ""; | ||
|
||
public KiraLightSequence(String seq) | ||
{ | ||
sequence = seq; | ||
} | ||
|
||
public void display(){ | ||
System.out.println("The light sequence is " + this.sequence); | ||
} | ||
|
||
public String getSequence(){ | ||
String string = this.sequence; | ||
return string; | ||
} | ||
|
||
public void changeSequence(String seq) | ||
{ | ||
this.sequence = seq; | ||
} | ||
|
||
public String insertSegment(String segment, int ind) | ||
{ | ||
String newSequence = this.sequence.substring(0, ind + 1) | ||
+ segment | ||
+ this.sequence.substring(ind + 1); | ||
|
||
return newSequence; | ||
|
||
} | ||
|
||
public static String newSequence(String oldSeq, String segment){ | ||
int index = oldSeq.indexOf(segment); | ||
String newSeq = oldSeq.substring(0, index) + oldSeq.substring(index + segment.length()); | ||
|
||
return newSeq; | ||
} | ||
|
||
public static int squareRoot(double a, double b){ | ||
double root = (Math.sqrt(a*a + b*b)); | ||
return (int)root; | ||
} | ||
|
||
|
||
public static void main(String args[]) | ||
{ | ||
KiraLightSequence gradshow = new KiraLightSequence("0101 0101 0101"); | ||
gradshow.display(); | ||
|
||
gradshow.changeSequence("0011 0011 0011"); | ||
gradshow.display(); | ||
|
||
System.out.println(gradshow.insertSegment("1111 1111", 4)); | ||
System.out.println(newSequence("1100000111", "11")); | ||
System.out.println(squareRoot(4, 0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters