Still need help

iv been trying to do it for hours

Page 1 of 1

1 Replies - 919 Views - Last Post: 26 October 2009 - 03:24 PM Rate Topic: -----

#1 Andrew_ahmad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-October 09

Still need help

Post icon  Posted 26 October 2009 - 03:02 PM

I have re posted my topic because im still stuck and i dont think anyones looking at my old post. I am really stuck with this, i am a maths student and one of my modules is programing, which i have never done in my life only 6 hours in the last 3 weeks, now ive been given homework and really cant do it, so you know i am trying i will post at the bottom how much i have done thank you.

I have to write a program that reads a string of letters from the english language and of at least 5 characters then converts it to uppercase and

1. prints the string in uppercase
2. prints the unicodes (as integer numbers) for each of the first 5 characters in the string
3. encode the first 5 characters of the string following the process described below
4. prints the resulting integer number.

* convert each letter into a number between 0 and 25 by replacing each letter by its unicode and then subtract from such code(seen as an integer number) the unicode for the letter A

*e.g. BUTS becomes 1,20,19, and 18.

encode the letters by: 1x26+20=46 46x26+19=1215 1215x26+18=31608
so the resulting integer for BUTS is 31608

Please help me the only thing i can do from this is take a string and print it in uppercase. I have only been programing for 3 weeks and im starting to get lost thank you
import java.io.*;

class homework{
	public static void main(String[]args){
	
	System.out.print("Type in the given string please: ");
	
	String five = new String ( input.next());
	int j = five;
	
	
	System.out.println("The string in uppercase is " + five.toUpperCase());
	System.out.println("The Unicodes are: " + j);
	System.out.println("After encoding the first 5 characters the integer is: ");

	}
}


this is all i can do i am completly lost with encoding it, i also dont know if this works because when i try to compile it says error for input.next like it doesnt recognise i.

if anyone could help i would be most greatfull, thank you again.

This post has been edited by Andrew_ahmad: 26 October 2009 - 03:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Still need help

#2 TriggaMike   User is offline

  • Using up all your 1's and 0's
  • member icon

Reputation: 85
  • View blog
  • Posts: 1,103
  • Joined: 26-September 08

Re: Still need help

Posted 26 October 2009 - 03:24 PM

Few Questions/Suggestions that may help direct you:

1. Where is input coming from? Maybe you should think about making a scanner?

Scanner input = new Scanner(System.in);


2. Why are you trying to cast a String to an int? You can't do that because a String is an object and an int is a primitive data type. If you are trying to get the code values for letters you will need to do it one at a time, likely using the charAt() method. Something like the following:

char buffer;
int j;

buffer = five.charAt(0);
int j = (int) buffer;


3. I suggest you take a closer look into object oriented programming techniques. I think knowing the difference between an object and a primitive data type.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1