Results 1 to 4 of 4
Thread: Make my main program simple
- 02-19-2013, 11:00 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Make my main program simple
Hi,
I am trying to do a hotel system where i have written up this code, however i was wondering if the there was a way to make the main program simple.
So what im trying to do is the code that ‘Views All rooms’ and ‘Adds customer to room’, put them into separate procedures and a menu so When i press ‘A’ is it will do the Add
procedure, and when i press ‘V’ the View procedure.
Below is the code i have written. I would really appreciate if anyone can help me
package reservation;
import java.util.*;
/**
*
* @author alex
*/
public class reservation {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
String roomName;
int roomNum = 0;
String[] hotel = new String[7];
for (int x = 0; x < 6; x++ ) hotel[x] = ""; //initialise
initialise(hotel); //better to initialise in a procedure
while ( roomNum < 6 )
{
System.out.println("Enter room number (0-5) or 6 to stop:" ) ;
roomNum = input.nextInt();
System.out.println("Enter name for room " + roomNum +" :" ) ;
roomName = input.next();
hotel[roomNum] = roomName ;
for (int x = 0; x < 6; x++ )
{
System.out.println("room " + x + " occupied by " + hotel[x]);
}
}
}
private static void initialise( String hotelRef[] ) {
for (int x = 0; x < 6; x++ ) hotelRef[x] = "e";
System.out.println( "initilise ");
Scanner input = new Scanner(System.in);
Room[] myHotel = new Room[4];
myHotel[0] = new Room();
myHotel[1] = new Room();
myHotel[2] = new Room();
myHotel[3] = new Room();
String roomName;
int roomNum = 0;
initialise(myHotel);
while (roomNum < 4) {
for (int x = 0; x < 4; x++ )
if (myHotel[x].mainName.equals("e"))System.out.println("room " + x + " is empty");
System.out.println("Enter room number (0-3) or 4 to stop:"); //error with 4
roomNum = input.nextInt();
System.out.println("Enter name for room " + roomNum + " :");
roomName = input.next();
myHotel[roomNum].mainName = roomName ;
// myHotel[roomNum].setName(roomName);
for (int x = 0; x < 4; x++) {
System.out.println("room " + x + " occupied by " + myHotel[x].mainName);
// System.out.println("room " + x + " occupied by " + myHotel[x].getName());
}
}
}
private static void initialise( Room hotelRef[] ) {
for (int x = 0; x < 4; x++ ) hotelRef[x].mainName = "e";
System.out.println( "initilise ");
}}
-
Re: Make my main program simple
Hello and welcome to the forum!
Please help us help you by editing your post above and surrounding your posted code with [code] [/code] tags. This will allow your code to retain its formatting and hopefully be more readable. Please be sure to use standard and regular indentation, to avoid inadequate use of whitespace (you want to avoid having }} for instance) and avoid over-use of whitespace too.
Best of luck!
- 02-19-2013, 11:52 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Re: Make my main program simple
i hope that is betterJava Code:import java.util.*; public class reservation { public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String roomName; int roomNum = 0; String[] hotel = new String[7]; for (int x = 0; x < 6; x++ ) hotel[x] = ""; //initialise initialise(hotel); //better to initialise in a procedure while ( roomNum < 6 ){ System.out.println("Enter room number (0-5) or 6 to stop:" ) ; roomNum = input.nextInt(); System.out.println("Enter name for room " + roomNum +" :" ) ; roomName = input.next(); hotel[roomNum] = roomName ; for (int x = 0; x < 6; x++ ){ System.out.println("room " + x + " occupied by " + hotel[x]);}}} private static void initialise( String hotelRef[] ) { for (int x = 0; x < 6; x++ ) hotelRef[x] = "e"; System.out.println( "initilise "); Scanner input = new Scanner(System.in); Room[] myHotel = new Room[4]; myHotel[0] = new Room(); myHotel[1] = new Room(); myHotel[2] = new Room(); myHotel[3] = new Room(); String roomName; int roomNum = 0; initialise(myHotel); while (roomNum < 4) { for (int x = 0; x < 4; x++ ) if (myHotel[x].mainName.equals("e"))System.out.println("room " + x + " is empty"); System.out.println("Enter room number (0-3) or 4 to stop:"); //error with 4 roomNum = input.nextInt(); System.out.println("Enter name for room " + roomNum + " :"); roomName = input.next(); myHotel[roomNum].mainName = roomName ; // myHotel[roomNum].setName(roomName); for (int x = 0; x < 4; x++) { System.out.println("room " + x + " occupied by " + myHotel[x].mainName); // System.out.println("room " + x + " occupied by " + myHotel[x].getName());}}} private static void initialise( Room hotelRef[] ) { for (int x = 0; x < 4; x++ ) hotelRef[x].mainName = "e"; System.out.println( "initilise ");}}
-
Re: Make my main program simple
Surely you can see that it isn't. All your code usually isn't full left justified is it? Surely you use indentations wisely, right? Please, again, edit your *original* post since we only need to see your code once, and please, again, only post well formatted code with regular and consistent indentation to begin with. Again if we can easily read and understand your code we can more easily help you. If we can't read it, well, then we're all out of luck.
Similar Threads
-
Could not find the main class: main. Program will exit
By Bodachi in forum EclipseReplies: 11Last Post: 10-30-2012, 09:28 AM -
How i can make a thread to run parallel form the main program?
By gyijhbk in forum New To JavaReplies: 1Last Post: 06-05-2012, 04:31 PM -
Help, cannot make my simple program an executable jar
By leoxy520 in forum AWT / SwingReplies: 11Last Post: 01-25-2012, 03:06 PM -
can i make a program to make keyboard and mouse idle or not responding for 10 second
By 3ammary in forum Advanced JavaReplies: 4Last Post: 07-23-2011, 08:08 PM -
Simple program compiles but main class is not found-- not sure why
By damong in forum New To JavaReplies: 4Last Post: 01-01-2009, 03:58 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks