-
java programming assignment help
how to code this one??
Code :
1. Create a program that accepts character input then determine whether it is letter, number or a symbol. If it is a letter, display whether it is Uppercase or lowercase letter. If it is a digit, display its square root. (Note: Use Character and JOptionPane class)
Use the following predefined methods:
isLetter( )
isDigit( )
charAt( )
length( )
sqrt( )
showConfirmDialog( )
SAMPLE OUTPUT 1:
Enter a character: 9
The character is a digit.
The square root of 9 is 3.0
Try again?[Y/N]
SAMPLE OUTPUT 2:
Enter a character: *
The character is a symbol.
Try again?[Y/N]
SAMPLE OUTPUT 3:
Enter a character: A
The character is an Uppercase letter.
Try again?[Y/N]
SAMPLE OUTPUT 4:
Enter a character: string10
Invalid Input. Input a character only.
Try again?[Y/N]
-
Re: java programming assignment help
Do you have any specific questions about the program? Show some effort and you'll get some help.
-
Re: java programming assignment help
if i can code even if a little of it i will do it but i really do not know how to start coding it...because we didnt study it..it is been an activity already
-
Re: java programming assignment help
Start by making a list the the steps the program needs to do.
Then start with the first step, code it, compile it, test it. When it works, move to the next item in the list.
Look at the Scanner class's methods for reading input from a user.
-
Re: java programming assignment help
help about getting the square root of i enter 9 the answer will be 7.54983443527075 and it should be 3
Code :
/**
* @(#)activity2.java
*
*
* @author
* @version 1.00 2012/10/1
*/
import javax.swing.*;
public class activity2 {
public static void main(String args[]) {
String input;
char inputs;
double x;
input=JOptionPane.showInputDialog(null,"Enter a character :");
inputs= input.charAt(0);
if(inputs>='a'&&inputs<='z'){
System.out.println("Lowercase");
}
else if(inputs>='A'&&inputs<='Z'){
System.out.println("Uppercase");
}
else if(inputs>='A'&&inputs<='Z'){
System.out.println("Uppercase");
}
else if(Character.isDigit(inputs)){
System.out.println("The character is a digit.");
System.out.println("The square root of " + inputs + " is " + Math.sqrt(inputs));
}
}
}
-
Re: java programming assignment help
Please use code tags to wrap code, not quote tags.
You are confusing char and int values. The char '1' does not have the int value of 1.
Do this to see a char's int value: System.out.println((int)'3' + " vs " + 3);
char is a primitive that can be used in arithmetic forumlas: int x = 'b' - 'a';
Given a char, you need to convert it to an int. One quick way to convert a char digit to an int is to subtract '0' from it. '9' - '0' = 9
-
Re: java programming assignment help
may i ask if how will i include it to my code?
-
Re: java programming assignment help
Quote:
how will i include it to my code?
Include what? Please be more specific.
Please edit your post and change quote to code tags.
-
Re: java programming assignment help
i do not know where to add the -0 to my program... or in short the one that you are telling to me sir
-
Re: java programming assignment help
Your code uses a char like '9' as if it were an int 9. You need to convert the char digit to an int value.
One way to do that is to subtract '0' from the char: '9' - '0' = 9
Did you try this: System.out.println((int)'9' + " vs " + 9);
What was the first number that printed? Was the sqrt() of that number the same as you got:
Quote:
square root of i enter 9 the answer will be 7.54983443527075
-
Re: java programming assignment help
ok i got it thanks.
but another problem why my program doesn't output The character is a symbol. if i input * but if i input $ it will output The character is a symbol.
Code :
import javax.swing.*;
public class aa {
public static void main(String args[]) {
String input;
char inputs;
double x;
input=JOptionPane.showInputDialog(null,"Enter a character :");
inputs= input.charAt(0);
if (Character.getType(inputs) == Character.LOWERCASE_LETTER){
System.out.println("Lowercase");
}
else if(Character.getType(inputs) == Character.UPPERCASE_LETTER){
System.out.println("Uppercase");
}
else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL){
System.out.println("The character is a symbol.");
}
else if(Character.isDigit(inputs)){
int num = inputs - '0';
System.out.println("The character is a digit.");
System.out.println("The square root of " + inputs + " is " + Math.sqrt(num));
}
}
}
-
Re: java programming assignment help
Can you copy and post here the content of the console that shows your input and the programs output?
Also Look at the API doc for the Character class. Is '*' defined as a symbol?
-
Re: java programming assignment help
if i input *.. my jcreator will not post anything instead process complete
-
Re: java programming assignment help
For a test, change this line and execute the program and see what happens:
Code :
input= "*"; // JOptionPane.showInputDialog(null,"Enter a character :");
Quote:
if i input *.. my jcreator will not post anything
At the end of the chain of if/else if you should add an else statement that prints a message about none of the if statements were true for the value of input. The code ignores and does nothing if none of the if statements were true.
-
Re: java programming assignment help
i tried your idea sir but still my program still doesnt recognize * as a symbol
-
Re: java programming assignment help
What is printed out in the else statement you added to the end of the if/else if chain?
What is the value of the '*'? Does your code test for it?
-
Re: java programming assignment help
i already add else then if i input * it will output The character is a symbol. but is there other way that when you input * and it will output The character is a symbol. with using else?? instead else if or if only?
-
Re: java programming assignment help
If you want the "character is a symbol" message to print for an "*" you need to add a test to the if statement that controls the printing of that message.
Code :
else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL || <*** ADD TEST HERE**>){
System.out.println("The character is a symbol.");
}
-
Re: java programming assignment help
thank you again for the help..
but what are the different keys that can be called sa symbol in java??
also how can i insert the isLetter() for my code below(what will i change to make it isLetter()
Code :
import javax.swing.*;
public class aa {
public static void main(String args[]) {
String input= "*";
char inputs;
double x;
int loop=0;
while (loop == JOptionPane.YES_OPTION) {
input=JOptionPane.showInputDialog(null,"Enter a character :");
inputs= input.charAt(0);
if (Character.getType(inputs) == Character.LOWERCASE_LETTER){
JOptionPane.showMessageDialog(null,"Lowercase");
}
else if(Character.getType(inputs) == Character.UPPERCASE_LETTER){
JOptionPane.showMessageDialog(null,"Uppercase");
}
else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL || inputs == '*' ){
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
else if(Character.isDigit(inputs)){
int num = inputs - '0';
JOptionPane.showMessageDialog(null,"The character is a digit.");
JOptionPane.showMessageDialog(null,"The square root of " + inputs + " is " + Math.sqrt(num));
}
loop = JOptionPane.showConfirmDialog(null, "Try again?[Y/N]", "repeat", JOptionPane.YES_NO_OPTION);
if(loop == JOptionPane.NO_OPTION){
JOptionPane.showMessageDialog(null,"Thank You For Using The Program");
}
}
}
}
-
Re: java programming assignment help
Quote:
but what are the different keys that can be called a symbol in java??
Read the API doc for the Character class.
If you have questions about one symbol's type, print out the value returned by the getType() methd and look it up in the table of definitions referred to by any of the static values defined in the Character class.
Quote:
how can i insert the isLetter() for my code
Where and when do you want to test if a character is a letter? insert the test there.
Your code still does not have an ending else statement after the chain of if/else if???
-
Re: java programming assignment help
i want it to lest it from my code in the LowerCase And UpperCase part to my program..
about this
SAMPLE OUTPUT :
Enter a character: string10
Invalid Input. Input a character only.
how will i do this will i use lenght()?? help again please thank you
Code :
import javax.swing.*;
public class aa {
public static void main(String args[]) {
String input= "*";
char inputs;
double x;
int loop=0;
while (loop == JOptionPane.YES_OPTION) {
input=JOptionPane.showInputDialog(null,"Enter a character :");
inputs= input.charAt(0);
if (Character.getType(inputs) == Character.LOWERCASE_LETTER){
JOptionPane.showMessageDialog(null,"Lowercase");
}
else if(Character.getType(inputs) == Character.UPPERCASE_LETTER){
JOptionPane.showMessageDialog(null,"Uppercase");
}
else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL || inputs == '*' ){
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
else if(Character.isDigit(inputs)){
int num = inputs - '0';
JOptionPane.showMessageDialog(null,"The character is a digit.");
JOptionPane.showMessageDialog(null,"The square root of " + inputs + " is " + Math.sqrt(num));
}
else{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
loop = JOptionPane.showConfirmDialog(null, "Try again?[Y/N]", "repeat", JOptionPane.YES_NO_OPTION);
if(loop == JOptionPane.NO_OPTION){
JOptionPane.showMessageDialog(null,"Thank You For Using The Program");
}
}
}
}
-
Re: java programming assignment help
Quote:
how will i do this
Please explain what it is that you want to do.
Please edit your code and format it so it is easier to read. Code within {}s should be indented at least 3 spaces to show logic levels.
-
Re: java programming assignment help
if i will input string10 or any not char size value the program prints out Invalid Input. Input a character only.
also about the isLetter i want it to be Place In The LowerCase And UpperCase
Code :
import javax.swing.*;
public class aa
{
public static void main(String args[])
{
String input= "*";
char inputs;
double x;
int loop=0;
while (loop == JOptionPane.YES_OPTION)
{
input=JOptionPane.showInputDialog(null,"Enter a character :");
inputs= input.charAt(0);
if (Character.getType(inputs) == Character.LOWERCASE_LETTER)
{
JOptionPane.showMessageDialog(null,"Lowercase");
}
else if(Character.getType(inputs) == Character.UPPERCASE_LETTER)
{
JOptionPane.showMessageDialog(null,"Uppercase");
}
else if(Character.getType(inputs) == Character.CURRENCY_SYMBOL || inputs == '*' )
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
else if(Character.isDigit(inputs))
{
int num = inputs - '0';
JOptionPane.showMessageDialog(null,"The character is a digit.");
JOptionPane.showMessageDialog(null,"The square root of " + inputs + " is " + Math.sqrt(num));
}
else
{
JOptionPane.showMessageDialog(null,"The character is a symbol.");
}
loop = JOptionPane.showConfirmDialog(null, "Try again?[Y/N]", "repeat", JOptionPane.YES_NO_OPTION);
if(loop == JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null,"Thank You For Using The Program");
}
}
}
}
-
Re: java programming assignment help
You can test if the user input a single letter by testing the length of the String.
Quote:
also about the isLetter i want it to be Place In The LowerCase And UpperCase
I'm not sure what you are asking here. Do you want to replace the tests for case with a test for letter?
-
Re: java programming assignment help
how will i test the length??and how will it confirm that the input is not a character?
about the isLetter because i want that isLetter can be found to my source code is there a place where i can place it?/