Results 1 to 5 of 5
- 04-11-2012, 04:20 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
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"); } }
- 04-11-2012, 04:41 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Creating an amount of variables based on user input
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.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.
- 04-11-2012, 05:06 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
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?
- 04-11-2012, 07:16 AM #4
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-11-2012, 08:23 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Creating an amount of variables based on user input
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
-
Creating 2D array from all user input
By peek_a_boo in forum New To JavaReplies: 1Last Post: 12-08-2011, 08:16 PM -
Creating a number of objects based on user input.
By Kevinius in forum New To JavaReplies: 21Last Post: 04-03-2011, 08:53 AM -
Making a loop and creating variables based off of user input
By seanfmglobal in forum New To JavaReplies: 2Last Post: 01-13-2011, 05:43 AM -
Creating a Table with user input
By JonniBravo in forum EclipseReplies: 1Last Post: 09-08-2010, 12:50 PM -
Creating a dialog to input user/password
By prfalco in forum New To JavaReplies: 4Last Post: 02-18-2008, 07:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks