How can I change this code so that the user inputs the values Grammar, Spelling,
ID: 3587195 • Letter: H
Question
How can I change this code so that the user inputs the values Grammar, Spelling, Correct Length, and content himself? Also, can someone add something that asks the user if he/she wants to exit? Thanks.
/*
*
* Test program
* */
//GradeTester.java
public class GradeTester {
public static void main(String[] args) {
//Create an instance of Eassy
Eassy compitition=new Eassy();
compitition.setGrammar(30);
compitition.setSpelling(20);;
compitition.setCorrectLength(20);
compitition.setContent(30);
//Create an instance of GradedActivity
GradedActivity ga=new GradedActivity();
ga.setScore(compitition.getTotalScore());
System.out.println("Points ");
//print points
System.out.println(compitition);
System.out.println("Total Score :");
//print total score
System.out.println(compitition.getTotalScore());
System.out.println("Grade letter : ");
//print grade
System.out.println(ga.getGrade());
}
}
Explanation / Answer
Note : As u asked, I just provided the code to get the input from the user and also I provided the code for how to run the block of repeatedly until the user enters 'n' or 'N'.
If u need anythingmore regading this just give me a comment Thank you..
______________________
GradeTester.java
import java.util.Scanner;
public class GradeTester {
public static void main(String[] args) {
// Declaring variables
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
int grammer, spelling, correctlen, content;
// Create an instance of Eassy
Eassy compitition = new Eassy();
while (true) {
System.out.print("Enter Points for Grammer :");
grammer = sc.nextInt();
System.out.print("Enter Points for Spelling :");
spelling = sc.nextInt();
System.out.print("Enter Points for Correct Length :");
correctlen = sc.nextInt();
System.out.print("Enter Points for Content :");
correctlen = sc.nextInt();
compitition.setGrammar(grammer);
compitition.setSpelling(spelling);
compitition.setCorrectLength(correctlen);
compitition.setContent(content);
// Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print("Do you want to continue(Y/N) ::");
char ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y')
continue;
else {
System.out.println(":: Program Exit ::");
break;
apackage org.students;
import java.util.Scanner;
public class GradeTester {
public static void main(String[] args) {
// Declaring variables
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
int grammer, spelling, correctlen, content;
// Create an instance of Eassy
Eassy compitition = new Eassy();
while (true) {
System.out.print("Enter Points for Grammer :");
grammer = sc.nextInt();
System.out.print("Enter Points for Spelling :");
spelling = sc.nextInt();
System.out.print("Enter Points for Correct Length :");
correctlen = sc.nextInt();
System.out.print("Enter Points for Content :");
correctlen = sc.nextInt();
compitition.setGrammar(grammer);
compitition.setSpelling(spelling);
compitition.setCorrectLength(correctlen);
compitition.setContent(content);
// Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print("Do you want to continue(Y/N) ::");
char ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y')
continue;
else {
System.out.println(":: Program Exit ::");
break;
}
}
// Create an instance of GradedActivity
GradedActivity ga = new GradedActivity();
ga.setScore(compitition.getTotalScore());
System.out.println("Points ");
// print points
System.out.println(compitition);
System.out.println("Total Score :");
// print total score
System.out.println(compitition.getTotalScore());
System.out.println("Grade letter : ");
// print grade
System.out.println(ga.getGrade());
}
}
}
}
// Create an instance of GradedActivity
GradedActivity ga = new GradedActivity();
ga.setScore(compitition.getTotalScore());
System.out.println("Points ");
// print points
System.out.println(compitition);
System.out.println("Total Score :");
// print total score
System.out.println(compitition.getTotalScore());
System.out.println("Grade letter : ");
// print grade
System.out.println(ga.getGrade());
}
}
___________________Thank YOu
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.