Method That Counts Registered Persons In A Program
May 7, 2015
Any method or two that counts, for example, registered persons in a program?
I have this insurance program that have different insurance registered on persons.
I really want a history class that counts registered persons, and theirs insurance.
View Replies
ADVERTISEMENT
Sep 29, 2014
I can't get my code to print it like it's on the picture.
import javax.swing.JOptionPane;
import java.util.*;
public class BokstavTeller
{
public static void main( String[] args ) {
String input = JOptionPane.showInputDialog(
[Code] .....
View Replies
View Related
Dec 3, 2014
What my program needs to do:
1) accepts a filename from the user that indicates the input file
2)obtains a filename to use as the output file
3)the program then reads the file and reports how many of each letter are there in the file.
4)if the file could not be opened, you must ask the user for valid file name until one is given
5)once a valid file name is given, print all of contents and store the analysis of the file in the output file name specified
You will be reading the input from a file and printing the output to another file. For example, if the file input.txt contains:
This file contains lett3rs.
YoU counT Only lEtTers, not numb3rs.
How many h's are in "Ohhhhhhhhhhh no!"?
The program should ignore white spaces, new lines and other special characters or numbers. It should count only the letters (a-z and/or A-Z) in the input file.
An example execution might look like this:
Input a file name: notAFile.txt
Invalid filename given. Input another.
Input a file name: alsoNotAFile.txt
Invalid filename given. Input another.
Input a file name: input.txt
[Code] ....
1)The last try/catch block was given by my professor, however the only thing it does is print out "hello java" into an out file. How would I make it print out similar to that of the given example?
2)I figured out how to make the array print out ABCDEFG... etc...how to count the amount of them.
View Replies
View Related
Dec 10, 2014
int getrelationshiptype(string person1, string person2)
int type = -1
I have to check if there is relationship between personA and personB then return relationship otherwise have to return -1 for no relationship..
View Replies
View Related
Dec 7, 2014
Everything compiles but doesn't work like it should. What the idea is, is to be able to add class personnel objects and have them saved in a file, so that later on i would be able to see them.
Back to my problem: When i create a new "Personnel" and try to run Write and read, to see if my new "Personnel" is added to the list, it's not there at all... what do i do wrong?
import java.io.*;
class Personnel implements Serializable
//No other action required by Serializable interface.
{
private long payrollNum;
private String surname;
private String firstNames;
[Code] ....
View Replies
View Related
Sep 1, 2014
I have uninstalled JAVA because I needed to download the 64-bit version but no matter WHAT I do I still get the same installation error message "keyset as registered in invalid" and I was downloading it from [URL] .... I will do whatever it takes to fix this!
View Replies
View Related
Oct 15, 2014
This is a piece of a program I am trying to write,my only problem is when an incorrect input is entered in "genreType" it still counts as a loop and therefore I do not end up with 20 results I am looking for..I have tried multiple different ways but nothing seems to work for me.
package assignment_1;
import javax.swing.*;
public class Assignment_1 {
public static void main(String[] args) {
int rockCounter=0;
int popCounter= 0;
int danceCounter= 0
[Code] ....
View Replies
View Related
Jan 17, 2015
/*****************************************************************
* Creates an MxN minesweeper game where each cell is a bomb with probability p.
* Prints out the MxN game and the neighboring bomb counts.
*
* Sample execution:
*
* % java Minesweeper 5 10 0.3
* * . . . . . . . . *
* . . . . . . * . . .
* . . . . . . . . * *
* . . . * * * . . * .
* . . . * . . . . . .
*
* * 1 0 0 0 1 1 1 1 *
* 1 1 0 0 0 1 * 2 3 3
* 0 0 1 2 3 3 2 3 * *
* 0 0 2 * * * 1 2 * 3
* 0 0 2 * 4 2 1 1 1 1
*
*
*************************************************************************/
public class MineSweeper
{
public static void main(String[] args)
{
int n = Integer.parseInt(args[0]); //columns
int s = Integer.parseInt(args[1]); //rows
int p = Integer.parseInt(args[2]); //max number of bombs
[Code] .....
Console:
. . * . *
. * . . .
. . * . *
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at Stefan.Minesweeper.main(Minesweeper.java:85)
Every time the compiler shows me this Array Index Out Of Bounds and shows me in the witch line i have error but i just don't get it how to fixed it and why compiler printing me this mistake because there is enough space in array field[][] because i provided a n+2 X s+2 fields in array and i am using just 1 to n ,including and 1 to s ,including m, so i have not used fields from field[0][0] to field[0][s+1] and field[0][0] to field[n+1][0], field[n+1][0] to field[n+1][s+1] ,field[n+1][s+1] to field[0][s+1] ,so i suppose i can check their values and do not get out of array bounds,but compiler claims otherwise!!!
View Replies
View Related
Mar 3, 2015
I am a first-timer using J2EE and here on coderanch.com and wanted to make a Simple Email-like System which a Registered User can Send Message/Email to another Registered User. how to do it. I have already my register/login process done but I'm stuck on how to make the Email. And I have an sample Bootstrap for my UserInterface which I want to use.
View Replies
View Related
Oct 23, 2014
Write a java code that asks the user for an Integer and then counts down from that number to 0. Printing each number. For example:
Enter an Integer: 5 (enter) <--- user hits the enter key
5
4
3
2
1
0
import java.util.Scanner;
public class Exam{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
View Replies
View Related
Nov 4, 2014
I am trying to create a method for my "ticketmachine" object that counts ticket objects in an arraylist of "ticket" objects with a specified field "route". The method works if i change the field type of the ticket class to public, however according to the homework task "route" of the ticket class needs to remain a private field.
Here is my code for the method.
public int countTickets(String route) //HAD TO CHANGE Ticket class FIELD "ROUTE" TO PUBLIC!!!!
{
int index = 0; //returns the number of Ticket objects in the machine with the specified "route".
int ticketCounter = 0;
while (index < tickets.size())
[Code] ....
Is my general approach to the problem wrong? also is there a way to access a private field?
View Replies
View Related
Nov 19, 2009
Is it possible to run a program(a method) without a main method?
View Replies
View Related
Feb 20, 2015
Write method distance, which calculates the distance between two points (x1, y1) and (x2, y2). All numbers and returned values should be of type double. Incorporate this method into an program that enable the user to enter the coordinates of the points, then calculate and display the distance by calling the method –distance.
I've tried numerous times to make it work and I'm on the right path, however I'm missing some things in the code to make my results look like this later on, which I've attached onto this post.
View Replies
View Related
Apr 7, 2015
I am trying to create a Hangman program using Arrays. When trying to compile my code I get the following error: 50: error: no suitable method found
for setCharAt(int,String)
method StringBuffer.setCharAt(int,char) is not applicable
method AbstractStringBuilder.setCharAt(int,char) is not applicable
Here's the code:
import java.util.*;
import java.io.*;
public class hangman {
public static void main() throws IOException {
Scanner kb = new Scanner(System.in);
String filename;
[code]....
View Replies
View Related
Dec 3, 2014
I have understood my programming class up to this point and now I have been given a lab that I can't figure out for the life of me. Here what I have to do: Write a program that will call a method (called f) to calculate the following function" f(x)=(x^2)-16...this is what the output should be:
x f(x)
1 -15
2 -12
3 -7
4 0
5 9
6 20
7 33
8 48
9 65
10 84
I guess it also has to print this output in a table even though my professor never mentioned it. Usually
public class Lab12 {
public static int f(int x)
{
return x*x-16;
[code]....
View Replies
View Related
Mar 4, 2014
class A
{
public final int Add(int a,int b) {
return a+b;
}
}
class B
{
public static void main (String args[])
{
System.out.println(Model.Add(5,10));
}
}
This is what I have. I'm not sure if this even makes use of a final method. But when I run it I get an error saying cannot find symbol for line 13.
View Replies
View Related
Jun 9, 2014
A method is declared to take three arguments. A program calls this method and passes only two arguments.Will it take the third argument as
1 null
2 void
3 zero
4 Compilation error
View Replies
View Related
May 27, 2014
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?
View Replies
View Related
May 27, 2014
I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.
Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.
import java.util.Scanner;
public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
[Code] ....
I have to make new string array in the method and return words without four letters in the main method
View Replies
View Related
Apr 29, 2014
Consider the following recursive method that calculates the greatest common divisor using Euclidean method.
PHP Code:
public static int GCD ( int x , int y )
{
if ( y == 0 )
return x;
else if ( x >= y && y > 0)
return GCD ( y , x % y );
else return GCD ( y , x );
}
Trace the above method for x=32 and y=46
View Replies
View Related
Oct 30, 2014
Alright, I don't understand how to link my compress method to my return statement method "getPText". Also in my compression I only want it to compress for 3 or more consecutive letters.
import java.util.Scanner;
class RunLengthCode {
String pText;
String cText;
void setPText(String PText) {
pText = "";
}
[Code]...
View Replies
View Related
Apr 21, 2014
I have two classes (Daughter and Son) that contain some very similar method definitions:
public class Family {
public static void main(String[] args) {
Daughter d = new Daughter();
Son s = new Son();
d.speak();
s.speak();
[Code] .....
Each of those classes has a "speak" method with two out of three lines being identical. I could move those into a parent class, but I need each of the child classes to continue to exhibit its unique behavior. I'm trying the approach below, which replaces the unique code with a call to a "placeholder" method that must be implemented by each child class:
public class Family {
public static void main(String[] args) {
Daughter d = new Daughter();
Son s = new Son();
[Code] .....
This works and moves the shared code from two places (the Daughter and Son classes) into one place (the new Mother class, which is now a parent class of Daughter and Son). Something about this feels a bit odd to me, though. It's one thing for a child class to override a parent class's methods to extend or alter their behavior. But, here, I've implemented an abstract method in the parent class to alter what happens when the parent class's method (speak(), in this case) is called, without overriding that parent class method itself.
View Replies
View Related
Feb 13, 2014
I am just trying to test this array, for a locker combination program that involves classes...but the array is printing out the whacky numbers for the location. When I try to call the method in the main, it does not work. How do I call a method that exist within a class into the main method?
public class locker {
public static void main(String[] args) {
CombinationLock();
[code]....
View Replies
View Related
Mar 5, 2014
Which method is used while passing or returning a java object from the native method?
View Replies
View Related
Oct 23, 2014
I am trying to call a private method to another method that are located in the same class.
I am trying to call prepareString to the encode method below.
Java Code:
public class ShiftEncoderDecoder
private String prepareString(String plainText)
{
String preparedString = "";
for(int i = 0 ; i < plainText.length();i++)
if(Character.isAlphabetic(plainText.charAt(i)))
[Code] .....
View Replies
View Related
Feb 26, 2015
I am currently working on a dice game. I have a private method called rollDice and it performs the action of rolling two dice. For my project, I need to create another method called playerRolls and I am supposed to invoke the rollDice method in the playerRolls method and perform actions based off of that. My question right now is how do I invoke a method into another method of the same class?
View Replies
View Related