Concept explainers
JAVA
Please modify this program ASAP BECAUSE the program down below does not pass all the test cases when I upload it to hypergrade. The program must pass the test case when uploaded to Hypergrade.
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class MorseEncoder {
private static HashMap<Character, String> codeMappings = new HashMap<>();
public static void main(String[] args) {
initializeMappings();
Scanner textScanner = new Scanner(System.in);
System.out.println("Please enter a string to convert to Morse code::");
String textForEncoding = textScanner.nextLine().toUpperCase();
if ("ENTER".equals(textForEncoding)) {
System.out.println();
return;
}
String encodedOutput = encodeText(textForEncoding);
System.out.println(encodedOutput);
}
private static void initializeMappings() {
try (BufferedReader mappingFile = new BufferedReader(new FileReader("morse.txt"))) {
String lineContent;
while ((lineContent = mappingFile.readLine()) != null) {
if(lineContent.length() < 5) {
continue;
}
char alphaChar = lineContent.charAt(0);
String morseString = lineContent.substring(4);
codeMappings.put(alphaChar, morseString);
}
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
}
private static String encodeText(String textForEncoding) {
StringBuilder encodedStringBuilder = new StringBuilder();
for (char individualChar : textForEncoding.toCharArray()) {
if (individualChar == ' ') {
encodedStringBuilder.append(" ");
continue;
}
String morseSymbol = codeMappings.get(individualChar);
if (morseSymbol != null) {
encodedStringBuilder.append(morseSymbol);
encodedStringBuilder.append(' ');
}
}
return encodedStringBuilder.toString();
}
}
0 -----
1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.
, --..--
. .-.-.-
? ..--..
A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.-
R .-.
S ...
T -
U ..-
V ...-
W .--
X -..-
Y -.--
Z --..
Test Case 1
ENTER
\n
Test Case 2
abcENTER
.- -... -.-. \n
Test Case 3
This is a sample string 1234.ENTER
- .... .. ... .. ... .- ... .- -- .--. .-.. . ... - .-. .. -. --. .---- ..--- ...-- ....- .-.-.- \n
Step by stepSolved in 5 steps with 9 images
- import org.firmata4j.IODevice;import org.firmata4j.Pin;import org.firmata4j.firmata.FirmataDevice;import org.firmata4j.ssd1306.SSD1306;import java.io.IOException;import java.util.HashMap;import java.util.TimerTask;public class minorproj extends TimerTask {static String recLog = "\"/dev/cu.usbserial-0001\"";static IODevice myGroveBoard;private final SSD1306 theOledObject;private Pin MoistureSensor;private Pin WaterPump;private Pin Button;private int sampleCount;public minorproj(SSD1306 theOledObject, Pin Button, Pin MoistureSensor, Pin WaterPump) {this.theOledObject = theOledObject;this.Button = Button;this.MoistureSensor = MoistureSensor;this.WaterPump = WaterPump;this.sampleCount = 0;}double startTime = System.currentTimeMillis();@Overridepublic void run() {while (true) {{// check if button is pressedif (this.Button.getValue() == 1) {break; // exit loop and stop program}String VolValue = String.valueOf(MoistureSensor.getValue());System.out.println("Moisture Sensor Value:" +…arrow_forwardJava Program Fix this Rock, Paper and scissor program so I can upload it to Hypergrade and it can pass all the test cases. Here is the program, please fix thses program when I upload it to Hypergrade it does not pass the test cases and I can input any seeds as a command line. Also I do not need any thanks for playing or goodbye in the program: import java.util.Random; import java.util.Scanner; public class RockPaperScissors { public static void main(String[] args) { if (args.length != 1) { System.out.println("Please provide a seed as a command line argument."); return; } long seed = Long.parseLong(args[0]); Random random = new Random(seed); Scanner scanner = new Scanner(System.in); System.out.println("Enter 1 for rock, 2 for paper, and 3 for scissors."); do { int computerChoice = random.nextInt(3) + 1; // Fix computer choice range. int userChoice =…arrow_forwardMake the code below offer three ways of to display output.GUI window or Print on screen or save to text file. import randomclass Circle(): def __init__(self, radius=1.0): self.__radius = radius self.__area = self.find_area() def get_radius(self): return self.__radius def set_radius(self, radius): self.__radius = radius def find_area(self): self.__area = 3.14159265 * self.__radius ** 2 return self.__area def display(self): self.find_area() print('Circle, Area of Circle: {:.2f}'.format(self.__area))class Square(): def __init__(self, side=1.0): self.__side = side self.__area = self.find_area() def get_side(self): return self.__side def set_side(self, side): self.__side = side def find_area(self): self.__area = self.__side ** 2 return self.__area def display(self): self.find_area() print('Square, Area of Square: {:.2f}'.format(self.__area))class Cube(): def…arrow_forward
- Please help how do I make the code show on the black screen instead of a txt.file. By the way I have already created a txt.file in this java compiler called Data.txtarrow_forwardjavaarrow_forwardsandbox $ javac Eggs.javaEggs.java:5: error: cannot find symbol Scanner scan= new Scanner(system.in); ^ symbol: variable system location: class EggsEggs.java:7: error: package system does not exist system.out.println("How many eggs?"); ^Eggs.java:14: error: package system does not exist system.out.println("You ordered "+eggs+" eggs. That's "+dozens+" at $3.25 per dozen and "+ind+" loose eggs at 45 cents for a total of $" +((dozens*3.25)+(ind*0.45))+"."); ^3 errorssandbox $ java EggsError: Could not find or load main class Eggssandbox $ I keep getting errors!arrow_forward
- please code in java..refer the 2 codes BankAccount and AccountTest.. BankAccount source code is given below and AccountTest source code is added in image Question is to add code to be able to lock the account. for example if someone withdraws a certain amount of money the accounts locks, etc /** The BankAccount class simulates a bank account.*/ public class BankAccount{ private double balance; // Account balance /** This constructor sets the starting balance at 0.0. */ public BankAccount() { balance = 0.0; } /** This constructor sets the starting balance to the value passed as an argument. @param startBalance The starting balance. */ public BankAccount(double startBalance) { balance = startBalance; } /** This constructor sets the starting balance to the value in the String argument. @param str The starting balance, as a String. */ public BankAccount(String str) { balance =…arrow_forwardStringFun.java import java.util.Scanner; // Needed for the Scanner class 2 3 /** Add a class comment and @tags 4 5 */ 6 7 public class StringFun { /** * @param args not used 8 9 10 11 12 public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter your first name: "); 13 14 15 16 17 18 System.out.print("Please enter your last name: "); 19 20 21 //Output the welcome message with name 22 23 24 //Output the length of the name 25 26 27 //Output the username 28 29 30 //Output the initials 31 32 33 //Find and output the first name with switched characters 34 //All Done! } } 35 36 37arrow_forwardJAVA PROGRAM ASAP There is an extra space in the program down below as shown in the screesshot. Please modify this program even more ASAP BECAUSE the program down below does not pass all the test cases when I upload it to hypergrade. The program must pass the test case when uploaded to Hypergrade. import java.util.HashMap;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.Scanner;public class MorseEncoder { private static HashMap<Character, String> codeMappings = new HashMap<>(); public static void main(String[] args) { initializeMappings(); Scanner textScanner = new Scanner(System.in); System.out.println("Please enter a string to convert to Morse code:"); String textForEncoding = textScanner.nextLine().toUpperCase(); if ("ENTER".equals(textForEncoding)) { System.out.println(); return; } String encodedOutput = encodeText(textForEncoding);…arrow_forward
- import org.firmata4j.IODevice;import org.firmata4j.Pin;import org.firmata4j.firmata.FirmataDevice;import org.firmata4j.ssd1306.SSD1306;import java.io.IOException;import java.util.HashMap;import java.util.TimerTask;public class minorproj extends TimerTask {static String recLog = "\"/dev/cu.usbserial-0001\"";static IODevice myGroveBoard;private final SSD1306 theOledObject;private Pin MoistureSensor;private Pin WaterPump;private Pin Button;private int sampleCount;public minorproj(SSD1306 theOledObject, Pin Button, Pin MoistureSensor, Pin WaterPump) {this.theOledObject = theOledObject;this.Button = Button;this.MoistureSensor = MoistureSensor;this.WaterPump = WaterPump;this.sampleCount = 0;}double startTime = System.currentTimeMillis();@Overridepublic void run() {while (true) {{// check if button is pressedif (this.Button.getValue() == 1) {break; // exit loop and stop program}String VolValue = String.valueOf(MoistureSensor.getValue());System.out.println("Moisture Sensor Value:" +…arrow_forwardIt's a fun program to make, I am just short on time.. import java.util.Scanner; class Employee { private final String firstName; private final String lastName; private final String socialSecurityNumber; public Employee(String f, String l, String ssn){ this.firstName = f; this.lastName = l; this.socialSecurityNumber = ssn; } public String getFirstName(){ return this.firstName; } public String getLastName(){ return this.lastName; } public String getSocialSecurityNumber(){ return this.socialSecurityNumber; } public String toString(){ return String.format("%s: %s %s%n%s: %s", "employee", getFirstName(), getLastName(), "social security number", getSocialSecurityNumber()); }} Create an HourlyEmployee class that inherits from Employee (I have the code copied below). Remember, HourlyEmployees get paid an hourly wage with time-and-a-half—1.5 times the hourly…arrow_forwardCreate a Java instance class named Rectangle that has two integer fields named length and width. Include two onstructors: a default constructor to initialize each of the fields to 1 and a second constructor that takes two rguments. Define a getter method for each of the fields.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education