Switch Statement That Decides What Range To Print Based On Letter Grade Input
Nov 1, 2014
Alright so I wrote a switch statement that decides what range to print based on the letter grade input.
import java.util.Scanner;
public class SwitchPractice
{
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
[code]...
It works fine, but once it the user enters a letter grade and then displays the value, it does not prompt the user for another letter grade so that it can perform the output again. Also if I wanted to display an error message to the user if they enter an invalid letter grade how would I do that. I tried using a while loop and if statement in the switch statement but that didn't work.
View Replies
ADVERTISEMENT
Nov 10, 2014
//Use a Switch statement to determine outcomes for letter grades
switch (Letter)
{
case 'A': outFile.println("
Good Work! You have met the pre-req for CIS 220.");
break;
case 'B': outFile.println("
[Code] ....
is not printing the information on the next line in my output file.
View Replies
View Related
Nov 23, 2014
I had to make a program that allowed the user to enter the number of students and the students names and grades and then print out the name with the grade in descending order. right now I only have it where it prints the names out in descending order. how do I get it the print out with the grade?
Here is my code
import java.util.*;
public class Grades {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int numofstudents = input.nextInt();
[Code] .....
View Replies
View Related
Apr 14, 2014
The purpose of this project is to determine the letter grade of students. The program needs to accept two command line arguments:
The first being the name of a disk file that contains the names of students, and their test scores, separated by commas followed by one or more spaces. Each line in the file will contain scores for one student.
The second argument is the name of an output disk file. The program is supposed to create a new output disk file using that name.
The number of students in the input file is unknown during compile time. The name of input and output files could be anything and only known during run time. Additionally, the average scores, along with the minimum and maximum scores for each test are to be displayed in the console.
Calculation: Final Score = quiz1 * .10 + quiz2 * .10 + quiz3 * .10 + quiz4 * .10 + midi * .20 + midii * .15 + final * .25
Final Score >= 90% then letter grade is A, 80%-89% B, 70%-79% C, 60-69% D, <= 59% F
input_data.txt:
firstName lastName, 100, 90, 80, 100, 89, 99, 88
firstName lastName, 90, 90, 100, 100, 99, 100, 95
firstName lastName, 100, 90, 100, 70, 78, 78, 80
firstName lastName, 80, 90, 90, 100, 89, 99, 85
etc.
output_data.txt
firstName lastName: B
firstName lastName: A
firstName lastName: F
firstName lastName: B
firstName lastName: C
averages (to appear in console)
Q1 Q2 Q3 Q4 MidI MidII Final
Average: 82.25 80.38 82.85 83.88 81.38 84.13 78.63
Minimum: 60 54 38 62 62 60 50
Maximum: 100 90 100 100 99 100 95
Press ENTER to continue...
Here's what I have so far :
import static java.lang.System.out;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
public class LetterGrader {
[Code] .....
View Replies
View Related
Sep 14, 2014
I am trying to create a program that allows me to enter 5 students numeric grade (0-100) to a letter grade (A, B, C, D, F) and I CANNOT use an array. When I try to run my program it says main class not found, and when I change the it from a string to a void in the main method it does not work.
Java Code:
import java.util.Scanner;
public class Week3ControlStatements2
{
public static String main(String[] args){
int numberGrade = 0;
int quotient = numberGrade / 10;
int remainder = numberGrade % 10;
[Code] ....
View Replies
View Related
Nov 1, 2014
I have been working on this letter to numeric grade convertor and my return function is not returning anything. Here is my code:
import java.util.Scanner;
public class GradeTest
{
private double numericValue = 0;
private static String grade = "";
public static void main(String[] args)
[code]....
View Replies
View Related
Oct 8, 2014
Write a program that translates a number between 0 and 4 into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B. Break ties in favor of the better grade; for example 2.85 should be a B. Use a class Grade with a method getNumericGrade. why when I type .3 it tells me "Exception in thread "main" java.util.InputMismatchException" Or if there is an easier way to do this.
import java.util.Scanner;
public class Grades {
public static void main(String [] args) {
System.out.println("Enter a number between 0 and 4");
Scanner input = new Scanner(System.in);
[code]....
View Replies
View Related
Oct 9, 2014
How do i check INT range for switch case: ?
int grade = 68;
switch (grade) {
case 100:
System. out.println( "You got an A. Great job!" );
break;
case 80:
System. out.println( "You got a B. Good work!");
break;
[code]....
View Replies
View Related
Jun 19, 2014
So from what iv learnt in Java and programming in general is that using a case statement is far more efficient that using multiple IF statements. I have an multiple IF statements contained within a method of my program, and would like to instead use a case statement.
public String checkPasswordStrength(String passw) {
int strengthCount=0;
String strengthWord = "";
String[] partialRegexChecks = { ".*[a-z]+.*", // lower
".*[A-Z]+.*", // upper
".*[d]+.*", // digits
".*[@#$%!]+.*" // symbols
[code].....
View Replies
View Related
Apr 15, 2014
Example : I have code and name but my code must start with the first letter of the inputed name if the 2 input is match it will be inserted into database
code = "A"001
name ="Angela"
= success this will inserted into database
else
code ="B"002
name="Angela"
=failed this will not inserted into database
else
code="A"003
name="Andy"
=success still accepts the input cause they have diff code number
What I am thinking on this was compare the code the name? if == it will be inserted but how do i get the 1st letter of the input name?
View Replies
View Related
Nov 18, 2014
So I want to make a simple Java that ask the user to pick a powers and it has two options.If the user picks magic then execute the first if statement then ask the user again which type of magic the user wants.I can't make it work it keeps printing the else statement. Why is that?
import java.util.Scanner;
public class Variable {
static Scanner zcan = new Scanner(System.in);
public static void main(String[] args)
[code]....
View Replies
View Related
Feb 13, 2014
Write a program that asks the user for the low and high integer in a range of integers. The program then asks the user for integers to be added up. The program computes two sums:
The sum of integers that are in the range (inclusive) and the sum of integers that are outside of the range. The user signals the end of input with a 0.
In-range Adder
Low end of range:
20
High end of range:
50
Enter data:
21
Enter data:
60
Enter data:
49
Enter data:
30
Enter data:
91
Enter data:
0
Sum of in range values: 100
Sum of out of range values: 151
Here is my code:
import java.util.Scanner;
class addRange
{
public static void main ( String[] args )
{
Scanner scan = new Scanner( System.in );
System.out.println("The In-Range integer is; ");
int inR = scan.nextInt();
[Code] ....
I'm getting an error on the line with the first else if saying nextNum might not have been initialized. but it's initialized on the line directly above that....
View Replies
View Related
Jul 28, 2014
For example:
if(JTextField = 15-30){
do this
}
I know it's simple but i have no clue how it's done....
View Replies
View Related
Apr 14, 2014
I have a Set S=[1,2,3,4,5,10,12]
Now I want to convert this Set into a Range Statement which is of Form as follows...
Desired Range Statement Form is = 1..5/10/12.
Since 1 to 5 are contigious in my Set, they are represented as 1..5 and 10 and 12 are single non contigious elements they are given a single element with a union (/) Symbol.
Similarly, I want to convert the RangeStatement 1..5/10/12 to Set S=[1,2,3,4,5,10,12].
DO we have any efficient method to o this in Java? if I need to write my own method or is there any inbuilt method to do this.
View Replies
View Related
Apr 10, 2015
this is what code i have so far i want to try and get the computer to output a String type result rather than a number and i wonder if there is a way to output the score after the user is done with the game. I couldn't really see if there was a way to incorporate a switch statement.
import java.util.Scanner;
import java.util.Random;
public class RPSLS {
public static void main(String[] args) {
[code]...
View Replies
View Related
Sep 23, 2014
I am having a problem with looping a while loop that contains a switch statement. Here is my code:
package hw4jenningsd;
import javax.swing.*;
public class HW4JenningsD {
[Code].....
View Replies
View Related
Dec 8, 2014
I am trying to add a while loop into my switch statement. If you run the program, it will ask to enter the class grade (9,10,11, or 12). If you insert 5, it will say to try again. But, if you enter a wrong number twice, it will continue on to the next part of the program, which is asking how many students are in the class. Therefore, I believe a while loop would work, but it is not working at all. The program still runs, just doesn't fix the error. The program is below:
import java.util.Scanner;
public class stephProject {
public static void main(String[] args) {
//call method
welcomeMessage(); //method 1 of 3
[Code] ....
View Replies
View Related
Oct 4, 2014
Write a program to calculate sales and visually display. An online Cowboy retailer sells five products whose retail prices are as follows:
Product 1: Cowboy Boots, $74.99
Product 2: Wranglers, $25.99
Product 3: Cowboy Hats, $24.95
Product 4: Chaps, $ 34.89
Product 5: Spurs, $12.50
Write an application that reads the quantity for each product until user has completed their order. Your program should use switch, if, for, while and do while statements to read, calculate and display the total retail value of all pro ducts sold for each user transaction. The user should be able to start a new transaction after the first transaction is completed. The user can make no more than 3 total orders
public class Merchandise {
private int bootsQTY;
private int wranglersQTY;
private int hatsQTY;
private int chapsQTY;
[Code] ....
When I run my program all of my quantities and the total are 0, I have been stuck for a while trying to figure out how to get values assigned to them...
View Replies
View Related
May 5, 2015
cannot break from while loop. Whenever I am trying to exit from startCustomerManagement-> backEnd() -> mainScreen()..It gets stuck between mainScreen and backEnd screen. However I can exit from backEnd()->startCustomerManagement() screen
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication19;
import java.io.BufferedReader;
[code]...
View Replies
View Related
Sep 6, 2014
What I want to happen is to add 2+ contacts by entering "a" from the menu. Then I want to enter "c" and have it display those contacts. But it doesn't seem to remember that I changed the arrayList masterList.
Java Code:
public class ContactListApp2 {
public static void main(String[] args) {
boolean quit = false;
while (quit == false) {
System.out.println("Main Menu:");
[Code] ....
View Replies
View Related
Jun 22, 2014
Why isn't heig ever equal to heightShipArray[count] no matter what letter I type in
String[] heightShipArray = {"A", "a", "B", "b", "C", "c", "D", "d", "E",
"e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j"};
boolean trueHeight = true; // checks if height is a letter between a-j/A-J
do {
Terminal.printLine("Input height with letters A to J");
[Code] ...
View Replies
View Related
May 19, 2014
I am stuck with two switch statements that I feel I am close to achieving. My first switch statement is to generate random mathematical operators for the math questions in the game (generated randomly) My second switch statement is to determines which action the system will take upon the correct or incorrect answer. For the first switch statement I have a variable called num. Num is a random integer. I have an operator mapped to each outcome of num. In my second switch statement I am trying to use the variable answer as a variable in the first case but do not know how.
package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
public static void main(String args[]) {
//Declare and construct variables
[Code] ....
View Replies
View Related
Sep 28, 2014
I'm trying to create a switch statement inside of a counter controlled (while) loop that asks for an input of...
"How many characters would you like to convert?"
Then you type in a number > 0, and then it should convert letters into the "1337" equivalent.
This is an example on what it should do.
How many characters would you like to convert? 5
Enter character #1 to convert: !
!-
Enter character #2 to convert: $
$-
Enter character #3 to convert: #
#-
Enter character #4 to convert: *
*-
Enter character #5 to convert: ,
, -
Whenever i try to run the program, i only get the- How many characters would you like to convert- i input 5 but then nothing else prints..
My codes..
System.out.print ( "How many characters would you like to convert?: " );
int convertCounter = 1;
char ch;
ch = input.next().charAt(0);
while (convertCounter > 0)
switch ( ch ){
[Code] ....
View Replies
View Related
Sep 10, 2014
In switch case statement string expression whether it will work or not ???
View Replies
View Related
Feb 21, 2015
I'm using jsoup to parse a calendar page.
I want to use a switch or if/else statement to filter out the data I don't need for the app. This is by no means anything more than a draft because java is easier to work with than android.
Element table = doc.getElementById("launch_calendar");
Iterator<Element> iterate = table.select("td").iterator();
if(iterate.hasNext()){
for(iterate.hasNext();;){
counter++;
[Code] ....
View Replies
View Related
Feb 23, 2014
I am trying to write out a program that takes numerical input from the user and converts it to a date using the English month name. I am experimenting with the method of a "switch" statement without using the "break" clause. However, I seem to be missing something, as Eclipse is telling me I have a syntax error with my block. My curly braces seem properly placed. Also, I made sure to follow guidelines to make my code fit on the screen and remain easy to read.
import acm.program.*;
public class MethodsThatReturnNonNumericValues extends ConsoleProgram {
public void run() {
int month=readInt("Enter month number");
int day=readInt("Enter day");
int year=readInt("Enter year");
[Code] ....
View Replies
View Related