Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0

    Java Program is getting terminated


    Hello my homework is to create a console application that will determine the students grade. The console application should take in 2 parameters. Parameter 1 should take in the school Id, the second parameter should take in the number grade. The program will return the name of the school, letter grade, description, and GPA seperated by commas. For example, if an end user enters 1 for school id, and grade number 90, the console application will display WidgetSchool_1,P,Passing,2.0.


    The code for the second part widgetschool_2 is not displaying anything. It just terminates after accepting two input.

    Can someone help me fixed the error I don't know what is wrong? Also the way I am writing it with if and else statement is it correct?? Any simpler way to write this type of program?? Thanks!!

    Here's the code.

    package main;

    import java.util.Scanner;

    public class Grade {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.print("Enter School Id (1,2,3, and 4): ");
    Scanner scanner = new Scanner(System.in);
    int inputSchoolId = scanner.nextInt();

    scanner = new Scanner(System.in);
    System.out.print("Enter Numeric Grade: ");
    float inputGrade = scanner.nextFloat();

    String letter = "F", description="Failing", gpa="0.0";
    String schoolName = "";

    if (inputSchoolId == 1){
    schoolName = "WidgetSchool_1";

    if (inputGrade >= 93){
    letter = "A";
    description = "Excellent";
    gpa = "4.0";}
    else if(inputGrade >=90){
    letter = "A-";
    description = "Great";
    gpa = "3.6";}
    else if(inputGrade >=87){
    letter = "B+";
    description = "Very Good";
    gpa = "3.2";}
    else if(inputGrade >=84){
    letter = "B";
    description = "Good";
    gpa = "2.8";}
    else if(inputGrade >=81){
    letter = "B-";
    description = "Pretty Good";
    gpa = "2.4";}
    else if(inputGrade >=78){
    letter = "C+";
    description = "Above Average";
    gpa = "2.0";}
    else if(inputGrade >=75){
    letter = "C";
    description = "Average";
    gpa = "1.6";}
    else if(inputGrade >=72){
    letter = "C-";
    description = "Below Average";
    gpa = "1.2";}
    else if(inputGrade >=69){
    letter = "D";
    description = "Barely Passing";
    gpa = "1.0";}


    if (inputSchoolId == 2){
    schoolName = "WidgetSchool_2";

    if (inputGrade >= 90){
    letter = "A";
    description = "Excellent";
    gpa = "4.0";}
    else if(inputGrade >=80){
    letter = "B";
    description = "Great";
    gpa = "3.6";}
    else if(inputGrade >=70){
    letter = "C";
    description = "Very Good";
    gpa = "3.2";}
    else if(inputGrade >=60){
    letter = "D";
    description = "Good";
    gpa = "2.8";}
    else{
    letter = "F";
    description = "Pretty Good";
    gpa = "2.4";}

    if (inputSchoolId == 3){
    schoolName = "WidgetSchool_3";
    }
    if (inputSchoolId == 4){
    schoolName = "WidgetSchool_4";
    }

    System.out.println(schoolName+","+letter+","+description+","+gpa);

    }

    }
    }
    }
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,719
    Rep Power
    348
    Can you copy the contents of the console from when you execute the program and paste it here?

    Please edit your post and wrap your code with
    [code]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    Originally Posted by NormR
    Can you copy the contents of the console from when you execute the program and paste it here?

    Please edit your post and wrap your code with
    [code]
    <terminated> Grade [Java Application] C:Program Files\Java\jre7\bin\javaw.exe (Feb15, 2013 11:00:53 AM)

    Enter School Id (1,2,3, and 4): 2
    Enter Numeric Grade: 90

    [/code]
    to get highlighting and preserve formatting.
    I get no output for the 2nd if statement I wrote for the widgetschool_2. Earlier on I was able to get it to display the description, gpa, but then it doesnt display the widgetschool_2. if you type 1 and then a grade it works for the widgetschool_1.

    Oh and I'm using Eclipse Java EE IDK to write the code.
    Thanks!!
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,719
    Rep Power
    348
    Please edit your post and wrap your code with
    [code]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    The lack of formatting on the code makes it very hard to read.

    Is this the program's output?

    Enter School Id (1,2,3, and 4): 2
    Enter Numeric Grade: 90
    Last edited by NormR; February 15th, 2013 at 11:32 AM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    yes the program prompts me to enter school id and a numeric grade. then when i enter it i get the error of terminated. <terminated> Grade [Java Application] C:Program Files\Java\jre7\bin\javaw.exe (Feb15, 2013 11:00:53 AM)

    and then nothing prints out. try it with enter school id 1 and then any number grade and it will work for the widgetschool_1 so i'm trying to get the second code to work so i can do the same for school id 3 and 4.

    sorry about the formatting i should really fix that. but let me know what is wrong something with my if and else statement or the way i placed the variable in the front for the string letter, gpa, description, string school name etc??


    this is the direction i'm suppose to do for my hw.

    Create a console application that will determine the students grade. The console application should take in 2 parameters. Parameter 1 should take in the school Id, the second parameter should take in the number grade. The program will return the name of the school, letter grade, description, and GPA seperated by commas. For example, if an end user enters 1 for school id, and grade number 90, the console application will display WidgetSchool_1,P,Passing,2.0. The GPA columns represents the lowest number possible to achieve the letter grade,description, and GPA. For Example, 93 is the lowest grade possible to get an A, 4.0 or Excellent for School with the id of 1, and the name of WidgetSchool_1.
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,719
    Rep Power
    348
    How are you executing the program? I've never seen <terminated> printed out by the java program.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    i hit the run button. is there anything wrong with the way i'm using the if statements. the original program that was given to me had the following code. i'm using eclipse.

    package main;

    import java.util.Scanner;

    public class Example_02 {

    /**
    * @param args
    * How to run jar files
    * java -cp school.jar main.Example_02
    * CST-3619-HW_02-A
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.print("Enter School Id (1,2,3, and 4): ");
    Scanner scanner = new Scanner(System.in);
    int inputSchoolId = scanner.nextInt();

    scanner = new Scanner(System.in);
    System.out.print("Enter Numeric Grade: ");
    float inputGrade = scanner.nextFloat();

    String schoolName = "";

    if (inputSchoolId == 1){
    schoolName = "WidgetSchool_1";
    }
    if (inputSchoolId == 2){
    schoolName = "WidgetSchool_2";
    }
    if (inputSchoolId == 3){
    schoolName = "WidgetSchool_3";
    }
    if (inputSchoolId == 4){
    schoolName = "WidgetSchool_4";
    }

    String letter = "F", description="Failing";
    if (inputGrade >= 65){
    letter = "P";
    description = "Passing";
    gpa = "";
    }

    System.out.println(schoolName+","+letter+","+description+","+gpa);

    }

    }


    Originally Posted by NormR
    How are you executing the program? I've never seen <terminated> printed out by the java program.
  14. #8
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,719
    Rep Power
    348
    Try opening a command prompt and using the java command to see if you get different results.

    The coding wouldn't give the <terminated> message.


    Please edit your post and wrap your code with
    [code]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    is the code working for you? i also have netbeans so maybe i can try to run it there?

    under markers for eclipse. i get o errors but 3 warning and one of them says this Description Resource Path Location Type
    Resource leak: 'scanner' is never closed Grade.java /02_GradeHW/src/main line 14 Java Problem


    the other is Description Resource Path Location Type
    TODO Auto-generated method stub Grade.java /02_GradeHW/src/main line 11 Java Task


    and Description Resource Path Location Type
    Unknown Unknown Java Exception Breakpoint



    Originally Posted by NormR
    Try opening a command prompt and using the java command to see if you get different results.

    The coding wouldn't give the <terminated> message.


    Please edit your post and wrap your code with
    [code]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
  18. #10
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,719
    Rep Power
    348
    is the code working for you
    I'm waiting for the code to be formatted before I copy it for testing.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    hey bro. i fixed it. it was missing some curly braces that didn't give the program errors but it was reading through the code that i wrote for the if statement. i moved the school id == 1, 2, 3 .

    package main;

    import java.util.Scanner;

    public class Grade {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.print("Enter School Id (1,2,3, and 4): ");
    Scanner scanner = new Scanner(System.in);
    int inputSchoolId = scanner.nextInt();

    scanner = new Scanner(System.in);
    System.out.print("Enter Numeric Grade: ");
    float inputGrade = scanner.nextFloat();


    String schoolName = "";

    if (inputSchoolId == 1)
    {
    schoolName = "WidgetSchool_1";
    }
    if (inputSchoolId == 2)
    {
    schoolName = "WidgetSchool_2";
    }
    if (inputSchoolId == 3)
    {
    schoolName = "WidgetSchool_3";
    }
    if (inputSchoolId == 4)
    {
    schoolName = "WidgetSchool_4";
    }

    String letter = "F", description="Failing", gpa="0.0";

    if (inputGrade >= 93)
    {
    letter = "A";
    description = "Excellent";
    gpa = "4.0";
    }
    else if(inputGrade >=90)
    {
    letter = "A-";
    description = "Great";
    gpa = "3.6";
    }
    else if(inputGrade >=87)
    {
    letter = "B+";
    description = "Very Good";
    gpa = "3.2";
    }
    else if(inputGrade >=84)
    {
    letter = "B";
    description = "Good";
    gpa = "2.8";
    }
    else if(inputGrade >=81)
    {
    letter = "B-";
    description = "Pretty Good";
    gpa = "2.4";
    }
    else if(inputGrade >=78)
    {
    letter = "C+";
    description = "Above Average";
    gpa = "2.0";
    }
    else if(inputGrade >=75)
    {
    letter = "C";
    description = "Average";
    gpa = "1.6";
    }
    else if(inputGrade >=72)
    {
    letter = "C-";
    description = "Below Average";
    gpa = "1.2";
    }
    else if(inputGrade >=69)
    {
    letter = "D";
    description = "Barely Passing";
    gpa = "1.0";
    }

    if (inputGrade >= 90)
    {
    letter = "A";
    description = "Excellent";
    gpa = "4.0";}
    else if(inputGrade >=80)
    {
    letter = "B";
    description = "Great";
    gpa = "3.6";}
    else if(inputGrade >=70)
    {
    letter = "C";
    description = "Very Good";
    gpa = "3.2";
    }
    else if(inputGrade >=60){
    letter = "D";
    description = "Good";
    gpa = "2.8";
    }
    else
    {
    letter = "F";
    description = "Pretty Good";
    gpa = "2.4";
    }

    System.out.println(schoolName+","+letter+","+description+","+gpa);

    }
    {
    }
    }


    Originally Posted by FYou
    is the code working for you? i also have netbeans so maybe i can try to run it there?

    under markers for eclipse. i get o errors but 3 warning and one of them says this Description Resource Path Location Type
    Resource leak: 'scanner' is never closed Grade.java /02_GradeHW/src/main line 14 Java Problem


    the other is Description Resource Path Location Type
    TODO Auto-generated method stub Grade.java /02_GradeHW/src/main line 11 Java Task


    and Description Resource Path Location Type
    Unknown Unknown Java Exception Breakpoint
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    the line where you see

    String letter = "F", description="Failing", gpa="0.0";

    is it necessary to fill in the letter, description, and gpa? i was thinking about leaving it " ";

    actually now i found out it is working but when i enter the number grade the result i get is not correct. its not getting it from the correct if else statement i wrote as you can see i wrote two.

    sorry i'm new taking a 101 java class.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    okay. here's the formatted code.

    package main;

    import java.util.Scanner;

    public class Grade {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.print("Enter School Id (1,2,3, and 4): ");
    Scanner scanner = new Scanner(System.in);
    int inputSchoolId = scanner.nextInt();

    scanner = new Scanner(System.in);
    System.out.print("Enter Numeric Grade: ");
    float inputGrade = scanner.nextFloat();


    String schoolName = "";
    String letter = "F", description="Failing", gpa="0.0";

    if (inputSchoolId == 1)
    {
    schoolName = "WidgetSchool_1";
    }
    if (inputGrade >= 93)
    {
    letter = "A";
    description = "Excellent";
    gpa = "4.0";
    }
    else if(inputGrade >=90)
    {
    letter = "A-";
    description = "Great";
    gpa = "3.6";
    }
    else if(inputGrade >=87)
    {
    letter = "B+";
    description = "Very Good";
    gpa = "3.2";
    }
    else if(inputGrade >=84)
    {
    letter = "B";
    description = "Good";
    gpa = "2.8";
    }
    else if(inputGrade >=81)
    {
    letter = "B-";
    description = "Pretty Good";
    gpa = "2.4";
    }
    else if(inputGrade >=78)
    {
    letter = "C+";
    description = "Above Average";
    gpa = "2.0";
    }
    else if(inputGrade >=75)
    {
    letter = "C";
    description = "Average";
    gpa = "1.6";
    }
    else if(inputGrade >=72)
    {
    letter = "C-";
    description = "Below Average";
    gpa = "1.2";
    }
    else if(inputGrade >=69)
    {
    letter = "D";
    description = "Barely Passing";
    gpa = "1.0";
    }
    if (inputSchoolId == 2)
    {
    schoolName = "WidgetSchool_2";
    }
    if (inputGrade >= 90)
    {
    letter = "A";
    description = "Excellent";
    gpa = "4.0";}
    else if(inputGrade >=80)
    {
    letter = "B";
    description = "Great";
    gpa = "3.6";}
    else if(inputGrade >=70)
    {
    letter = "C";
    description = "Very Good";
    gpa = "3.2";
    }
    else if(inputGrade >=60){
    letter = "D";
    description = "Good";
    gpa = "2.8";
    }
    else
    {
    letter = "F";
    description = "Pretty Good";
    gpa = "2.4";
    }

    if (inputSchoolId == 3)
    {
    schoolName = "WidgetSchool_3";
    }
    if (inputGrade >= 93)
    {
    letter = "A";
    description = "Excellent";
    gpa = "4.0";
    }
    else if(inputGrade >=90)
    {
    letter = "A-";
    description = "Great";
    gpa = "3.6";
    }
    else if(inputGrade >=87)
    {
    letter = "B+";
    description = "Very Good";
    gpa = "3.2";
    }
    else if(inputGrade >=84)
    {
    letter = "B";
    description = "Good";
    gpa = "2.8";
    }
    else if(inputGrade >=81)
    {
    letter = "B-";
    description = "Pretty Good";
    gpa = "2.4";
    }
    else if(inputGrade >=78)
    {
    letter = "C+";
    description = "Above Average";
    gpa = "2.0";
    }
    else if(inputGrade >=72)
    {
    letter = "C";
    description = "Average";
    gpa = "1.6";
    }
    else if(inputGrade >=65)
    {
    letter = "D";
    description = "Barely Passing";
    gpa = "1.0";
    }
    else
    {
    letter = "F";
    description = "Failing";
    gpa = "0.0";
    }

    if (inputSchoolId == 4)
    {
    schoolName = "WidgetSchool_4";
    }

    if (inputGrade >= 95)
    {
    letter = "A";
    description = "Excellent";
    gpa = "4.0";}
    else if(inputGrade >=90)
    {
    letter = "B";
    description = "Good";
    gpa = "3.0";}
    else if(inputGrade >=85)
    {
    letter = "S";
    description = "Satisfactory";
    gpa = "2.0";
    }
    else if(inputGrade >=75){
    letter = "NI";
    description = "Needs Improvement";
    gpa = "1.0";
    }
    else
    {
    letter = "U";
    description = "Unsatisfactory";
    gpa = "0.0";
    }

    System.out.println(schoolName+","+letter+","+description+","+gpa);

    }
    {
    }
    }
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    i get the right output for widget school 4 by entering any numeric grade but for widget 1, 2 and 3 school it's not displaying the right output for the letter grade, description and gpa.
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0
    help someone or anyone?? now my program prints 4 lines.

    Code:
    package main;
    
    import java.util.Scanner;
    
    public class Grade {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		// TODO Auto-generated method stub
    		
    		 System.out.print("Enter School Id (1,2,3, and 4): ");
    		 Scanner scanner = new Scanner(System.in);
    		 int inputSchoolId = scanner.nextInt(); 
    		 
    		 scanner = new Scanner(System.in);
    		 System.out.print("Enter Numeric Grade: ");
    		 float inputGrade = scanner.nextFloat();
    
    		 
    		 String schoolName = "";
    		 String letter = "", description="", gpa="";
    		 
    		 if (inputSchoolId == 1)
    		 {
    			schoolName = "WidgetSchool_1";
    		 }
    		 if (inputGrade >= 93 )
    		 { 
    			letter = "A";
    			description = "Excellent";
    			gpa = "4.0";
    		 }
    		 else if (inputGrade >=90)
    		 {
    			letter = "A-";
    		 	description = "Great";
    		 	gpa = "3.6";
    		 }
    		 else if (inputGrade >=87)
    		 {
    			letter = "B+";
    			description = "Very Good";
    			gpa = "3.2";
    		 }
    	     else if (inputGrade >=84)
    	     {
    		    letter = "B";
    			description = "Good";
    			gpa = "2.8";
    		 }
    		 else if (inputGrade >=81)
    		 {
    			letter = "B-";
    			description = "Pretty Good";
    		    gpa = "2.4";
    		 }
    		 else if (inputGrade >=78)
    		 {
    			letter = "C+";
    			description = "Above Average";
    			gpa = "2.0";
    		 }
    		 else if (inputGrade >=75)
    		 {
    			letter = "C";
    			description = "Average";
    		    gpa = "1.6";
    		 }
    		 else if (inputGrade >=72)
    		 {
    			letter = "C-";
    			description = "Below Average";
    			gpa = "1.2";
    		 }
    		 else if (inputGrade >=69)
    		 {
    			 letter = "D";
    			 description = "Barely Passing";
    			 gpa = "1.0";
    		 }
    		 else 
    		 {
    			 letter = "F";
    			 description = "Failing";
    			 gpa = "0.0"; 
    		 }
    		 
    		 System.out.println(schoolName+", "+ letter +", "+ description +", "+ gpa);
    		 
    		 if (inputSchoolId == 2)
    		 {
    			schoolName = "WidgetSchool_2";
    		 }
    		 if (inputGrade >= 90)
    		 {
    			letter = "A";
    			description = "Excellent";
    			gpa = "4.0";
    		 }
    		 else if (inputGrade >=80)
    		 {
    			letter = "B";
    			description = "Great";
    			gpa = "3.6";
    		 }
    		 else if (inputGrade >=70)
    		 {
    			letter = "C";
    			description = "Very Good";					
    			gpa = "3.2";
    		 }
    		 else if (inputGrade >=60)
    		 {
    			letter = "D";
    			description = "Good";
    			gpa = "2.8";
    		 }
    		 else 
    		 {
    			letter = "F";
    			description = "Pretty Good";
    		    gpa = "2.4";
    		 }
    		 
    		 System.out.println(schoolName+", "+ letter +", "+ description +", "+ gpa);
    		 
    		 if (inputSchoolId == 3)
    		 {
    			schoolName = "WidgetSchool_3";
    		 }
    		 if (inputGrade >= 93)
    		 {
    			letter = "A";
    			description = "Excellent";
    			gpa = "4.0";
    		 }
    		 else if (inputGrade >=90)
    		 {
    			letter = "A-";
    		 	description = "Great";
    		 	gpa = "3.6";
    		 }
    		 else if (inputGrade >=87)
    		 {
    			letter = "B+";
    			description = "Very Good";
    			gpa = "3.2";
    		 }
    	     else if (inputGrade >=84)
    	     {
    		    letter = "B";
    			description = "Good";
    			gpa = "2.8";
    		 }
    		 else if (inputGrade >=81)
    		 {
    			letter = "B-";
    			description = "Pretty Good";
    		    gpa = "2.4";
    		 }
    		 else if (inputGrade >=78)
    		 {
    			letter = "C+";
    			description = "Above Average";
    			gpa = "2.0";
    		 }
    		 else if (inputGrade >=72)
    		 {
    			letter = "C";
    			description = "Average";
    		    gpa = "1.6";
    		 }
    		 else if (inputGrade >=65)
    		 {
    			letter = "D";
    			description = "Barely Passing";
    			gpa = "1.0";
    		 }
    		 else 
    		 {
    			letter = "F";
    			description = "Failing";
    			gpa = "0.0";
    		 }
    		 
    		 System.out.println(schoolName+", "+ letter +", "+ description +", "+ gpa);
    		 
    		 if (inputSchoolId == 4)
    		 {
    			schoolName = "WidgetSchool_4";
    		 }
    		 if (inputGrade >= 95)
    		 {
    			letter = "A";
    			description = "Excellent";
    			gpa = "4.0";
    		 }
    		 else if (inputGrade >=90)
    		 {
    			letter = "B";
    			description = "Good";
    			gpa = "3.0";
    		 }
    		 else if (inputGrade >=85)
    		 {
    			letter = "S";
    			description = "Satisfactory";					
    			gpa = "2.0";
    		 }
    		 else if (inputGrade >=75)
    		 {
    			letter = "NI";
    			description = "Needs Improvement";
    			gpa = "1.0";
    		 }
    		 else 
    		 {
    			letter = "U";
    			description = "Unsatisfactory";
    		    gpa = "0.0";		    
    		 }
    		 
    		 System.out.println(schoolName+", "+ letter +", "+ description +", "+ gpa);
    	}
    }
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo