This is Reservation program full code written in JAVA <from the web>
No Problems are in running process.
I'm required to convert it to C language.
--
1- these are lines that i did not understand it. <could any one explain>
a. private static DataInputStream k = new DataInputStream(System.in);
//what is DataInputStream
b. throws IOException
//what does it do
c. sop
//is it System out print!
d. try {
//what is it
e. Integer.parseInt(k.readLine());
//could any one explain ths line.
f. static void sop(String str) {System.out.print(str);}
g. static void space() {sop("\n\n\n\n\n\n\n\n\n\n\n\n");}
//what is job of these 2 function
2- Can I convert this code to C language? or there are some Lines in this Java code impossible to convert it to C? <Are packages in Java can be converted to C?>
--
import java.io.*;
class Reservation {
private static DataInputStream k = new DataInputStream(System.in);
private static int index=6;
private static String resRom[] = new String[index];
private static int roomNum;
private static String A="Available";
private static String R="Reserved";
public static void main(String[] args)throws IOException {
roomDis();
menu();
}
static void roomDis() {
space();
sop("ROOM #. STATUS\n\n");
roomNum=1;
for(int i=1;i<index;i++) {
resRom[i]=A;
System.out.println(" " +roomNum + "\t " +resRom[i]);
roomNum++;
}
}
static void roomDisOrg() {
space();
sop("ROOM #. STATUS\n\n");
roomNum=1;
for(int i=1;i<index;i++) {
System.out.println(" " +roomNum + "\t " +resRom[i]);
roomNum++;
}
}
static void menu()throws IOException {
try {
sop("\n\nMenu \n [1] - Reserve \n [2] - Cancel Reservation \n [3] - Exit");
sop("\n\n\nEnter Menu: ");
int menu = Integer.parseInt(k.readLine());
switch(menu) {
case 1:
System.out.print("Enter the room #: ");
int rNo = Integer.parseInt(k.readLine());
if(resRom[rNo]==A) {
resRom[rNo]=R;
roomDisOrg();
System.out.println("\n\nRoom number " + rNo + " reserved!");
menu();
}else {
space();
roomDisOrg();
System.out.println("\n\nRoom number " + rNo + " already reserved!");
menu();
}
break;
case 2:
System.out.print("Enter the room #: ");
int rNo1 = Integer.parseInt(k.readLine());
System.out.print("\nCancel this room?[1]-Yes/[2]-No: ");
int ask = Integer.parseInt(k.readLine());
if(ask==1) {
if(resRom[rNo1]==R) {
space();
resRom[rNo1] = A;
roomDisOrg();
System.out.println("\n\nRoom number " + rNo1 + " is now " + A);
menu();
}else {
space();
roomDisOrg();
System.out.println("\n\nRoom number " + rNo1 + " is already " + A);
menu();
}
}else if(ask==2) {
space();
roomDisOrg();
menu();
}else {
sop("Invalid Input...\n");
}
break;
case 3:
System.exit(0);
break;
default:
space();
roomDisOrg();
System.out.println("\n\nInvalid menu!");
menu();
break;
}
}catch(NumberFormatException er) {
space();
roomDisOrg();
System.out.println("\n\nInvalid menu!");
menu();
}
}
static void sop(String str) {
System.out.print(str);
}
static void space() {
sop("\n\n\n\n\n\n\n\n\n\n\n\n");
}
}
HELP please.
& Thanks