6 Replies - 405 Views - Last Post: 01 August 2013 - 09:19 PM Rate Topic: -----

#1 streek405  Icon User is offline

  • D.I.C Addict

Reputation: 12
  • View blog
  • Posts: 592
  • Joined: 10-March 13

improve my class and object

Posted 30 July 2013 - 09:53 PM

I just finished making this code using an object and class, but I want to add more stuff to it, anything! It seems to dull for me and simple (since Im still a noob). Could anyone give me some suggestions to make this better or at least add stuff to it. Sorry if this seems like a vague request. Here is my code:

// this program will ask the user what they would like to do when they start up their xbox  
	
	import java.util.Scanner;

   public class XBOX360{
   
      public static void main(String[] args){
      
         Scanner input = new Scanner(System.in);
         String g = "games";
         String m = "media";
         String s = "settings";
      
      //create object
         Dashboard dash = new Dashboard();	
      
      //ask user what they would like to choose
         System.out.println("Hello, would you like to play games, watch media, or go to settings? Please enter games, media, or settings: ");
         String answer = input.next();
      
         if (answer.equals(g)){
         //turn on power
            dash.powerOn();
				System.out.println("The XBOX is on and starting up games");
            dash.showGames();
         }
         
         else if (answer.equals(m)){
            dash.powerOn();
				System.out.println("The XBOX is on and starting up media");	
            dash.showMedia();            
         }
         
         else if (answer.equals(s)){
				System.out.println("The XBOX is on and starting up settings");
            dash.powerOn();
            dash.showSettings();            	
         }
			
         else{
			dash.powerOff();
            System.out.println("Invalid entry");
         }
      }
   }

   class Dashboard{
   
      boolean games = false;
      boolean media = false;
      boolean settings = false;
      boolean power = false; // off by default
   
   //constructor 
      Dashboard(){
      }
   
   //turn on and off power
      public void powerOn(){
         power = true;
      }	
   
      public void powerOff(){
         power = false;
      }
   
   //make pages available
   
      public void showGames(){
         games = true;
			System.out.println("Here's the list of games");
      }
   
      public void hideGames(){
         games = false;
      }
   
      public void showMedia(){
         media = true;
			System.out.println("Here's the list of crappy movies");
      }
   
      public void hideMedia(){
         media = false;
      }
   
      public void showSettings(){
         settings = true;
			System.out.println("Bringing up settings...");
      }
   
      public void hideSettings(){
         settings = false;
      }
   }





PS my code works fine, no errors :)/>/>/>

EDIT: Also, is there a way to actually display to the user that the game/settings/media is off or on?

This post has been edited by streek405: 30 July 2013 - 09:55 PM


Is This A Good Question/Topic? 0
  • +

Replies To: improve my class and object

#2 ConciselyVerbose  Icon User is offline

  • D.I.C Regular

Reputation: 90
  • View blog
  • Posts: 315
  • Joined: 05-July 13

Re: improve my class and object

Posted 30 July 2013 - 09:56 PM

I don't really have suggestions for what to add, but I would think about using String.equalsIgnoreCase for the inputs. It is more user friendly for it to work intuitively and let them capitalize it,
Was This Post Helpful? 2
  • +
  • -

#3 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4399
  • View blog
  • Posts: 12,255
  • Joined: 18-April 07

Re: improve my class and object

Posted 30 July 2013 - 10:05 PM

A few things you can add or change...

1) Change it so that if I enter an invalid character, the XBOX reprompts me. Perhaps I accidentally typed the wrong character.
2) Build a menu function to display and handle the menu choices. In other words, refactor it. I shouldn't have a menu and its options all tied up in main.
3) Not sure what it means to "hide settings" or "hide games". If this means to remove what is on screen or something then write the code to do that.
4) Maybe give the dashboard some kind of visual interface? This will help you learn something like Swing.

Just a few ideas. I am not sure exactly what you are building here but a few of these might help expand it. :)
Was This Post Helpful? 0
  • +
  • -

#4 streek405  Icon User is offline

  • D.I.C Addict

Reputation: 12
  • View blog
  • Posts: 592
  • Joined: 10-March 13

Re: improve my class and object

Posted 31 July 2013 - 01:10 PM

View PostConciselyVerbose, on 30 July 2013 - 09:56 PM, said:

I don't really have suggestions for what to add, but I would think about using String.equalsIgnoreCase for the inputs. It is more user friendly for it to work intuitively and let them capitalize it,


Thanks. I've been meaning to do that ignoreCase thing for a while now, but forgot how to..until now :)

View PostMartyr2, on 30 July 2013 - 10:05 PM, said:

A few things you can add or change...

1) Change it so that if I enter an invalid character, the XBOX reprompts me. Perhaps I accidentally typed the wrong character.
2) Build a menu function to display and handle the menu choices. In other words, refactor it. I shouldn't have a menu and its options all tied up in main.
3) Not sure what it means to "hide settings" or "hide games". If this means to remove what is on screen or something then write the code to do that.
4) Maybe give the dashboard some kind of visual interface? This will help you learn something like Swing.

Just a few ideas. I am not sure exactly what you are building here but a few of these might help expand it. :)/>



Thanks! That GUI thing is a pretty good idea.
Was This Post Helpful? 0
  • +
  • -

#5 schutzzz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 138
  • View blog
  • Posts: 338
  • Joined: 22-April 13

Re: improve my class and object

Posted 01 August 2013 - 05:46 AM

Quote

Thanks! That GUI thing is a pretty good idea.


If you'd like I included an example of how it could be done with a GUI. Hopefully you could take it as a learning attempt for it :)

Spoiler

This post has been edited by schutzzz: 01 August 2013 - 06:27 AM

Was This Post Helpful? 2
  • +
  • -

#6 streek405  Icon User is offline

  • D.I.C Addict

Reputation: 12
  • View blog
  • Posts: 592
  • Joined: 10-March 13

Re: improve my class and object

Posted 01 August 2013 - 07:02 PM

View Postschutzzz, on 01 August 2013 - 05:46 AM, said:

Quote

Thanks! That GUI thing is a pretty good idea.


If you'd like I included an example of how it could be done with a GUI. Hopefully you could take it as a learning attempt for it :)/>

Spoiler

WOW! Thanks! Although I still dont understand GUI's that much, it is so far the main topic that I am interested in learning. I am just a few chapters away from reviewing them and I will for sure look back at your code and try to understand it. Thank you very much again!!! :D
Was This Post Helpful? 0
  • +
  • -

#7 salazar  Icon User is offline

  • D.I.C Addict

Reputation: 87
  • View blog
  • Posts: 539
  • Joined: 26-June 13

Re: improve my class and object

Posted 01 August 2013 - 09:19 PM

You could try turning the game, media, settings variables into their own classes. :whistling:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1