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 10-13-09   #1 (permalink)
Commodore 64
 
[Teh Root]'s Avatar
 
intel nvidia

Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228

Rep: 89 [Teh Root] is acknowledged by some
Unique Rep: 72
Trader Rating: 9
Default Help with Java programs.

Hey guys, I;m currently taking a course in Java and I don't remember how to do this.

1. Write a swtich statement that follows the menu given below.
Enter A to print the name Alan
Enter B to print the name Bob
Enter C to print the name Carl
Enter D to print the name David
If anything else if entered print "Invalid Choice"

How would I do that?

And for number 2.

2.Write a program that will aloow a user to input an integer between 1 and 25(inclusive) and then print a line of asteriks (*), using a for loop, that uses the input value as the length of the line..

Example 1
Input: Please enter and integer from 1 to 25: 5
Output: *****

Example 2
Input: Please enter an integer from 1 to 25: 7
Output: *******

Help guys? This is in Java using Eclipse.
__________________
Quote:
Originally Posted by jaibot
with more nanometers we can put more voltage through our chips to make them perform better
Quote:
Originally Posted by Contagion
My dad would've beaten me with a toaster.
I would have deserved it too.

Xfire : gormogon : [OCN] Teh Root
SteamID: [OCN] Teh Root

System: Black Streak
CPU
Intel Q6600 @ to 3.33(1.36v)
Motherboard
Asus P5N-D[Vdroop Pencil Mod]
Memory
G.SKILL 4GB (2 x 2GB) DDR2 800
Graphics Card
[2 BFG 9800 GTX+ in SLI mode]
Hard Drive
Dual 750GB SS Hard Drives in RAID 0
Sound Card
Creative Labs SB X-FI Titanium Fatal1ty Pro
Power Supply
950W Coolmax "Green Power"
Case
Ultra M923 "Full" Tower
CPU cooling
ZEROtherm Butterfly BTF90
GPU cooling
Generic BFG Heatsink
OS
Vista Ultimate x64
Monitor
Acer Black 22" 3ms DVI Widescreen
[Teh Root] is offline   Reply With Quote
Old 10-13-09   #2 (permalink)
.
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: Virginia
Posts: 3,589

Trader Rating: 4
Default

It would be helpful if you posted what you have so far. That way no one is actually doing this assignment for you. This is fairly simple stuff, so if you post what you've got so far, it won't be hard to help walk you through it.
__________________
Imaging with Windows PE
Please keep the OCN Terms of Service in mind when posting.

System: My System
CPU
Q6700
Motherboard
Gigabyte p35-DS4
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Apogee GTZ
GPU cooling
Stock
OS
Vista Ultimate x64 SP1, Xubuntu 8.10, Windows 7
Monitor
Hanns-G 28" & Dell 19" widescreen
BiG O is offline Overclocked Account   Reply With Quote
Old 10-13-09   #3 (permalink)
Commodore 64
 
[Teh Root]'s Avatar
 
intel nvidia

Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228

Rep: 89 [Teh Root] is acknowledged by some
Unique Rep: 72
Trader Rating: 9
Default

How do I create a string in Eclipse?
__________________
Quote:
Originally Posted by jaibot
with more nanometers we can put more voltage through our chips to make them perform better
Quote:
Originally Posted by Contagion
My dad would've beaten me with a toaster.
I would have deserved it too.

Xfire : gormogon : [OCN] Teh Root
SteamID: [OCN] Teh Root

System: Black Streak
CPU
Intel Q6600 @ to 3.33(1.36v)
Motherboard
Asus P5N-D[Vdroop Pencil Mod]
Memory
G.SKILL 4GB (2 x 2GB) DDR2 800
Graphics Card
[2 BFG 9800 GTX+ in SLI mode]
Hard Drive
Dual 750GB SS Hard Drives in RAID 0
Sound Card
Creative Labs SB X-FI Titanium Fatal1ty Pro
Power Supply
950W Coolmax "Green Power"
Case
Ultra M923 "Full" Tower
CPU cooling
ZEROtherm Butterfly BTF90
GPU cooling
Generic BFG Heatsink
OS
Vista Ultimate x64
Monitor
Acer Black 22" 3ms DVI Widescreen
[Teh Root] is offline   Reply With Quote
Old 10-13-09   #4 (permalink)
.
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: Virginia
Posts: 3,589

Trader Rating: 4
Default

Quote:
Originally Posted by [Teh Root] View Post
How do I create a string in Eclipse?
Creating a string is not based on what program you're using. It's simply java.

Code:
String str = new String("This is a String");
__________________
Imaging with Windows PE
Please keep the OCN Terms of Service in mind when posting.

System: My System
CPU
Q6700
Motherboard
Gigabyte p35-DS4
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Apogee GTZ
GPU cooling
Stock
OS
Vista Ultimate x64 SP1, Xubuntu 8.10, Windows 7
Monitor
Hanns-G 28" & Dell 19" widescreen
BiG O is offline Overclocked Account   Reply With Quote
Old 10-13-09   #5 (permalink)
Commodore 64
 
[Teh Root]'s Avatar
 
intel nvidia

Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228

Rep: 89 [Teh Root] is acknowledged by some
Unique Rep: 72
Trader Rating: 9
Default

but I have this.... for the first one...

import java.util.*;
public class names {
static Scanner Scanner = new Scanner(System.in);

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Enter A to print the name Alan: ");
string names = Scanner.nextString();
}

}

To enter a character is it string or a char?
__________________
Quote:
Originally Posted by jaibot
with more nanometers we can put more voltage through our chips to make them perform better
Quote:
Originally Posted by Contagion
My dad would've beaten me with a toaster.
I would have deserved it too.

Xfire : gormogon : [OCN] Teh Root
SteamID: [OCN] Teh Root

System: Black Streak
CPU
Intel Q6600 @ to 3.33(1.36v)
Motherboard
Asus P5N-D[Vdroop Pencil Mod]
Memory
G.SKILL 4GB (2 x 2GB) DDR2 800
Graphics Card
[2 BFG 9800 GTX+ in SLI mode]
Hard Drive
Dual 750GB SS Hard Drives in RAID 0
Sound Card
Creative Labs SB X-FI Titanium Fatal1ty Pro
Power Supply
950W Coolmax "Green Power"
Case
Ultra M923 "Full" Tower
CPU cooling
ZEROtherm Butterfly BTF90
GPU cooling
Generic BFG Heatsink
OS
Vista Ultimate x64
Monitor
Acer Black 22" 3ms DVI Widescreen
[Teh Root] is offline   Reply With Quote
Old 10-13-09   #6 (permalink)
Commodore 64
 
[Teh Root]'s Avatar
 
intel nvidia

Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228

Rep: 89 [Teh Root] is acknowledged by some
Unique Rep: 72
Trader Rating: 9
Default

I only need to actually write the switch statement for the first one, the second one I have to write.
__________________
Quote:
Originally Posted by jaibot
with more nanometers we can put more voltage through our chips to make them perform better
Quote:
Originally Posted by Contagion
My dad would've beaten me with a toaster.
I would have deserved it too.

Xfire : gormogon : [OCN] Teh Root
SteamID: [OCN] Teh Root

System: Black Streak
CPU
Intel Q6600 @ to 3.33(1.36v)
Motherboard
Asus P5N-D[Vdroop Pencil Mod]
Memory
G.SKILL 4GB (2 x 2GB) DDR2 800
Graphics Card
[2 BFG 9800 GTX+ in SLI mode]
Hard Drive
Dual 750GB SS Hard Drives in RAID 0
Sound Card
Creative Labs SB X-FI Titanium Fatal1ty Pro
Power Supply
950W Coolmax "Green Power"
Case
Ultra M923 "Full" Tower
CPU cooling
ZEROtherm Butterfly BTF90
GPU cooling
Generic BFG Heatsink
OS
Vista Ultimate x64
Monitor
Acer Black 22" 3ms DVI Widescreen
[Teh Root] is offline   Reply With Quote
Old 10-13-09   #7 (permalink)
Overclocker
 
1337guy's Avatar
 
intel nvidia

Join Date: Aug 2007
Location: *Cape Town* FTW!
Posts: 1,746

Rep: 143 1337guy is acknowledged by many1337guy is acknowledged by many
Unique Rep: 110
Trader Rating: 0
Default

Buddy this is easy stuff, would help you but im on my cellphone now. Goodluck learning the java language! Its pretty neat,i just wrote my IT programming finals a few days ago (now that was crap i tell you!).
Cheers
__________________

Don't listen to crap! Listen to real music. Listen to TRANCE!!
I WANT TO FOLD FOR OCN BUT MY CELERY JUST AINT CUTTING IT!
Best OCN flame pics!
Best game ever!
...┌∩┐(◣_◢)┌∩┐...

System: T3H FA1LB0X 1S FA1L!! :'(
CPU
prescott celery D @ 3.20ghz
Memory
1GB-DDR400
Graphics Card
6600GT stock @ 500/900
Hard Drive
80GB hitachi deskstar || 1TB 7200.12
Sound Card
onboard
Power Supply
CM Silent Power Pro 600w Modular || 40amps single 12v
CPU cooling
Stock
GPU cooling
Stock
OS
XP Pro SP3 32bit
Monitor
17' crt 1280x1024
1337guy is offline 1337guy's Gallery   Reply With Quote
Old 10-13-09   #8 (permalink)
The CanAsian
 
UberN00B's Avatar
 
intel ati

Join Date: Jan 2005
Posts: 5,811

FAQs Submitted: 4
Folding Team Rank: 1245
Hardware Reviews: 8
Trader Rating: 28
Default

Quote:
Originally Posted by [Teh Root] View Post
Hey guys, I;m currently taking a course in Java and I don't remember how to do this.

1. Write a swtich statement that follows the menu given below.
Enter A to print the name Alan
Enter B to print the name Bob
Enter C to print the name Carl
Enter D to print the name David
If anything else if entered print "Invalid Choice"

How would I do that?

And for number 2.

2.Write a program that will aloow a user to input an integer between 1 and 25(inclusive) and then print a line of asteriks (*), using a for loop, that uses the input value as the length of the line..

Example 1
Input: Please enter and integer from 1 to 25: 5
Output: *****

Example 2
Input: Please enter an integer from 1 to 25: 7
Output: *******

Help guys? This is in Java using Eclipse.
its been awhile since ive touched on java, so someone fix my syntax if im wrong.. ill only do the first one for you.

string letter = joptionpane.showInputDialog("Input whatever letter");
string lower = letter.toLowerCase();

if (lower==a)
System.out.println("Alan");
else if (lower == b)
System.out.println("Bob");

thats how you do the first one. relatively simple stuff.

the second one is just a loop where the user enters a number (15 for example) and you get that number using integer number = JOptionPane.showInputDialog("Whatever here");
then you use the variable "number" into a loop statement. You also need to create a counter (i use variable i) so that its like..

while(i<=number)
System.out.print("*") or something.

hope that helps.
__________________
On a budget Build? See my FAQ!!
http://www.overclock.net/faqs/36946-...-system-i.html

UPDATED MARCH 5th 07'

NEW! Overclock.net Ping boosted CS:S Server - overclock.nuclearfallout.net:27015

System: MAN PARTS
CPU
Intel Q6600 3.1ghz
Motherboard
DFI Blood Iron
Memory
4GB DDR2-1000 Mushkin Redlines
Graphics Card
HD 4850 1GB
Hard Drive
2x 250GB Seagate 7200.10 RAID0
Sound Card
XTremeMusic
Power Supply
Silverstone 500w
Case
Coolermaster HAF932
CPU cooling
Thermalright Ultra-120 Extreme *LAPPED*
GPU cooling
Thermalright HR-03 GT
OS
Windows XP / Vista Dual Boot
Monitor
20" LG Widescreen

Last edited by UberN00B : 10-13-09 at 06:41 PM
UberN00B is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Old 10-13-09   #9 (permalink)
Commodore 64
 
[Teh Root]'s Avatar
 
intel nvidia

Join Date: Mar 2009
Location: The Capital Wasteland
Posts: 2,228

Rep: 89 [Teh Root] is acknowledged by some
Unique Rep: 72
Trader Rating: 9
Default

I suck at programming :P I'm into computer hardware design.
__________________
Quote:
Originally Posted by jaibot
with more nanometers we can put more voltage through our chips to make them perform better
Quote:
Originally Posted by Contagion
My dad would've beaten me with a toaster.
I would have deserved it too.

Xfire : gormogon : [OCN] Teh Root
SteamID: [OCN] Teh Root

System: Black Streak
CPU
Intel Q6600 @ to 3.33(1.36v)
Motherboard
Asus P5N-D[Vdroop Pencil Mod]
Memory
G.SKILL 4GB (2 x 2GB) DDR2 800
Graphics Card
[2 BFG 9800 GTX+ in SLI mode]
Hard Drive
Dual 750GB SS Hard Drives in RAID 0
Sound Card
Creative Labs SB X-FI Titanium Fatal1ty Pro
Power Supply
950W Coolmax "Green Power"
Case
Ultra M923 "Full" Tower
CPU cooling
ZEROtherm Butterfly BTF90
GPU cooling
Generic BFG Heatsink
OS
Vista Ultimate x64
Monitor
Acer Black 22" 3ms DVI Widescreen
[Teh Root] is offline   Reply With Quote
Old 10-13-09   #10 (permalink)
.
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: Virginia
Posts: 3,589

Trader Rating: 4
Default

Quote:
Originally Posted by UberN00B View Post
its been awhile since ive touched on java, so someone fix my syntax if im wrong.. ill only do the first one for you.

string letter = joptionpane.showInputDialog("Input whatever letter");
string lower = letter.toLowerCase();

if (lower==a)
System.out.println("Alan");
else if (lower == b)
System.out.println("Bob");

thats how you do the first one. relatively simple stuff.

the second one is just a loop where the user enters a number (15 for example) and you get that number using integer number = JOptionPane.showInputDialog("Whatever here");
then you use the variable "number" into a loop statement. You also need to create a counter (i use variable i) so that its like..

while(i<=number)
System.out.print("*") or something.

hope that helps.
There's a lot wrong with this one. You need to pay more attention to capitalization, OP. Also, you don't use == for strings, you use .equals().

Quote:
Originally Posted by [Teh Root] View Post
but I have this.... for the first one...

import java.util.*;
public class names {
static Scanner Scanner = new Scanner(System.in);

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Enter A to print the name Alan: ");
string names = Scanner.nextString();
}

}

To enter a character is it string or a char?
Code:
import java.util.*;
public class names {
	static Scanner scanner = new Scanner(System.in);

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.print("Enter A to print the name Alan: ");
		String names = scanner.nextString();
                if (names.equals("A") || names.equals("a"){
                      System.out.println("Alan");
                }

	}

}
If fixed that one section for you.
__________________
Imaging with Windows PE
Please keep the OCN Terms of Service in mind when posting.

System: My System
CPU
Q6700
Motherboard
Gigabyte p35-DS4
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Apogee GTZ
GPU cooling
Stock
OS
Vista Ultimate x64 SP1, Xubuntu 8.10, Windows 7
Monitor
Hanns-G 28" & Dell 19" widescreen

Last edited by BiG O : 10-13-09 at 07:14 PM
BiG O is offline Overclocked Account   Reply With Quote
Reply


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



All times are GMT -5. The time now is 08:09 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

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