Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi guys, I'm trying to solve a Lab in my class and no matter what I try I can't seem to get my head around this LAB. So can some please provide me with a solution so I can learn from it by seeing how it actually works. I'm going crazy with this lab!

What I have tried:

5.26 LAB: Fun with characters (EO)

Write a method checkCharacter() which has 2 parameters: A String, and a specified index (an int). Method checkCharacter() checks the character at the specified index of the String parameter, and returns a String based on the type of character at that location indicating if the character is a letter, digit, whitespace, or unknown character.

Ex: The method calls below with the given arguments will return the following Strings:
checkCharacter("happy birthday", 2) returns "Character 'p' is a letter"
checkCharacter("happy birthday", 5) returns "Character' is a white space"
checkCharacter("happy birthday 2 you", 15) returns "Character '2' is a digit"
checkCharacter ("happy birthday!", 14) returns "Character ! is unknown"


Your program must define the method:
public String checkCharacter (String word, int index)

import java.util.Scanner;
3 public class Funwithcharacters {

/* Type your code here */

public static void main(String[] args) {

Funwithcharacters labobject = new Funwithcharacters();
String word = "happy birthday"; // Set string
int index = 2; // Set specified index to 2
System.out.println(Labobject.checkcharacter(word, index));

index = 5; // Set specified index to 2
System.out.println(labobject.checkCharacter(word, index));

word = "happy birthday 2 you";
index = 15; // Set specified index to 2
System.out.println(labobject.checkcharacter(word, index));

word = "happy birthday!";
index = 14; 1/ Set specified index to 2
System.out.println(Labobject.checkcharacter(word, index));

}


Would really appreciate it it some could provide me with a solution, as I dont usually do this but this LAB is just giving me a headache.
Posted
Updated 5-Aug-21 1:57am
Comments
Richard MacCutchan 5-Aug-21 8:44am    
Your program must define the method:
public String checkCharacter (String word, int index)

This is not a code writing service.
We do not do your homework.
When you show us some efforts you have made
we will kindly help you.

BTW "I want the solution" could be understood as impolite
and will certainly not speed up getting answers.
 
Share this answer
 
v2
The Character class gently provides all you need, just read 'The Documentation':
Character (Java Platform SE 7 )[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900