Thread: Java Homework(Grade system)

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21
  1. #11  
    Super Donator

    Benji's Avatar
    Join Date
    Feb 2010
    Age
    29
    Posts
    1,525
    Thanks given
    920
    Thanks received
    503
    Rep Power
    570
    I actually did the average part for you since I was bored:

    Code:
    import java.util.Scanner;
    
    
    public class Main {
    
    	public double total = 0, count = 0;
    	public double calculateAverage() {
    		double result = total / count;
    		return result;
    	}
    	public static void main(String[] args) {
    		boolean shouldContinue = false;
    		int mark = 0;
    		Scanner scanner = new Scanner(System.in);
    		do {
    			System.out.printIn("Enter your points:");
    			try {
    				mark = scanner.nextInt();
    				if(mark >= 90) {
    					System.out.println("You got an A!");
    					System.out.println("Would you like to continue? (yes/no) ");
    					total = total + mark;
    					count++;
    				} else {
    					System.out.println("You got less than an A.");
    					System.out.println("Would you like to continue? (yes/no) ");
    				}
    					
    			} catch(NumberFormatException e) {
    				System.out.printIn("Wrong Format");
    			}
    			
    			scanner.nextLine();
    			if(scanner.nextLine().contains("yes")) {
    				shouldContinue = true;
    			} else if(scanner.nextLine().contains("no")) {
    				shouldContinue = false;
    				System.out.printIn("Your grade average is: " + calculateAverage());
    			} else {
    				shouldContinue = false;
    			}
    			
    
    		} while(shouldContinue);
    		System.out.println("Your first mark is: "+mark);
    	}
    	
    		
    }

    To do this part
    The first grade is: A with points 90
    The second grade is: A with points 100
    You have to use arrays, which should be easier

    allScores = new int[i];

    allScores[x] = y;

    and so on, just calculate the average using the array values in the end.

    Reply With Quote  
     

  2. Thankful user:


  3. #12  
    Registered Member .oX,'s Avatar
    Join Date
    Jun 2010
    Posts
    162
    Thanks given
    7
    Thanks received
    8
    Rep Power
    2
    Quote Originally Posted by Benjii View Post
    I actually did the average part for you since I was bored:

    Code:
    import java.util.Scanner;
    
    
    public class Main {
    
    	public double total = 0, count = 0;
    	public double calculateAverage() {
    		double result = total / count;
    		return result;
    	}
    	public static void main(String[] args) {
    		boolean shouldContinue = false;
    		int mark = 0;
    		Scanner scanner = new Scanner(System.in);
    		do {
    			System.out.printIn("Enter your points:");
    			try {
    				mark = scanner.nextInt();
    				if(mark >= 90) {
    					System.out.println("You got an A!");
    					System.out.println("Would you like to continue? (yes/no) ");
    					total = total + mark;
    					count++;
    				} else {
    					System.out.println("You got less than an A.");
    					System.out.println("Would you like to continue? (yes/no) ");
    				}
    					
    			} catch(NumberFormatException e) {
    				System.out.printIn("Wrong Format");
    			}
    			
    			scanner.nextLine();
    			if(scanner.nextLine().contains("yes")) {
    				shouldContinue = true;
    			} else if(scanner.nextLine().contains("no")) {
    				shouldContinue = false;
    				System.out.printIn("Your grade average is: " + calculateAverage());
    			} else {
    				shouldContinue = false;
    			}
    			
    
    		} while(shouldContinue);
    		System.out.println("Your first mark is: "+mark);
    	}
    	
    		
    }

    To do this part


    You have to use arrays, which should be easier

    allScores = new int[i];

    allScores[x] = y;

    and so on, just calculate the average using the array values in the end.
    not for me but thanks for the script, just one more thing to go!
    thanks + rep++
    ESTONIA< 3
    50 Posts [X]
    100 Posts [X]
    200 Posts [ ]
    500 Posts [ ]
    1000 Posts [ ]
    2000 Posts [ ]
    Reply With Quote  
     

  4. #13  
    Member

    Join Date
    May 2008
    Posts
    1,288
    Thanks given
    50
    Thanks received
    92
    Rep Power
    0
    Just a tip, most teachers expect java homework to be properly commented..

    edit: also you should probably include more grades then just 'A'
    Reply With Quote  
     

  5. #14  
    Registered Member .oX,'s Avatar
    Join Date
    Jun 2010
    Posts
    162
    Thanks given
    7
    Thanks received
    8
    Rep Power
    2
    Quote Originally Posted by Clifton View Post
    Just a tip, most teachers expect java homework to be properly commented..

    edit: also you should probably include more grades then just 'A'
    Yes i know that, thanks for the tip
    ESTONIA< 3
    50 Posts [X]
    100 Posts [X]
    200 Posts [ ]
    500 Posts [ ]
    1000 Posts [ ]
    2000 Posts [ ]
    Reply With Quote  
     

  6. #15  
    Renown Programmer
    veer's Avatar
    Join Date
    Nov 2007
    Posts
    3,746
    Thanks given
    354
    Thanks received
    1,370
    Rep Power
    3032
    waiting for a better solution
    Reply With Quote  
     

  7. #16  
    Registered Member
    Joker's Avatar
    Join Date
    Nov 2009
    Age
    28
    Posts
    1,845
    Thanks given
    378
    Thanks received
    1,206
    Rep Power
    5000
    Code:
    import java.util.Scanner;
    
    public class Main {
    
        public static double total = 0, count = 0, totalAverage;
        public static String totalAverageResult;
    
        public static double calculateAverage() {
            double result = total / count;
            return result;
        }
    
        public static void main(String[] args) {
            boolean shouldContinue = false;
            int mark;
            System.out.println("Enter a grade:");
            Scanner scanner = new Scanner(System.in);
            do {
                mark = scanner.nextInt();
                if(mark >= 90 && mark <= 100) {
                    System.out.println("You got an A.");
                } else if(mark >= 80) {
                    System.out.println("You got a B.");
                } else if(mark >= 70) {
                    System.out.println("You got a C.");
                } else if(mark >= 60) {
                    System.out.println("You got a D.");
                } else {
                    System.out.println("You got an F.");
                }
                System.out.println("Enter more grades? (yes/no):");
                total = total + mark;
                count++;
                scanner.nextLine();
                if(scanner.nextLine().equalsIgnoreCase("yes")) {
                    System.out.println("Enter a grade:");
                    shouldContinue = true;
                } else {
                totalAverage = calculateAverage();
                if(totalAverage >= 90 && totalAverage <= 100) {
                    totalAverageResult = "A";
                } else if(totalAverage >= 80) {
                    totalAverageResult = "B";
                } else if(totalAverage >= 70 ) {
                    totalAverageResult = "C";
                } else if(totalAverage >= 60) {
                    totalAverageResult = "D";
                } else {
                    totalAverageResult = "F";
                }
                    System.out.println("Your average grade is: " + calculateAverage() + ", which is a " + totalAverageResult + ".");
                    shouldContinue = false;
                }
            } while(shouldContinue);
        }
    
    }
    Not the cleanest code, but it does the job, supports all letter grades, and even tells you the letter grade of the averaged total.

    Precompiled: UppIT - Free File hosting - Grade.rar

    Reply With Quote  
     

  8. #17  
    Renown Programmer
    veer's Avatar
    Join Date
    Nov 2007
    Posts
    3,746
    Thanks given
    354
    Thanks received
    1,370
    Rep Power
    3032
    what if suddenly he wanted to add the support of more specific grades, such as A+, or C-?
    Reply With Quote  
     

  9. #18  
    Registered Member
    Joker's Avatar
    Join Date
    Nov 2009
    Age
    28
    Posts
    1,845
    Thanks given
    378
    Thanks received
    1,206
    Rep Power
    5000
    Code:
    import java.util.Scanner;
    
    public class Main {
    
        public static double total = 0, count = 0, totalAverage;
        public static String totalAverageResult;
    
        public static double calculateAverage() {
            double result = total / count;
            return result;
        }
    
        public static void main(String[] args) {
            boolean shouldContinue = false;
            int mark;
            System.out.println("Enter a grade:");
            Scanner scanner = new Scanner(System.in);
            do {
                mark = scanner.nextInt();
                if(mark > 95 && mark <= 100) {
                    System.out.println("You got an A+.");
                } else if(mark == 95) {
                    System.out.println("You got an A.");
                } else if(mark >= 90 && mark < 95) {
                    System.out.println("You got an A-.");
                } else if(mark > 85 && mark < 90) {
                    System.out.println("You got a B+.");
                } else if(mark == 85) {
                    System.out.println("You got a B.");
                } else if(mark >= 80 && mark < 85) {
                    System.out.println("You got a B-.");
                } else if(mark > 75 && mark < 80) {
                    System.out.println("You got a C+.");
                } else if(mark == 75) {
                    System.out.println("You got a C.");
                } else if(mark >= 70 && mark < 75) {
                    System.out.println("You got a C-.");
                } else if(mark > 65 && mark < 70) {
                    System.out.println("You got a D+.");
                } else if(mark == 65) {
                    System.out.println("You got a D.");
                } else if(mark >= 60 && mark < 65) {
                    System.out.println("You got a D-.");
                } else {
                    System.out.println("You got an F.");
                }
                System.out.println("Enter more grades? (yes/no):");
                total = total + mark;
                count++;
                scanner.nextLine();
                if(scanner.nextLine().equalsIgnoreCase("yes")) {
                    System.out.println("Enter a grade:");
                    shouldContinue = true;
                } else {
                totalAverage = calculateAverage();
                if(totalAverage > 95 && totalAverage < 100) {
                    totalAverageResult = "A+";
                } else if(totalAverage == 95) {
                    totalAverageResult = "A";
                } else if(totalAverage >= 90 && totalAverage < 95) {
                    totalAverageResult = "A-";
                } else if(totalAverage > 85 && totalAverage < 90) {
                    totalAverageResult = "B+";
                } else if(totalAverage == 85) {
                    totalAverageResult = "B";
                } else if(totalAverage >= 80 && totalAverage < 85) {
                    totalAverageResult = "B-";
                } else if(totalAverage > 75 && totalAverage < 80) {
                    totalAverageResult = "C+";
                } else if(totalAverage == 75) {
                    totalAverageResult = "C";
                } else if(totalAverage >= 70 && totalAverage < 75) {
                    totalAverageResult = "C-";
                } else if(totalAverage > 65 && totalAverage < 70) {
                    totalAverageResult = "D+";
                } else if(totalAverage == 65) {
                    totalAverageResult = "D";
                } else if(totalAverage >= 60 && totalAverage < 65) {
                    totalAverageResult = "D-";
                } else {
                    totalAverageResult = "F";
                }
                    System.out.println("Your average grade is: " + calculateAverage() + ", which is a " + totalAverageResult + ".");
                    shouldContinue = false;
                }
            } while(shouldContinue);
        }
    
    }
    Added more specific grading, such as A+ or C-, does this for the final average too.

    Precompiled: UppIT - Free File hosting - Grade.rar

    Reply With Quote  
     

  10. #19  
    Registered Member snwspeckle's Avatar
    Join Date
    Jul 2010
    Posts
    428
    Thanks given
    22
    Thanks received
    25
    Rep Power
    12
    Use arrays, then learn through various JAVA tutorials.
    Reply With Quote  
     

  11. #20  
    Super Donator

    Benji's Avatar
    Join Date
    Feb 2010
    Age
    29
    Posts
    1,525
    Thanks given
    920
    Thanks received
    503
    Rep Power
    570
    Quote Originally Posted by snwspeckle View Post
    Use arrays, then learn through various JAVA tutorials.
    Stop trying to sound smart, it's failing

    Added more specific grading, such as A+ or C-, does this for the final average too.
    cool

    Reply With Quote  
     

Page 2 of 3 FirstFirst 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Lottery Ticket/Gambler System/Java
    By Rainex in forum Snippets
    Replies: 21
    Last Post: 09-26-2010, 08:36 PM
  2. Replies: 10
    Last Post: 07-10-2010, 04:17 PM
  3. 5TH Grade homework
    By nubcoder in forum Homework
    Replies: 9
    Last Post: 05-23-2010, 06:05 AM
  4. Java display System Info?
    By Alex in forum Application Development
    Replies: 1
    Last Post: 04-09-2010, 01:58 AM
  5. Show Users System Specs - Java MODS
    By Java Maniac in forum Application Development
    Replies: 0
    Last Post: 10-14-2009, 04:43 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •