Switch Statement - Determine Outcomes For Letter Grades

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


ADVERTISEMENT

Simple GradeBook - Switch Statement To Count A B C D And F Grades

Nov 4, 2014

// GradeBook class uses switch statement to count A, B, C, D and F grades.

import java.util.Scanner;
public class GradeBook
{
private String courseName;
private int total;
private int gradeCounter;
private int aCount;

[Code] .....

Then eclipse told me that:

"Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at chapter5_control_statements_II.GradeBook.inputGrades(GradeBook.java:52)
at chapter5_control_statements_II.GradeBookTest.main(GradeBookTest.java:11)"

View Replies View Related

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 View Related

Switch Statements To Initialize Variable Due To Multiple Outcomes?

May 20, 2014

After this problem is fixed, my math game will run. The answer variable is supposed to be equal to the cases in the second switch statement by random but I get errors whenever I try to initialize it this way. I have been writing this program for almost 5 days now and it is finally wrapping up. Why I can't map the answer variable to the second switch statement the way I want to?

package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
  public static void main(String args[]) {
//Declare and construct variables
Random randomnum = new Random();
int fnum, snum, answer;

[Code] .....

View Replies View Related

Convert Integer To Letter Grades

Jan 31, 2014

/*This program will convert integer grades to letter grades and say how many A's, B's, C's, D's , F's do we have

public class DSlab3 {
private char LetterGrades;
private int IntegerGrades;
//default constructor
public DSlab3() {
LetterGrades =' ';
IntegerGrades = 0;

[Code] .....

View Replies View Related

Java Program That Converts Number Grades To Letter?

Aug 3, 2014

I wrote a java application that coverts number grades to letter grades. Here is what it looks like:

/java application to That corresponds the letter grade with the number grade
import java.util.Scanner; //program uses the class scanner
public class gradescore{

[Code]....

View Replies View Related

How To Turn If Statement Into A Case / Switch Statement

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

Using Switch Statement Inside If Statement

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

Way To Incorporate Switch Statement

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

Looping Through While Loop With Switch Statement?

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

Can Insert While Loop In Switch Statement?

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

Can't Get Values Found In Switch Statement

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

Switch Statement Inside While Loop

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

Modifying ArrayList With Switch Statement

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

Check If Height Is A Letter Between A To J - If Statement Always False

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

Using Variables In Switch Statement Case Clauses

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

Counter Controlled Loop With A Switch Statement

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

Switch Case Statement - String Expression

Sep 10, 2014

In switch case statement string expression whether it will work or not ???

View Replies View Related

Use Switch Or If / Else Statement To Filter Out Data Not Required For App

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

Method That Returns Non-Numeric Values - Switch Statement

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

Cash Register Program For 5 Products Using Switch Or If Else Statement In Java

Dec 3, 2014

We're told to make a cash register program for 5 products using Java. It loops until "-1" is entered on the "Continue?" input dialog box.There should be a:

1. Main Menu - where the user will pick what to buy (one product at a time) like the sample code below and prompt the user if he will buy another product or not. If yes, the program will go back to the main menu to buy another product and if not, continue to the program. And it looks something like this: LEvFOwQ.png

2. Receipt - at the end of every transaction.

3. Daily Sales Report where it shows all receipts then grand total like:

Transaction 1

-subtotal

Transaction 2

-subtotal

and so on then,

GRAND TOTAL

4. Inventory Report where it shows the Items Available before the Selling, Items Sold, and Items Available after Selling in table format.

Below is the code for a simple cash register for only one product that I made but I need to upgrade it for it to work for 5 products. That code will serve as the basis for this program.make the switch or if-else statement for the main menu first and if I got it right I try doing the rest.

int userQty1 = Integer.parseInt(JOptionPane.showInputDialog(
"Product ID Product Name Product Quantity Product Price"
+prodID1 + " " +prodName1 + " " + prodQty1 + " " +prodPrice1 "
"
+ and so on until prod5));

[code].....

View Replies View Related

Writing A Program Using Switch Statement - Allow Users To Choose Item Of A Menu

Oct 5, 2014

Write a program using switch statement to allow users to choose an item of a menu. For example, the menu looks like the following.

File menu
1. Open
2. Close
3. Save
4. Exit
Enter your choice:

If you type 1, then your program should print out "Open is selected" (double quotes not included).

Notice:
(1) Using Scanner to get user choice;
(2) If the number user input is not in {1,2,3,4}, your program should let user know that.

Here's what I have:

public static void main (String[] args) {
int user = 1
switch (1) {
case value: 1
System.out.println ("Open is selected");

[Code] .....

View Replies View Related

Averaging Grades Program Not Adding Grades

Aug 18, 2014

Write a Swing program that declares an empty array of grades with a maximum length of 50. Implement a JOptionPane input box within a while loop to allow the user to enter grades. When the user enters the sentinel value of -1, that will signal the end of the data input loop.

After the grades are entered, a content pane should display the grades sorted from lowest to highest. Write a loop that goes through the array looking for elements that are greater than zero (0). Keep a running count of those items, and also accumulate them into a grand total. Divide the grand total by the number of grades entered to find an average, and display the average at the end of the sorted list of grades. Use the DecimalFormat method to display the average to 2 decimal places.

View Replies View Related

Strings - Change Every Capital Letter Into Small Letter And Vise Versa

Oct 22, 2014

I have a problem with functions connected to strings.

I have a random String, e.g. "Hello World!" and I have to change every capital Letter into a small letter and vise versa. This alone would be fairly simple, but I have to do it with two other strings.

lowercase= "abcde...z" and

uppercase="ABCDE...Z". Every small letter stands at the very same position as the capital letter, but in the other string.

There should be a letter for letter search in lowercase and uppercase for the letters of "Hello World".

How I could solve the task, however I need a way to search the first string, here "Hello World", according to position. A statement which does: "Give me the letter of position x". This found letter should be able to be stored in a variable or else be able to be used by another statement. And it should be compatible with a for lope.

View Replies View Related

How To Get 1st Letter Of Input (String) And Compare It To Single Letter Before Insert To DB

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

All Possible Outcomes Of Dice Roll Using Recursion

Nov 26, 2014

Here is what I have so far:

/**
* This class encapsulates a simple dice game. The number of dice and number of sides on those dice are given by instance variables. The outcomes ArrayList holds a list of all possible outcomes of throwing that number of dice with that number of sides.
*
* If there were 2 dice, each with 6 sides, then possible outcomes would include 1 1, 1 2, 1 3, 1 4, 1 5, 1 6, 2 1, 2 2, 2 3, and so on.
*
* Your task is to complete the methods that calculate the possible outcomes. One method calculates outcomes allowing for repeated numbers. One method calculates the outcomes of a fictional dice game where repeated numbers cannot occur.
*
* You must use recursion. This is a variation on the permutations problem from the book.
*/

public class Dice
{
private static int numberOfSides;
private static int numberOfDice;
public ArrayList<String> outcomes;

[code]...

I manage to calculate the numberOfOutcomes correctly, but then get a nullPointerException. Also, is there a way that I can use getNumberOf Outcomes without making it static? The testing code that the teacher provided is using it in another class and if I make it static, then it doesn't work in that file.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved