java - Convert String to Double? -


This is a two part code with a tester class. For some reason I can not understand how this string variable is correctly included in the equation granulation = grade - .3 and the granadum = grade + 0.3. any idea?

  / ** This is my class grade * / public class grade {private string grade; Private double grade no; // Constructor public grade (string shograte) {grade = showGrade; Gradence = 0; } // Getumrikik Grade method of grade number public double Milegetrigure (to) (if (GradekequalsIgnoreCase ( "A") || Gred.aksalagyatkas ( "A +")) {Grednm = 4.0;} else if (GradekequalsIgnoreCase ( "A-")) {gradeNum = 3.7;} if (grade.equalsIgnoreCase ( "B")) {gradeNum = 3.0;} else if (Gred.amenls ignore case ( "B +")) {Grednum = 3.3; } else if (grade.equalsIgnoreCase ( "B-")) {gradeNum = 2.7;} if (Gred.amenls ignore case ( "C")) {gradeNum = 2.0;} if (grade.equalsIgnoreCase ( "C +" )) {GradeNum = 2.3;} and if (Grade.Emangel's Eganore Case ("C-")) {Gradnam = 1.7} (Gred.amenls ignore case ( "D")) {gradeNum = 1.0;} else if (Gred.amenls ignore case ( "D +")) {Grednm = 1.3;} else if (GradekequalsIgnoreCase ( "D-" )) {gradeNum = .7;} if (Gred.amenls ignore case ( "F")) {Grednm = 0.0;} return grade no; System.out.println ( "invalid letter grades"); return -1.0;} } / ** This is my class tester / / import Java Util.Scanner; / ** This program checks numerical grades with a given letter grade. * / Public class gradester {public static zero main (string [] args) {scanner = new scanner (System.in); System.out.println ("Enter a letter grade:"); String shogred = in. NXtine (); Grade gg = new grade (shograt); System.out.print ("numeric value:"); Println (gg.getNumericGrade ()); In.close (); }}  

David & amp; Ken's answers are correct. You have to implement both of them and additionally, if you have to remove additional return statements, the code will work as expected. Here's an example:

  if (Character.toUpperCase (grade.charAt (0)) == 'B') Gradence = 3.0; If (grade. Lang ()> gt; 1 & amp; amp; amp; amp; amp; amp; & amp; amp; amp; amp; amp; amp; amp; amp; amp; character. Return grades No; < / Code> 

Before, when you are checking from grade.equalsIgnoreCase ("B") , this does not match in the form of "B-" for input If there is an account, the grammarum will not be named as 3.0 . It will still be 0.0 and then granumum = grade-nm - 0.3; , which results in -0.3 .

In addition, if you have multiple statements Switch switches can make it more elegant / readable and efficient.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -