Question: Here is the assignment: Using loops with the String and Character classes. You can also use the StringBuilder class to concatenate on the error messages.
Here is the assignment: Using loops with the String and Character classes. You can also use the StringBuilder class to concatenate on the error messages. Floating point literals can be expressed as digits with one decimal point or using scientific notation. The only valid characters are digits (0 through 9) At most one decimal point. At most one occurrence of the letter E At most two positive or negative signs. examples of valid expressions: 3.14159 -2.54 2.453E3 66.3E-5 Write a class definition file that has a String field to hold a possible floating point number. Name this class ValidateFloat. Write a method in ValidateFloat that returns true if the String is a valid floating point literal and false if it is not valid. Use other methods in your ValidateFloat class to create a modular solution. Write a Driver class with main( ) that prompts the user to enter candidate strings and prints a message stating whether the entry is a valid floating point number or not. For 10 additional extra credit points, print all the reasons why an expression that is not valid fails the tests. Remember, all the printing is done in main( ). The program ends when the user enters quit Here is the answer you have posted: package driverfloat; import java.util.Scanner; public class DriverFloat { public static void main(String[] args) { String result,num; Scanner input=new Scanner(System.in); System.out.println("Enter a floating point number: "); num=input.next(); ValidateFloat vf=new ValidateFloat(num); result=vf.isValid(); if(result.equalsIgnoreCase("Valid")) System.out.println("This is a valid floating point number"); else System.out.println("Error: "+result); } } /ValidateFloat.java package driverfloat; public class ValidateFloat { String fpNumber; public ValidateFloat(String num) { fpNumber=num; } String isValid() { if(hasDecimalPoint()) if(hasValidCharacters()) if(hasAtMostOneE()) if(hasAtMostTwoSign()) return "Valid"; else return "Contains more than two signs."; else return "More than one E"; else return "Has invaild characters"; else return "Doesn't contain decimal point"; } boolean hasDecimalPoint() { for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
