Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 09-05-06   #1 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,470

FAQs Submitted: 7
Folding Team Rank: 390
Trader Rating: 0
Default Help with a Java program

OK well I'm writing this program for school. Its one that a user enters a class name then enters the grades, then finds the total for each letter grade then the total grades entered , and then does all that again and compares the two grade histograms to see if they are equal.

The Prof. already gave us the javadoc for the class. My first problem is in one of the methods, trying to convert a instance variable of type char to uppercase, but the string class method .toUpperCase does not work(since its type char). So is there another way to do this? Like with type casting or the Wrapper classes?

Thanks for any help.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn

Try out the latest Programming Challenge
Quote:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

CPU-Z Validation
@ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15


Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64
Monitor
Acer AL2216W 22" WS LCD
dangerousHobo is offline I fold for Overclock.net Overclocked Account dangerousHobo's Gallery   Reply With Quote
Old 09-05-06   #2 (permalink)
Programmer
 
intel nvidia

Join Date: Jul 2006
Posts: 194

Rep: 11 mjoc13 Unknown
Unique Rep: 10
Trader Rating: 5
Default

Quote:
Originally Posted by dangerousHobo
OK well I'm writing this program for school. Its one that a user enters a class name then enters the grades, then finds the total for each letter grade then the total grades entered , and then does all that again and compares the two grade histograms to see if they are equal.

The Prof. already gave us the javadoc for the class. My first problem is in one of the methods, trying to convert a instance variable of type char to uppercase, but the string class method .toUpperCase does not work(since its type char). So is there another way to do this? Like with type casting or the Wrapper classes?

Thanks for any help.
Well it's not the prettiest coding but if you are determined to use the toUpperCase() then you can write something like this.

public char convert(char lowerChar) {
String temp = "" + lowerChar;
temp = temp.toUpperCase();

return temp.charAt(0);
}

OR

public char convert(char lowerChar) {
lowerChar -= 32;
return lowerChar;
}

Since the difference b/w ascii 'a' and ascii 'A' is 32.

hope it helps.
__________________
Relax and enjoy life!

System: My System
CPU
C2D e6400
Motherboard
eVga 680i - T1
Memory
2x1GB Gskill HZ
Graphics Card
eVga 8800 gts sc 320
Hard Drive
wd 320 sataII, WD 250 PATA
Sound Card
OB
Power Supply
Corsair HX620W
Case
Coolmaster Elite
OS
Win XP pro sp2
Monitor
Sammy 19 ws LCD

Last edited by mjoc13 : 09-05-06 at 10:13 AM.
mjoc13 is offline   Reply With Quote
Old 09-05-06   #3 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,470

FAQs Submitted: 7
Folding Team Rank: 390
Trader Rating: 0
Default

Quote:
Originally Posted by mjoc13
Well it's not the prettiest coding but if you are determined to use the toUpperCase() then you can write something like this.

public char convert(char lowerChar) {
String temp = "" + lowerChar;
temp = temp.toUpperCase();

return temp.charAt(0);
}

OR

public char convert(char lowerChar) {
lowerChar -= 32;
return lowerChar;
}

Since the difference b/w ascii 'a' and ascii 'A' is 32.

hope it helps.
Thanks mate. I think I'm just going to do an OR statement in the if question to cover both 'a' and 'A'.
Thank you for the help though. I just want to keep the instance variable as type char and not mess with a temporary string for it.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn

Try out the latest Programming Challenge
Quote:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

CPU-Z Validation
@ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15


Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64
Monitor
Acer AL2216W 22" WS LCD
dangerousHobo is offline I fold for Overclock.net Overclocked Account dangerousHobo's Gallery   Reply With Quote
Old 09-05-06   #4 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,975
Blog Entries: 1

Rep: 564 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 338
FAQs Submitted: 6
Trader Rating: 5
Default

if you want it in one line
yourchar = (((new String(yourchar)).toUpperCase()).toCharArray())[0];

or

yourchar = ((new String(yourchar)).toUppercase()).charAt(0);
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw

Last edited by rabidgnome229 : 09-05-06 at 02:36 PM.
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 09-05-06   #5 (permalink)
Programmer
 
intel nvidia

Join Date: Jul 2006
Posts: 194

Rep: 11 mjoc13 Unknown
Unique Rep: 10
Trader Rating: 5
Default

char grade = 'a';
... work...
grade -= 32; //convert to upperCase

If you know your always dealing with lowercase then just subtract 32 from the char and the ascii will be upercase. No nested if's or type casting needed.
__________________
Relax and enjoy life!

System: My System
CPU
C2D e6400
Motherboard
eVga 680i - T1
Memory
2x1GB Gskill HZ
Graphics Card
eVga 8800 gts sc 320
Hard Drive
wd 320 sataII, WD 250 PATA
Sound Card
OB
Power Supply
Corsair HX620W
Case
Coolmaster Elite
OS
Win XP pro sp2
Monitor
Sammy 19 ws LCD
mjoc13 is offline   Reply With Quote
Old 09-05-06   #6 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,975
Blog Entries: 1

Rep: 564 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 338
FAQs Submitted: 6
Trader Rating: 5
Default

that only works if you know you have a lowercase letter. if you start with uppercase that method will mess the data up
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 09-05-06   #7 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,470

FAQs Submitted: 7
Folding Team Rank: 390
Trader Rating: 0
Default

its a mixer of upper and lower case letters. I just wanted them all in uppercase to simplify the if statement.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn

Try out the latest Programming Challenge
Quote:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

CPU-Z Validation
@ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15


Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64
Monitor
Acer AL2216W 22" WS LCD
dangerousHobo is offline I fold for Overclock.net Overclocked Account dangerousHobo's Gallery   Reply With Quote
Old 09-05-06   #8 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,470

FAQs Submitted: 7
Folding Team Rank: 390
Trader Rating: 0
Default

well I've ran into yet another problem. Seems like over the summer I've really forgotten some stuff.

Problem is I've got an infinite loop.
Code:
public String toString()
	{
		String temp = "A ";
		int star = 0, largest = 0;
		for(int i=0; i<gradeArray.length; i++)
			if(largest < gradeArray[i])
				largest = gradeArray[i];
		
		for(int s=0; s < gradeArray.length; s++)
		{
			while(star != this.gradeArray[s])
			{
				temp = temp + "*";
				star++;
			}
			while(star < largest)
				temp = temp + " ";
			temp =temp + " " + gradeArray[s] + "\n";
			
			if(s == 0)
				temp = temp + "B ";
			else if(s == 1)
				temp = temp + "C ";
			else if (s == 2)
				temp = temp + "D ";
			else if(s == 3)
				temp = temp + "F ";
			
			star = 0;
		}
		
		temp = temp + "\n" + getTotalGrades();
		return temp;
	}

public int getTotalGrades()
	{
		int total=0;
		for(int i=0;i < gradeArray.length; i++)
			total = total + gradeArray[i];
		return total;
	}
gradeArray[] has 5 locations. One for each letter grade.
The first method is just to print out the results like so: (say gradeArray[0] = 2 & gradeArray[1] = 1)

A ** 2
B * 1
etc.
can anyone spot the problem?
Thanks
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn

Try out the latest Programming Challenge
Quote:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

CPU-Z Validation
@ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15


Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64
Monitor
Acer AL2216W 22" WS LCD

Last edited by dangerousHobo : 09-05-06 at 09:11 PM.
dangerousHobo is offline I fold for Overclock.net Overclocked Account dangerousHobo's Gallery   Reply With Quote
Old 09-05-06   #9 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,975
Blog Entries: 1

Rep: 564 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 338
FAQs Submitted: 6
Trader Rating: 5
Default

Code:
while(star < largest)
		temp = temp + " ";
star never gets incremented, so it is always less than largest
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 09-05-06   #10 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,470

FAQs Submitted: 7
Folding Team Rank: 390
Trader Rating: 0
Default

Quote:
Originally Posted by rabidgnome229
Code:
while(star < largest)
		temp = temp + " ";
star never gets incremented, so it is always less than largest
I cannot believe I overlooked that
Thank you have much rabidgnome.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn

Try out the latest Programming Challenge
Quote:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

CPU-Z Validation
@ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15


Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64
Monitor
Acer AL2216W 22" WS LCD
dangerousHobo is offline I fold for Overclock.net Overclocked Account dangerousHobo's Gallery   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 01:10 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.34691 seconds with 8 queries