Results 1 to 5 of 5
  1. #1
    HDInfinity is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Creating an amount of variables based on user input

    I am fairly new to java so for my first program I though I would create a grading system based on Homework,Quizzes and Tests. The user selects what percentage of each is over the total grade. Then asks you how many of each you are grading. Using that info it will determine how much each individual Homework, Quiz, and Test is worth if they were given 100%. I am trying to allow the person to individually grade each homework/quiz/test so that the total grade will be completley accurate.

    So overall what I need to do is when a person for example inputs that they are grading 5 homeworks, 2 quizzes, and 1 test. Java will create 5 variables for Homework, 2 for quizzes, and 1 new test variable. Each allowing the user to input what the value for each variable is. How do I go about doing this?

    Here is the code:

    Java Code:
    package test;
    
    import java.util.Scanner;
    
    public class TGrade {
    
    	
    	static Scanner scanner = new Scanner(System.in);
    	
    	public static void main(String[] args) {
    		
    		System.out.println("Welcome to Mario's Grader!");
    		
    		System.out.println("What % is Homework");
    		int hwp = scanner.nextInt();
    		// hwp = Homework / Total
    		
    		
    		System.out.println("How many Homework's are you grading?");
    		int hwa = scanner.nextInt();
    		// hwa = Amount of Homeworks Being Graded
    		
    		int hwe = hwp / hwa;
    		// hwe = How much each Homework is worth
    		
    		System.out.println("What % are Quizzes");
    		int qp = scanner.nextInt();
    		// qp = Quiz / Total
    		
    		System.out.println("How many Quizzes are you grading?");
    		int qa = scanner.nextInt();
    		// qa = Amount of Quizzes being graded
    		
    		int qe = qp / qa;
    		
    		int tp = 100 - hwp - qp;
    		// tp = Percentage for Test/Total
    		
    		System.out.println("How many Tests are you grading?");
    		int ta = scanner.nextInt();
    		// ta = Amount of Tests being graded
    		
    		int te = tp / ta;
    		
    		System.out.println("The percentage for Quiz/Total is =" + qp);
    		System.out.println("The percentage for Homwork/Total is=" + hwp);
    		System.out.println("The perecentage for Test/Total is=" + tp);
    		
    		System.out.println("You are grading " + qa + " Quizzes");
    		System.out.println("You are grading " + hwa + " Homeworks");
    		System.out.println("You are grading " + ta + " Tests");
    		
    		System.out.println("Each quiz is worth " + qe + " points");
    		System.out.println("Each homework is worth " + hwe + " points");
    		System.out.println("Each test is worth " + te + " points");
    
    
    		
    		
    		
    	}
    	
    	
    
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Creating an amount of variables based on user input

    So overall what I need to do is when a person for example inputs that they are grading 5 homeworks, 2 quizzes, and 1 test. Java will create 5 variables for Homework, 2 for quizzes, and 1 new test variable.
    Separate variables are not needed. (And there is no way in Java of declaring some number of variables decided on at runtime.). Consider using arrays: for example the homework marks could be put into an int array which you declare to have size hwa.

  3. #3
    HDInfinity is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: Creating an amount of variables based on user input

    Can I make it so for every Int created by the array the user can provide input for each one?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Creating an amount of variables based on user input

    HDInfinity, please don't remove the content of your posts. This time round, I've deleted the thread in which you replaced the content with the single word "Resolved." Next time something like that happens, please leave the question and share the solution. That's what a forum is all about.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Creating an amount of variables based on user input

    Quote Originally Posted by HDInfinity View Post
    Can I make it so for every Int created by the array the user can provide input for each one?
    The array provides access to each of its element: you can assign values to each element, and read what they are. So, yes, you can use input from the user to give the array elements values.

    See Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. Creating 2D array from all user input
    By peek_a_boo in forum New To Java
    Replies: 1
    Last Post: 12-08-2011, 08:16 PM
  2. Creating a number of objects based on user input.
    By Kevinius in forum New To Java
    Replies: 21
    Last Post: 04-03-2011, 08:53 AM
  3. Replies: 2
    Last Post: 01-13-2011, 05:43 AM
  4. Creating a Table with user input
    By JonniBravo in forum Eclipse
    Replies: 1
    Last Post: 09-08-2010, 12:50 PM
  5. Creating a dialog to input user/password
    By prfalco in forum New To Java
    Replies: 4
    Last Post: 02-18-2008, 07:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •