Results 1 to 5 of 5
Thread: Code
- 02-10-2008, 06:46 AM #1
Code
No real point to this thread, just wanted to show off where my baby steps have gotten me thus far :D
/*
* Filename: kthMLab3.java
* Created: 01/30/2008 by Kevin H
* Modified: 02/06/2008 by Kevin H
* Purpose: Display various objects
*/
public class kthMLab3 //start of class kthMLab3
{
public static void main(String[] args) //start of main method
{
xObject();
spacer();
spacer();
diamondObject();
spacer();
spacer();
rocketObject();
} //end of main method
public static void xObject() //start x
{
downarrow();
uparrow();
} //end x
public static void diamondObject() //start diamond
{
xpiece();
uparrow();
middlepiece();
downarrow();
xpiece();
} //end diamond
public static void rocketObject() //start rocket
{
xpiece();
uparrow();
verticallines();
crossline();
rockettail();
rocketexhaust();
} //end rocket
public static void uparrow() //start of uparrow
{
System.out.println(" |||");
System.out.println(" |||||");
System.out.println(" |||||||");
System.out.println(" |||||||||");
System.out.println(" |||||||||||");
System.out.println(" |||||||||||||");
System.out.println(" |||||||||||||||");
System.out.println(" |||||||||||||||||");
System.out.println(" |||||||||||||||||||");
System.out.println(" |||||||||||||||||||||");
System.out.println(" |||||||||||||||||||||||");
System.out.println(" |||||||||||||||||||||||||");
System.out.println(" |||||||||||||||||||||||||||");
System.out.println(" |||||||||||||||||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
} //end of uparrow
public static void downarrow() //start of downarrow
{
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" |||||||||||||||||||||||||||||");
System.out.println(" |||||||||||||||||||||||||||");
System.out.println(" |||||||||||||||||||||||||");
System.out.println(" |||||||||||||||||||||||");
System.out.println(" |||||||||||||||||||||");
System.out.println(" |||||||||||||||||||");
System.out.println(" |||||||||||||||||");
System.out.println(" |||||||||||||||");
System.out.println(" |||||||||||||");
System.out.println(" |||||||||||");
System.out.println(" |||||||||");
System.out.println(" |||||||");
System.out.println(" |||||");
System.out.println(" |||");
} //end of downarrow
public static void crossline() //start of crossline
{
System.out.println(" =============================================");
System.out.println(" =============================================");
System.out.println(" =============================================");
System.out.println(" =============================================");
System.out.println(" =============================================");
System.out.println(" =============================================");
} //end of crossline
public static void verticallines() //start of verticallines
{
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
} //end of verticallines
public static void rocketexhaust() //start of rocketexhaust
{
System.out.println(" |*******************************************|");
System.out.println(" |************************||***************|");
System.out.println(" |************||********| |*************|");
System.out.println(" |**********| |******| |***********||");
System.out.println(" |********| ||****|| |**********|");
System.out.println(" |********| |****| |********|");
System.out.println(" |********| |**| ||******||");
System.out.println(" |******| |||| |******|");
System.out.println(" ||****|| || |****|");
System.out.println(" |****| ||**||");
System.out.println(" |**| |**|");
System.out.println(" |||| |||");
System.out.println(" || |");
} //end of rocketexhaust
public static void middlepiece () //start of middlepiece
{
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println("||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
} //end of middlepiece
public static void rockettail() //start of rockettail
{
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" ||||||||||||||| |||||||||||||||");
System.out.println(" =============================================");
System.out.println(" =============================================");
} //end of rockettail
public static void spacer() //start of spacer
{
System.out.println();
System.out.println();
} //end of spacer
public static void xpiece() //start or xpiece
{
System.out.println(" |");
} //end of xpiece
} //end of class kthMLab3Hey I'm still learning... Thats my story and I'm sticking to it :)
- 02-10-2008, 09:36 AM #2
Very good
Hello dc2acgsr99
I glad that you are making progress. ;) Try to self study loops and if-statements. With that, you can really improve on this code. Search the forums and the internet and ask when you get stuck at Java Forums.
Good luck! :DEyes dwelling into the past are blind to what lies in the future. Step carefully.
- 02-11-2008, 11:46 PM #3
Tim you must have the power to see the future my friend because my question pertains to just that, the "if" statements and so forth. Specifically the code below is strikingly similar to the one posted above with modifications, now everything complies and executes just fine but... I must have the section in red there or it will show an error when the cancel button is pressed, but when it is there the D, X and R do not show their image in the general output window... But to add to it I do not think the "else" statements are being used correctly as no matter what letter I input into the "JOptionPane.showInputDialog" it shows the "Please enter a D, X or R" message, even if it is the right letter and it shows the image... Ideas, views, suggestions, opinions?
Java Code:import javax.swing.JOptionPane; public class kthMiniLab4 //start class { public static void main (String[] args) //start main { progra(); System.exit (0); } //end main public static void progra() //start progra { String response; response = JOptionPane.showInputDialog ( "Type a D for a Diamond, an X for an X and a R for a Rocket." ); [COLOR="Red"] { //cancel if (response == null) JOptionPane.showMessageDialog(null, "Quitter!!"); System.exit (0); } //cancel[/COLOR] { //diamond if (response.equals("D")||(response.equals("d"))) diamondObject(); else JOptionPane.showMessageDialog (null, "Please enter a D, X or R"); } //diamond { //the X if (response.equals("X")||(response.equals("x"))) xObject(); else JOptionPane.showMessageDialog (null, "Please enter a D, X or R"); } //the X { //rocket if (response.equals("R")||(response.equals("r"))) rocketObject(); else JOptionPane.showMessageDialog (null, "Please enter a D, X or R"); } //rocket } //end progra public static void xObject() //start x { downarrow(); uparrow(); } //end x public static void diamondObject() //start diamond { xpiece(); uparrow(); middlepiece(); downarrow(); xpiece(); } //end diamond public static void rocketObject() //start rocket { xpiece(); uparrow(); verticallines(); crossline(); rockettail(); rocketexhaust(); } //end rocket public static void uparrow() //start of uparrow { System.out.println(" |||"); System.out.println(" |||||"); System.out.println(" |||||||"); System.out.println(" |||||||||"); System.out.println(" |||||||||||"); System.out.println(" |||||||||||||"); System.out.println(" |||||||||||||||"); System.out.println(" |||||||||||||||||"); System.out.println(" |||||||||||||||||||"); System.out.println(" |||||||||||||||||||||"); System.out.println(" |||||||||||||||||||||||"); System.out.println(" |||||||||||||||||||||||||"); System.out.println(" |||||||||||||||||||||||||||"); System.out.println(" |||||||||||||||||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); } //end of uparrow public static void downarrow() //start of downarrow { System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" |||||||||||||||||||||||||||||"); System.out.println(" |||||||||||||||||||||||||||"); System.out.println(" |||||||||||||||||||||||||"); System.out.println(" |||||||||||||||||||||||"); System.out.println(" |||||||||||||||||||||"); System.out.println(" |||||||||||||||||||"); System.out.println(" |||||||||||||||||"); System.out.println(" |||||||||||||||"); System.out.println(" |||||||||||||"); System.out.println(" |||||||||||"); System.out.println(" |||||||||"); System.out.println(" |||||||"); System.out.println(" |||||"); System.out.println(" |||"); } //end of downarrow public static void crossline() //start of crossline { System.out.println(" ============================================="); System.out.println(" ============================================="); System.out.println(" ============================================="); System.out.println(" ============================================="); System.out.println(" ============================================="); System.out.println(" ============================================="); } //end of crossline public static void verticallines() //start of verticallines { System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); } //end of verticallines public static void rocketexhaust() //start of rocketexhaust { System.out.println(" |*******************************************|"); System.out.println(" |************************||***************|"); System.out.println(" |************||********| |*************|"); System.out.println(" |**********| |******| |***********||"); System.out.println(" |********| ||****|| |**********|"); System.out.println(" |********| |****| |********|"); System.out.println(" |********| |**| ||******||"); System.out.println(" |******| |||| |******|"); System.out.println(" ||****|| || |****|"); System.out.println(" |****| ||**||"); System.out.println(" |**| |**|"); System.out.println(" |||| |||"); System.out.println(" || |"); } //end of rocketexhaust public static void middlepiece () //start of middlepiece { System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println("||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); } //end of middlepiece public static void rockettail() //start of rockettail { System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ||||||||||||||| |||||||||||||||"); System.out.println(" ============================================="); System.out.println(" ============================================="); } //end of rockettail public static void spacer() //start of spacer { System.out.println(); System.out.println(); } //end of spacer public static void xpiece() //start or xpiece { System.out.println(" |"); } //end xpiece } //end class
Hey I'm still learning... Thats my story and I'm sticking to it :)
- 02-13-2008, 05:37 AM #4
no takers???
Hey I'm still learning... Thats my story and I'm sticking to it :)
- 02-13-2008, 05:45 AM #5
Nested if-statements
Hello dc2acgsr99
Try nesting your if-statements. For example:
Java Code:if (input1){ // Do input 1 } else if (input2){ // Do input 2 } else if (input3) { // Do input 3 } // And so forth
Eyes dwelling into the past are blind to what lies in the future. Step carefully.
Similar Threads
-
Need help with my code.
By stormviper in forum New To JavaReplies: 8Last Post: 11-18-2013, 03:58 PM -
I need help fixing my code.. or non code?
By MrHuggykins in forum New To JavaReplies: 1Last Post: 03-19-2008, 10:12 PM -
Pls some one to help mi wit this code
By _nik_ in forum New To JavaReplies: 3Last Post: 02-10-2008, 02:02 AM -
tic tac toe code
By zoe in forum New To JavaReplies: 1Last Post: 07-23-2007, 04:36 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM
Bookmarks