Program Not Recognizing String Sentinel?

Jun 10, 2014

I'm new to Java and am trying to create a simple payroll program that uses a while loop to repeat until the user enters "Stop" for the employee's name. I've tried everything I can think of and everything others have suggested and for some reason, I cannot get the program to differentiate between the word "Stop" or any other word. what I'm doing wrong? My code is as follows:

import java.util.Scanner; // imports scanner class for user input
public class Payrolltest {
public static void main( String[] args )// begins execution of program {
Scanner input = new Scanner( System.in ); // creates a scanner to obtain user input
String Employee = "name"; // employee's name

[code]...

View Replies


ADVERTISEMENT

Using Sentinel Value To End A Program?

Mar 24, 2014

So the question asks us to use a sentinel value to end a program, but the sentinel value is 999, but the while loop only recognises strings...
 
static Scanner console = new Scanner (System.in);
public static void main (String[] args)
throws FileNotFoundException 
{
PrintWriter outfFile = new PrintWriter ("Invoice.txt") ;
String firstItem;
String item ;
int price;

[Code] .....

View Replies View Related

How To Use CTRL-D To Terminate Program (sentinel Value)

Mar 1, 2014

how to use the CTRL-D in my program. The program records the amount of times a positive and negative integer is typed. When the user decides to end the program, they will use the CTRL-D to terminate the program. After the button combination has been pressed, I spit out to the user the results. The problem is when I press CTRL-D the program just terminates and I can't even get it to read the next line of code. ....

View Replies View Related

Object Oriented Sentinel Program Won't Work

Nov 28, 2014

I am working on this object oriented sentinel problem but when i am running it, its showing error.

import java.util.Scanner;
public class example1 {
private String gasmilage;
public example1(String milage){
milage=gasmilage;

[code]....

View Replies View Related

Java Program That Will Ask A User To Input Grades Until User Inputs Sentinel Value

Apr 9, 2014

Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".

View Replies View Related

Switch Not Recognizing Upper Case Q

Mar 30, 2014

why this switch code does not work for the 'Q'. Everything works fine for the other cases, i.e. 1,2,3, and 'q', but when I type in 'Q', I get the default case. Please note all the values have been defined in an earlier part of the code but for simplicity's sake I have removed them below

do { 
switch (choix) {
//demande le nombre de patons a achete
case '1':

[Code].....

View Replies View Related

Swing/AWT/SWT :: Not Recognizing A User Input

Sep 21, 2014

I'm doing a problem where someone will input a name and it will show their title or vice versa. It works fine when the user inputs the name but whenever they input a title it is coming back not found. Not sure what I did wrong.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class JEmployeeTitle2 extends JApplet implements //class extends JApplet and AL.
ActionListener

[code]....

View Replies View Related

Average Of Numbers With Sentinel Value Equals To 0

Mar 27, 2014

(Count positive and negative numbers and compute the average of numbers). Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.

I moved the different boolean statements around, but I'm not getting the sentinel value to end the run. It continues to let me add integers endlessly. The code I wrote is below:

package exerciseFourOne;
import java.util.Scanner;
public class AverageOfIntergers {
public static void main(String[] args) {
// TODO Auto-generated method stub
int positive = 0; // number of positive integers
int negative = 0; // number of negative integers
int sum = 0; // value of sum of integers

[Code] .....

View Replies View Related

While Loop With Two Sentinel Values Is Terminating Early

Sep 25, 2014

The program is supposed to print all even and odd numbers between 50 and 100 using ONE while or do while loop. The evens work, but the program terminates after printing 51 for the odds, which doesn't satisfy the second value sentinel value for the while loop.

public class EvenOdd {
public static void main(String args[]) {
int x = 50;
int y = 50;
int i = 0;
int j = 0;
System.out.print("Even numbers between 50 and 100: ");

[Code] ....

View Replies View Related

String Reverser Program?

Feb 14, 2014

I was tasked to make a program that took a string input, then reversed it using recursion. I'm getting a syntax error causing an exit code 1. Also, I'm sure there may be an error in the code as I'm not very strong with recursion.

import java.util.Scanner;
public class StringReverser
{
public static void main(String[] args)

[Code].....

View Replies View Related

Program Will Only Accept Input From 1 String?

Jan 14, 2015

I am trying to create a fortune teller and everything is running fine except the program does not prompt you to answer the questions

Do you like donuts?
and
What did you have for breakfast?

Here is the code this is in Bluej :

import java.util.Scanner;
public class FortuneTeller {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to Fortune Teller");

[Code] .....

View Replies View Related

Program Is A Random String Generator

Sep 11, 2014

The program is a Random String Generator; it takes user input (type of string, and length), and then generates a string with their requested method. Its extremly simplistic, but had some interesting coding challenges considering I only just did 'Hello World' a few days back xP I actually already have quite a few additions and modifications I want to make to it, but wanted to get a bit of feedback on it otherwise.

The Main Class, RandomStringGenerator.java:URL...
InputHandler.java:URL....
RandomGenerator.java: URL....

View Replies View Related

String To Unicode Converter Program In Java

Mar 2, 2014

I need a program to convert any string of any language to unicode using java....

View Replies View Related

String Manipulation For Program Manipulating Name Of City

Jan 23, 2015

I have to write a program that asks the user to enter the name of their favorite city and use string variable to store the input. The program should display the following:

-The number of characters in the city name
-The name of the city in all uppercase letters
-The name of the city in all lowercase letters
-The first character in the name of the city

However, I can't seem to get past the following errors;

Programming Challenge #12.java:37: error: variable cityFirstChar is already defined in method main(String[])
char cityFirstChar = city.charAt(0);
^
8 errors[CODE
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
[/CODE]

My code is as follows:

import java.util.Scanner;
 
/*
* 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.
*/
 
[code]....

View Replies View Related

Create A Java Program That Accepts A String

Feb 19, 2014

So basically I have to create a java program that accepts a string and does the following:

1.) Insert a blank space before capital letters
2.) Convert any capital letters into lower case except the first letter(if it is capital).

So if the user enters "HiMyNameIsJohn", the result should be "Hi my name is john". I am having problems inside my changeMe method. Everything works fine including putting a blank space in between upper case words. So from the previous example, my code would show "Hi My Name Is John". I am having issues making the code to convert the upper case letters into lower case. Im pretty sure the code should be right after the str.insert(i, " "). But I do not how to code it. Ive thought about Character.toUpperCase(ch); but doesnt work.

Java Code:

import java.util.*;
public class WordSeparator
{
public static void main(String[] args)
{
String word1, word2;
Scanner userInput = new Scanner(System.in);

[code]....

View Replies View Related

Java Program To Count Each Repeated Letters In Given String?

Jan 12, 2014

for example if the given string is: The world is running java technology?

Ans:
T is =2
h is=2
e is=2
w is=1
n= 4

like wise i need out put of the program?

View Replies View Related

Java Program To Remove Repeated Characters In A String

Jan 27, 2015

I was trying to create a java program which can remove the repeated characters in a String. For ex-

Input: kamehamehaaa
Output: kameh

Here is my code:-

import java.util.Scanner;
class replace {
public static void main (String args[]) {
Scanner br = new Scanner(System.in);
System.out.println("Enter a word");

[Code] ....

On executing the program, StringOutOfBoundsIndex error occurs.

View Replies View Related

Program Is Working But String Index Out Of Range Error

Sep 5, 2014

My Computer Programming teacher has given the class a problem that requires the use of var.charAt(), var.length() and while/for. Basically, the problem is that we have to create program that'll show a mirrored or reverse version of the entered word. Like for example, if your input is the word "Hello" (the quotation marks aren't included), the output will be "olleH".

Here's the code:

import java.io.*;
public class StringMirror
{public static void main (String [] args) throws IOException
{BufferedReader scan = new BufferedReader (new InputStreamReader(System.in));
String enteredWord = "";
int lengthOfTheWord = 0;
int lengthOfTheWordMinusOneVersion = 0;

[code]....

It is working, but the problem is that after the output, there's this error that says String index out of range: -1.

the program is working but I kind of wanted it to have no errors in the end.

View Replies View Related

Program Used To Implement Palindrome String Of Using Stack And Queue

Jan 8, 2015

this program used to implement palindrome String of using stack and queue.i wont to enter string by scanner how can i chang it ??????

class Palindrom_homwork1{
int top=-1;
int rear=-1;
int front=-1;
int max=3;
int max1=3;
char array[]=new char[max];
char array1[]=new char[max1];

[code]....

View Replies View Related

Write A Program That Use Java String Class Methods

Feb 10, 2015

There are two versions

1. The words remain in their places but the letters are reversed. Eg I love you becomes Ievol uoy
2. The words are also reversed. Eg I love you becomes uoy evol IWrite a program that use the java String class methods.

View Replies View Related

Program To See Occurrences Of A Character In String Stored In Text File

Apr 26, 2014

I have this program to see the occurrences of a character in a string stored in a text file. My text file has the following contents (as shown below):

Quote
P-P-N-N-L-V
N-R-U-S-R-Q
K-Q-E-L-E-A
A-J-B-G-E-F
F-E-L-Q-R-R
U-F-J-V-I-M
P-I-Q-K-B-K
U-N-L-F-O-B
M-A-N-M-H-O
P-Q-J-D-N-I
G-U-O-D-F-I
Q-M-M-B-C-Q
N-B-I-L-E-J
S-A-T-Q-H-U
C-L-G-U-J-M
R-P-V-M-A-A
C-R-A-V-L-B
M-U-Q-K-M-Q
E-I-C-H-V-J
J-N-N-K-R-P

View Replies View Related

Program To Accept 10 Name In String And Sorting In Bubble Sort Alphabetically

Jun 10, 2014

import java.io.*;
Class bubble
{
public static void main()throws IOException
{
BuffetedReader br=new BufferedReader (new InputStreamReader (System.in));
int j, k, temp;
String st[]=new string [10];

[Code] .....

View Replies View Related

Program That Read TXT File And Count Character Occurrence In String

Jan 12, 2014

I wrote a program to read a .txt file and return how many times a, e, s, and t occur in the .txt file. I am getting an error that I do not know how to fix. It says Error: FileNotFoundException cannot be resolved to a type...

import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
public class Count
{
public static void main (String[] args) throws FileNotFoundException {
String phrase; // a string of characters

[Code] ....

View Replies View Related

Write GUI Program To Convert All Lowercase Letters In String To Uppercase?

Mar 21, 2015

Write a GUI program to convert all lowercase letters in a string to uppercase letters, and vice versa. For example, Alb34eRt will be converted to aLB34ErT.

View Replies View Related

Program To Accept String Float And Integer As Command Line Arguments

Feb 8, 2015

Write a java program to accept a string, float and an integer as command line arguments. String value should be displayed. Also the program should display the maximum value of two numbers. Use Integer.parseInt() and Float.parseFloat()

View Replies View Related

Retrieving User Input String From Keyboard - Program Errors (try / Catch)

Sep 23, 2014

I need to design, implement, and test a program to input and analyze a name. The program begins by retrieving a user input string from the keyboard. This string is intended to be the user's name. These are the errors we have to search analyze the user input for: No blanks between names firstName and lastName, Non-alphabetic characters in names, Less than two characters in first name, and Less than two characters in last name. Each of these errors must be thrown. All exceptions must be derived from a programmer-defined class called NameException. Each exception should use a detailed message to differentiate among the file types of errors.

This is the format of my NameException class, is the format itself correct? I will fill in the details of each exception I am just wondering if that is how I should set it up.

public class NameException extends Exception {
private String firstName, lastName;
public NoBlanksException(String firstName,String lastName) {
}
public NonAlphabeticalCharactersException(String firstName, String lastName) {

[Code] .....

I was told not to try and catch thrown errors in the main method, would I just create another method in the Driver class to take care of that then?

View Replies View Related







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