Jump to content

Application

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
hoku2000_99

hoku2000_99

    Newbie

  • Members
  • PipPip
  • 24 posts
I have this application and have some of it started, but I am stuck.

This is what I have so far:

	import java.util.Random;

	public class Name
	{

		public static void main (String[]args)

		{
		   	String name ="john smith";
		   	String ID1, ID2, ID3;

		  	String firstName="john";
		   	String lastName="smith";


		   	System.out.println("First name: " + firstName);
		   	System.out.println("Last name: " + lastName);

			Random generator= new Random();
			int num1;

			ID2=ID.toUpperCase();
			num1=generator.nextInt(31);
			System.out.println("ID: " + num1);




		}
}
My application is suppose to read a persons first and last name separately.
I have to create a string "ID" for that person that contains the first letter of the person's first name, followed by the first 3 characters of the person's last name, which is then followed by a random number in the range 15 - 30. Print this new ID.

I have to create a second ID that converts all letters in the string to uppercase. Print this second ID.

I have to create a third ID that will replace all of the occurrences of the digit 8 and letter A in the second ID. Print this third ID.

Edited by WingedPanther, 17 February 2009 - 08:33 AM.
add code tags (the # button)


#2
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts
I feel nice today, so going to give you a "half baked" program...

The rest is on your shoulders !

import java.util.Random;

public class MakeMe {

public static void main (String[]args) {

String name ="john smith";

String ID = "ID";

int num = 15;

String firstName="john";

String lastName="smith";


System.out.println("First name: " + firstName);

System.out.println("Last name: " + lastName);


	Random generator= new Random();

	num = generator.nextInt(num);

	num = Math.abs(num);

	num = num + 15;

	num += 1;

	System.out.println("First letter of firstname: "+name.substring(0, 1)+

			" The three last letters of lastname: "+name.substring(7, 10)+

			" "+ID+": "+num);

	}

}

Try to figure out next step, I will give the hint...
More substrings...and length, go now and learn !
Posted Image

#3
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
Dont have immediate access to a compiler, but im curious of what value num would end up with. I thought < num = generator.nextInt(num); > generates a specified range of ints. Or is that deliberate?
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#4
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

fread said:

Dont have immediate access to a compiler, but im curious of what value num would end up with. I thought < num = generator.nextInt(num); > generates a specified range of ints. Or is that deliberate?

15 <=> 30

By making the start point 15 we add in 15+Any random number within 15 range !
So it will automatically do...
15+1
15+6
15+12
w/e

Edited by Turk4n, 17 February 2009 - 03:42 AM.
More...

Posted Image

#5
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
Shoot!!! so accustomed seeing % 15 + 1. I forgot you can do that with
generator.nextInt(range).
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#6
hoku2000_99

hoku2000_99

    Newbie

  • Members
  • PipPip
  • 24 posts
Thanks for the help!

#7
hoku2000_99

hoku2000_99

    Newbie

  • Members
  • PipPip
  • 24 posts
I got stuck again. I tired to go back and add the random number between 15-30, but when I test my application, one time it started at 0. I am not too sure how to fix that.

For my second ID, I got it, but doesnt work.

Then for my third ID, I have replace all occurrences of the digit 8 and letter A in the second ID with an *. Print this third ID. I was thinking it would be like ID3=ID2.replace('8','A'). And I do I replace the occurrences of 8 and A with the *?

Here is my code so far:
	import java.util.Random;

	public class MakeMe
	{
	public static void main (String[]args)
	{
	String name ="john smith";
	String ID = "ID";
	String ID2=name.toUpperCase();

	int num;


	String firstName="john";
	String lastName="smith";

	System.out.println("First name: " + firstName);
	System.out.println("Last name: " + lastName);

	Random generator = new Random();
	num=generator.nextInt(16)+15;


	System.out.println("First letter of firstname: "+name.substring(0, 1));
	System.out.println("The first three letters of lastname: "+name.substring(5, 8));
	System.out.println("ID: "+num);



	}
}

Edited by WingedPanther, 19 February 2009 - 09:04 AM.
add code tags (the # button)


#8
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts
I can't see what your after, digit 8, A?
ID 1,2 and 3?
Are you after to replace second ID with first ID and replace third ID with second ID?

Could you explain in detail?
I could help you out if you just tell me specifically what you want to do !
Posted Image

#9
hoku2000_99

hoku2000_99

    Newbie

  • Members
  • PipPip
  • 24 posts
When my application is done this is what its suppose to do and what I am suppose to do. I think I am suppose to have three different ID's declared.

Reads the person's first and last name (separately)

I have to create a string "ID" for that person that contains the first letter of the person's first name, followed by the first 3 characters of the person's last name, which is then followed by a random number in the range 15 - 30. Print this new ID.

I have create a second ID that converts all letters in the string to uppercase. Print this second ID.

I have to create a third ID that replaces all occurrences of the digit 8 and letter A in the second ID with an *. Print this third ID.

#10
hoku2000_99

hoku2000_99

    Newbie

  • Members
  • PipPip
  • 24 posts
Here is my updated code.

	import java.util.Random;

	public class MakeMe
	{
	public static void main (String[]args)
	{

	String ID = "john smith";
	String ID2=ID.toUpperCase();
	String ID3=ID2.replace('8','E');

	int num;


	String firstName="john";
	String lastName="smith";

	System.out.println("First name: " + firstName);
	System.out.println("Last name: " + lastName);

	Random generator = new Random();
	num=generator.nextInt(16)+15;


	System.out.println("First letter of firstname: "+ID.substring(0, 1));
	System.out.println("The first three letters of lastname: "+ID.substring(5, 8));
	System.out.println("Number: "+num);
	System.out.println("*" + ID3);



	}
}

Edited by WingedPanther, 19 February 2009 - 09:03 AM.
add code tags (the # button)


#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
hoku, please use code tags (the # button)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#12
hoku2000_99

hoku2000_99

    Newbie

  • Members
  • PipPip
  • 24 posts
Updated code. Please give me feedback.

  	import java.until.Scanner;

	import java.util.Random;


	public class Name

	{

	public static void main (String[]args)

	{


	int num;

	String firstName;

	String lastName;

	String ID;

	String ID2=ID.toUpperCase();

	String ID3=ID2.replace('8','*');

	String ID3=ID2.replace('A','*');



	Scanner scan = new Scanner(System.in);


	System.out.println("Enter first name: "  + ID);

	ID=scan.nextLine();


	System.out.println("Enter last name: " +ID3+ID2);

	lastName=scan.nextLine();


	Random generator = new Random();

	num=generator.nextInt(16)+15;


	System.out.println("First letter of firstname: "+ID3.substring(0, 1));

	System.out.println("The first three letters of lastname: "+ID.substring(5, 8));

	System.out.println("Number: "+num + ID3);


	}

}