How do i use the value from my main class to my other class? - netbeans

So this is my main class
public class Main_Page {
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader (isr);
String type;
String ticnum;
int number;
int i=1;
int choice =0;
double distance;
double total=0;
double payment=0;
public static void main(String[] args) throws Exception{
Main_Page m=new Main_Page();
m.doMenu();
m.doBus();
m.doTrain();
}
public void doMenu() throws Exception {
do
{
System.out.println("***WELCOME***");
System.out.println("What ticket do you want to purchase?");
System.out.println("(1) Bus " + "\n(2) Train" + "\n(3) Exit");
System.out.println("Please enter your choice:");
choice=Integer.parseInt(br.readLine());
switch(choice)
{
case 1: doBus();
break;
case 2: doTrain();
break;
case 3:
Receipt re=new Receipt();
ReceiptMain rm=new ReceiptMain();
rm.setReceipt(re);
rm.getReceipt();
rm.getReceipt().print();
default: System.out.println("Invalid choice. Please try again");
}
}while(choice<=2);
}
public void doBus()throws Exception {
type="Bus";
System.out.println("Please enter distance(km):");
distance=Integer.parseInt(br.readLine());
total=distance*0.5;
payment+=total;
number+=i;
System.out.println("Total payment is:RM" +payment);
ticnum="B";
}
public void doTrain() throws Exception{
type="Train";
System.out.println("Please enter distance(km):");
distance=Integer.parseInt(br.readLine());
total=distance*0.8;
payment+=total;
number+=i;
ticnum="T";
}
}
And this is my other class
public class Receipt extends Main_Page {
public void print(){
Main_Page mp=new Main_Page();
Date d=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
System.out.println("******RECEIPT******");
System.out.println(d);
System.out.println("[Type] [Number] [Price]");
System.out.println(mp.type + " " + mp.number + " "
+ " " + mp.payment);
}
}
The problem that I'm having right now is, I want to use the values from my main class to my Receipt class. When I run the program, when the Receipt displays, "mp.type, mp.number and mp.payment" appears as null. But in main class, there is a value for the variables.

Related

Open Perspective programmatically

I am trying to provide a command/ handler to switch to a specific Perspective.
I came up with the following class:
public class OpenPerspectiveHandler {
private static final Logger logger = Logger.getLogger(OpenPerspectiveHandler.class);
#Inject
private MApplication application;
#Inject
private EModelService modelService;
#Inject
private EPartService partService;
private final String perspectiveId;
public OpenPerspectiveHandler(String perspectiveId) {
super();
this.perspectiveId = perspectiveId;
}
public void changePerspective(String perspectiveId) {
Optional<MPerspective> perspective = findPerspective();
if(perspective.isPresent()) {
partService.switchPerspective(perspective.get());
} else {
logger.debug("Perspective not found (" + perspectiveId + ")");
}
}
#Execute
public void execute() {
changePerspective(perspectiveId);
}
private Optional<MPerspective> findPerspective() {
MUIElement element = modelService.find(perspectiveId, application);
if(element instanceof MPerspective) {
return Optional.of((MPerspective)element);
} else {
logger.debug("Wrong type " + element);
}
return Optional.empty();
}
#Override
public String toString() {
return "OpenPerspectiveHandler [application=" + application + ", modelService=" + modelService + ", partService=" + partService + ", perspectiveId=" + perspectiveId + "]";
}
}
Interestingly, this works only once. A workaround is to cache MPerspective once it was found and not to use modelService.find(perspectiveId, application) again.
Why does it work only once? modelService.find(perspectiveId, application) returns null after the first execution.
EDIT:
Another approach (as suggested by greg-449) is the following:
public class OpenPerspectiveHandler {
private static final Logger logger = Logger.getLogger(OpenPerspectiveHandler.class);
private final String perspectiveId;
public OpenPerspectiveHandler(String perspectiveId) {
super();
this.perspectiveId = perspectiveId;
}
#Execute
public void changePerspective(MApplication application, EModelService modelService, EPartService partService) {
Optional<MPerspective> perspective = findPerspective(application, modelService);
if(perspective.isPresent()) {
partService.switchPerspective(perspective.get());
} else {
logger.debug("Perspective not found (" + perspectiveId + ")");
}
}
private Optional<MPerspective> findPerspective(MApplication application, EModelService modelService) {
MUIElement element = modelService.find(perspectiveId, application);
if(element instanceof MPerspective) {
return Optional.of((MPerspective)element);
} else {
logger.debug("Wrong type " + element);
}
return Optional.empty();
}
}
But this approach also changes the perspective only once. modelService.find(perspectiveId, application); returns null after the first execution.
The EPartService varies depending on the context that the handler runs in. In some cases you get the Application part service which only works if there is an active window.
You can get the part service for that window using something like:
MWindow window = (MWindow)modelService.find("top window id", application);
IEclipseContext windowContext = window.getContext();
EPartService windowPartService = windowContext.get(EPartService.class);

how to watch the cilent when it lose Leadership through zookeeper curator?

as we know,when the client get the leadership,will invode the takeLeadership,but the document do not tell me when the client lost the leadership!!!so,how to watch the cilent when it lose Leadership through zookeeper curator?
question two : why my client was lose,i am can not debug the stateChanged(...) thought idea?
here my code, expect your great answer,thx
public class ExampleClient extends LeaderSelectorListenerAdapter implements Closeable{
private final String name;
private final LeaderSelector leaderSelector;
private final AtomicInteger leaderCount = new AtomicInteger();//用于记录领导次数
public ExampleClient(CuratorFramework client,String path,String name) {
this.name = name;
leaderSelector = new LeaderSelector(client, path, this);
leaderSelector.autoRequeue();//保留重新获取领导权资格
}
public void start() throws IOException {
leaderSelector.start();
}
#Override
public void close() throws IOException {
leaderSelector.close();
}
#Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
if ((newState == ConnectionState.SUSPENDED) || (newState == ConnectionState.LOST) ) {
log.info("stateChanged !!!");
throw new CancelLeadershipException();
}
}
/**
* will be invoded when get leadeship
* #param client
* #throws Exception
*/
#Override
public void takeLeadership(CuratorFramework client) throws Exception {
final int waitSeconds =(int)(Math.random()*5)+1;
log.info(name + " is the leader now,wait " + waitSeconds + " seconds!");
log.info(name + " had been leader for " + leaderCount.getAndIncrement() + " time(s) before");
try {
/**/
Thread.sleep(TimeUnit.SECONDS.toMillis(waitSeconds));
//do something!!!
/*while(true){
//guarantee this client be the leader all the time!
}*/
}catch (InterruptedException e){
log.info(name+" was interrupted!");
Thread.currentThread().interrupt();
}finally{
log.info(name+" relinquishing leadership.\n");
}
}
}
LeaderLatchListener has two call backs about isLeader and notLeader. Some examples,
http://www.programcreek.com/java-api-examples/index.php?api=org.apache.curator.framework.recipes.leader.LeaderLatchListener

Only One Method Call is Shown in Output

I am trying to figure out how to call and output my methods correctly. However, in the output, only one method call is shown (the last one). How do I get it to output all of the method calls and not just the last one. Seems like all of the previous method calls are getting overridden and only the last one persists. I am just beginning in Java. Any help would be appreciated.
Here is the PartyDriver Class where I make 5 method calls. Only the last one is showing in the printParty method.
import java.util.ArrayList;
public class PartyDriver
{
public static void main(String[] args)
{
Party party = new Party(3, "David Beckham");
ArrayList<String> guest = new ArrayList<>();
party.addGuest("Roberto Baggio");
party.addGuest("Zinedine Zidane");
party.addGuest("Roberto Baggio");
party.addGuest("Johan Cruyff");
party.addGuest("Diego Maradona");
party.printParty();
} // end main
}//End Party Driver
Here is the Party Class with all of my methods:
import java.util.ArrayList;
public class Party
{
// instance variables that will hold your data
// private indicates they belong to this class exclusively
private int maxGuests;
private String host;
private String guest;
//Constructor
public Party(int maxGuests, String host)
{
this.maxGuests = maxGuests;
this.host = host;
}
//getter
// define type of data to be returned
public String getHost()
{
return host;
}
//setter
// setters have type void b/c they return nothing
public void setHost(String host)
{
this.host = host;
}
//*************************************
//Method to add to guest list
public void addGuest(String guest)
{
this.guest = guest;
}
//*************************************
//Method to print party
public void printParty()
{
System.out.println("Guest list for " +
this.host + "'s party is: \n\n" +
this.guest + ".\n");
} // end Print Party method
}//end class Party
No methods but PrintParty() print anything because you haven't told any methods but PrintParty() to print anything.
One way to print output to the console is to use System.out.println().
I've adjusted each of your methods to print something to the screen. I also added a guests instance variable to your Party class and made your addGuest(String guest) method modify that instance variable appropriately.
import java.util.ArrayList;
public class Party
{
// instance variables that will hold your data
// private indicates they belong to this class exclusively
private int maxGuests;
private String host;
private ArrayList<String> guests;
//Constructor
public Party(int maxGuests, String host)
{
System.out.println("Initializing party with maxGuests: '" + maxGuests + "' and host: '" + host + "'");
this.guests = new ArrayList<String>();
this.maxGuests = maxGuests;
this.host = host;
}
//getter
// define type of data to be returned
public String getHost()
{
System.out.println("Setting host to: " + host);
return host;
}
//setter
// setters have type void b/c they return nothing
public void setHost(String host)
{
System.out.println("Setting host to: " + host);
this.host = host;
}
//*************************************
//Method to add to guest list
public void addGuest(String guest)
{
if (guests.size() < maxGuests)
{
System.out.println("Adding guest: " + guest);
this.guests.add(guest);
}
else
{
System.out.println("Guest list full");
}
}
//*************************************
//Method to print party
public void printParty()
{
System.out.println("Guest list for " +
this.host + "'s party is: \n\n" +
this.guests + ".\n");
} // end Print Party method
public static void main(String[] args)
{
Party party = new Party(3, "David Beckham");
party.addGuest("Roberto Baggio");
party.addGuest("Zinedine Zidane");
party.addGuest("Roberto Baggio");
party.addGuest("Johan Cruyff");
party.addGuest("Diego Maradona");
party.printParty();
} // end main
}//end class Party

Final Ratio will not calculate. Is my class method called wrong?

In my code I ahve to calculate the number of delayed flights/total flights for airliners. I have written the code and everything works except the final ratio printout. does anyone see the problem?
import au.com.bytecode.opencsv.CSVReader;
// javac -classpath .;opencsv-2.3.jar flightinfo.java
import java.util.*;
import java.io.*;
import java.lang.*;
public class flightinfo2{
public static void main (String [] args) throws Exception{
CSVReader reader = new CSVReader(new FileReader("delayed.csv"));
String [] nextLine;
Map<String, Carrier> airlines = new HashMap<String, Carrier>();
while ((nextLine = reader.readNext()) != null) {
// At this point, nextLine is the name of the carrier, e.g., "Continental"
// nextLine can be used as the key in your "airlines" map. E.g., airlines.put(nextLine, new Carrier());
if (airlines.containsKey(nextLine[1])){
airlines.get(nextLine[1]).addNumFlights(Integer.valueOf(nextLine[6]));
airlines.get(nextLine[1]).addNumDelayed(Integer.valueOf(nextLine[7]));
airlines.get(nextLine[1]).setDelayedRatio();
}
else {
airlines.put(nextLine[1], new Carrier());
airlines.get(nextLine[1]).setName(nextLine[1]);
airlines.get(nextLine[1]).setNumFlights(Integer.valueOf(nextLine[6]));
airlines.get(nextLine[1]).setNumDelayed(Integer.valueOf(nextLine[7]));
}
}
airlines.get("Continental").print();
airlines.get("Atlantic Southeast").print();
airlines.get("American Eagle").print();
airlines.get("Delta").print();
airlines.get("ExpressJet").print();
airlines.get("United").print();
airlines.get("SkyWest").print();
airlines.get("US Airways").print();
airlines.get("JetBlue").print();
airlines.get("American").print();
airlines.get("Mesa").print();
airlines.get("Frontier").print();
airlines.get("AirTran").print();
airlines.get("Southwest").print();
}
}
the Class
public class Carrier{
String name;
int totalFlights;
int delayedFlights;
int totalDelayedRatio;
public Carrier(){}
public void setName(String s){
name = s;
}
public void setNumDelayed(int n){
delayedFlights = n;
}
public void setNumFlights(int s){
totalFlights = s;
}
public void addNumDelayed(int n){
delayedFlights = delayedFlights + n;
}
public void addNumFlights(int s){
totalFlights = delayedFlights + s;
}
public void setDelayedRatio(){
totalDelayedRatio = (delayedFlights/totalFlights);
}
public void print(){
System.out.printf("%s:\t%d,\t%d,\t%d\n", name, totalFlights, delayedFlights, totalDelayedRatio);
}
}
the printout looks like this:
Continental: 92, 81, 0 <---should be the ratio
...more carriers
Instead of:
totalDelayedRatio = (delayedFlights/totalFlights);
Try using "this" explicitly:
this.totalDelatedRatio = (delayedFlights/totalFlights);

File sharing with my chat RMI program

I have been doing a RMI chat system on school and wanted some sort of file sharing with it. Have not done something like this before and have not been through this at school, but I wanted to try. Have done some searching on google and this
http://java.sun.com/developer/technicalArticles/RMI/rmi_corba/
was the best i found. Is this "technology" new so i can use it? Did not get it to work, but that can be my lack of Java knowledge.
Some tips why i don't get it to work?
There isn't a tremendous difference between sending messages back and forth and sending files. The answer depends largely on what your current code looks like. Do you have some code to share?
What does your current RMI interface look like? What does your architecture look like?
Do you have a server that clients connect to?
Do you have a method sendChat(String message)?
With respect to having sendChat(), you could probably add a sendFile( ... ). Then the question is just what you want to do for the parameters.
Do you want to send a java.io.File object? A byte[] (along with a String name, maybe a boolean flag to distinguish binary files)?
Seeing that this is your first time doing this, you might want to code the mundane parts yourself. However, tasks like obtaining bytes from a file are rather common annoyances. The Apache commons and Google guava libraries both provide methods to simplify the process. I suppose it depends on the learning goals you have on this project.
Yes. The clients connects to the server, and are able to chat in chatrooms.
Here is some of the code we have until now, except the file for connecting and communication with the database, and the GUI. Thanks for answering.
Interfaces:
Chatfront interface:
public interface ChatFront extends Remote {
boolean registerClient(Client client, String password) throws RemoteException;
void logMeOut(Client client) throws RemoteException;
void newChannelMessage(String toChannel, String fromUser, String message) throws RemoteException;
void newPrivateMessage(String fromUser, String toUser, String message) throws RemoteException;
String connectChannel(String username, String channel) throws RemoteException;
String disconnectChannel(String username, String channel) throws RemoteException;
boolean isUserRegistered(String username) throws RemoteException;
void errorMessage(String toUser, String message) throws RemoteException;
}
Clientinterface:
public interface Client extends Remote {
String findName() throws RemoteException;
void newPrivateMessage(String fromUser, String toUser, String message) throws RemoteException;
void newMessageChannel(String toChannel, String fromUser, String message) throws RemoteException;
void newSystemMessageChannel(String toChannel, String fromUser, String message) throws RemoteException;
void errorMessage(String toUser, String message) throws RemoteException;
}
Serverside:
class ChatServer {
public static void main(String[] args) throws Exception {
String objectname = "chatter";
LocateRegistry.createRegistry(1099);
ChatFront cf = new ChatFrontImpl();
Naming.rebind(objectname, cf);
javax.swing.JOptionPane.showMessageDialog(null, "Tjener kjører. Trykk OK for å avslutte tjeneren.");
Naming.unbind(objectname);
System.exit(0);
}
}
ChatFrontImpl.java
package server;
import Interfaces.ChatFront;
import Interfaces.Client;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
/**
*
* #author sindre
*/
class ChatFrontImpl extends UnicastRemoteObject implements ChatFront {
private UserDAC u = new UserDAC();
private Hashtable<String, ArrayList<String>> channels = new Hashtable<String, ArrayList<String>>();
private ArrayList<Client> clients = new ArrayList<Client>();
public ChatFrontImpl() throws RemoteException {
}
/* Registrerer en ny client */
#Override
public synchronized boolean registerClient(Client client, String password) throws RemoteException {
if(!u.logIn(client.findName(), password)){
System.out.println("feil username eller password");
return false;
}
if (!clients.contains(client)) {
try {
clients.add(client);
System.out.println("Na er " + client.findName() + " registrert.");
} catch (Exception e){
System.out.println("Feil oppstatt i registrerMeg(): " + e);
}
return true;
} else
return false;
}
/* Kobler en client til en kanal */
#Override
public String connectChannel(String username, String kanal) throws RemoteException{
if(isUserRegistered(username)){
if (!channels.containsKey(kanal)) {
String message = "Bruker " + username + " har ankommet kanalen";
channels.put(kanal, new ArrayList<String>());
channels.get(kanal).add(username);
notifyChannelSystem(kanal, "SYSTEM", message);
notifySelf(username, "Skriv /? for mulige kommandoer");
return("Kanal opprettet, og bruker satt i kanalen.");
}
else{
if(channels.get(kanal).contains(username)){
return ("Brukeren er allerede i kanalen.");
} else {
channels.get(kanal).add(username);
String message = "Bruker " + username + " har ankommet kanalen";
notifyChannelSystem(kanal, "SYSTEM", message);
return ("Kanal fantes allerede. Bruker satt i kanalen.");
}
}
}
return "";
}
/*Sjekker om brukeren ikke er blank.*/
#Override
public boolean isUserRegistered(String username){
if(username.equals("")){
return false;
}
return true;
}
/* Kobler en bruker fra en kanal */
#Override
public String disconnectChannel(String username, String channel) throws RemoteException{
if(isUserInChannelX(username, channel)){
channels.get(channel).remove(username);
String message = "Bruker " + username + " har forlatt kanalen.";
notifySelf(username, " Du har nå forlatt kanalen " + channel);
notifyChannelSystem(channel, "SYSTEM", message);
if(channels.get(channel).isEmpty()){
channels.remove(channel);
}
}
return ("Bruker har forlatt kanalen.");
}
/* Kobler en client fra clientlisten */
#Override
public synchronized void logMeOut(Client client) throws RemoteException {
boolean isfound = false;
int clientIndeks = 0;
while (clientIndeks < clients.size() && !isfound) {
Client denne = clients.get(clientIndeks);
if (denne.equals(client)) { // bruker equals() for a sammenlikne stubbobjektene
isfound = true;
clients.remove(clientIndeks);
System.out.println("Na er clienten " + client.findName() + " fjernet.");
} else clientIndeks++;
}
}
/* Sjekker om brukeren finnes i en gitt kanal */
public boolean isUserInChannelX(String bruker, String kanal){
if(channels.containsKey(kanal) && channels.get(kanal).contains(bruker)){
return true;
} else {
return false;
}
}
/* Kaller metoden varsleKanal()*/
#Override
public void newChannelMessage(String tilKanal, String fraBruker, String message) throws RemoteException{
if(isUserInChannelX(fraBruker, tilKanal)){
notifyChannel(tilKanal, fraBruker, message);
}
else{
}
}
/* Kaller metoden varsleEn() */
#Override
public void newPrivateMessage(String fra, String toUser, String message) throws RemoteException{
notifyUser(fra,toUser,message);
}
#Override
public void errorMessage(String toUser, String message) throws RemoteException{
notifySelf(toUser, message);
}
private void notifySelf(String toUser, String message) throws RemoteException{
for(Client k: clients){
if(k.findName().equals(toUser)){
k.errorMessage(toUser, message);
}
}
}
/* Bruker metoden nymessagePrivat() + ser om brukeren er tilkoblet*/
private void notifyUser(String fromUser, String toUser, String message) throws RemoteException{
boolean funnet = false;
for(Client k : clients){
if(k.findName().equals(toUser)){
k.newPrivateMessage(fromUser, toUser, message);
funnet = true;
}
}
if (!funnet) errorMessage(fromUser, "Ingen brukere ved dette navnet!");
}
/* Kjører metoden nymessageKanal() */
private void notifyChannel(String toChannel, String fromUser, String message) throws RemoteException{
if(channels.containsKey(toChannel) && isUserRegistered(fromUser)){
for(String k : channels.get(toChannel)){
for(Client cli : clients){
if(cli.findName().equals(k)){
cli.newMessageChannel(toChannel, fromUser, message);
}
}
}
}
else{
System.out.println("Brukeren er ikke registrert.");
}
}
private void notifyChannelSystem(String toChannel, String fromUser, String message) throws RemoteException{
if(channels.containsKey(toChannel) && isUserRegistered(fromUser)){
for(String k : channels.get(toChannel)){
for(Client kli : clients){
if(kli.findName().equals(k)){
kli.newMessageChannel(toChannel, fromUser, message);
}
}
}
}
else{
System.out.println("Brukeren er ikke registrert.");
}
}
}
Clientside:
GUILogic.java
package gui;
import Interfaces.ChatFront;
import Interfaces.Client;
import java.rmi.Naming;
import java.rmi.RemoteException;
import klient.ClientImpl;
/**
*
* #author sindre
*/
public class GUILogic {
GUI gui;
ChatFront cf;
public String username;
public String channel;
public String password;
public String message;
public GUILogic(GUI gui){
this.gui = gui;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getChannel() {
return channel;
}
public void setChannel(String channel) {
this.channel = channel;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
/* Kobler GUI klienten opp mot serveren */
public void createCFConnection(String username, String password) throws Exception{
String objectname = "chatter";
String hostname = "localhost";
String url = "rmi://" + hostname + "/" + objectname;
cf = (ChatFront) Naming.lookup(url);
Client k = new ClientImpl(username, gui);
cf.registerClient(k, password);
}
public void connectChannel(String username, String channel) throws RemoteException{
cf.connectChannel(username, channel);
}
public void disconnectChannel(String username, String channel) throws RemoteException{
cf.disconnectChannel(username, channel);
}
public void newChannelMessage(String toChannel, String fromUser, String message) throws RemoteException{
cf.newChannelMessage(fromUser ,toChannel, message);
}
public void newPrivateMessage(String fromUser, String toUser, String message) throws RemoteException{
cf.newPrivateMessage(fromUser, toUser, message);
}
public void errorMessage(String toUser, String message) throws RemoteException{
cf.errorMessage(toUser, message);
}
/* Logger klienten av GUIen */
public boolean logOut(String username) throws RemoteException{
Client k = new ClientImpl(username, gui);
if(k.findName().equals("")){
return false;
} else {
cf.logMeOut(k);
System.out.println("user " + username + " logget ut.");
return true;
}
}
/* Analysermessage har funnet / i starten av messageen, og da blir denne metoden kjørt. */
public String commandWritten(String username, String channel, String message) throws RemoteException{
String[] result = message.split(" ", 3);
String channel1;
if((result[0].equalsIgnoreCase("/join") || (result[0].equalsIgnoreCase("/j")))){
channel1 = result[1];
setChannel(channel1);
connectChannel(username, channel1);
}
else if(result[0].equalsIgnoreCase("/leave") || (result[0].equalsIgnoreCase(("/l")))){
channel = result[1];
disconnectChannel(username, channel);
}
else if(result[0].equalsIgnoreCase("/whisper") || (result[0].equalsIgnoreCase(("/w")))){
for (int x=2; x<result.length; x++)
newPrivateMessage(username, result[1], result[x]);
}
else if(result[0].equalsIgnoreCase("/exit") || (result[0].equalsIgnoreCase(("/e")))){
System.exit(0);
}
else if(result[0].equalsIgnoreCase("/?")){
errorMessage(username, "Mulige kommandoer er:" + "\n" +
"/leave 'channel' eller /l" + "\n" +
"/whisper 'username' eller /w" + "\n" +
"/join 'channel' eller /j" + "\n" +
"/exit eller /e" + "\n");
}
else{
errorMessage(username, "Feil kommando! Skriv /? for mulige kommandoer");
}
return message;
}
/* Analyserer messageen som skrives inn i messagefeltet. Kommandoer starter med / */
public void analyzeMessage(String username, String channel, String message) throws RemoteException{
String text = getMessage().toLowerCase();
char command = '/';
for(int i = 0; i<1; i++){
char c = text.charAt(0);
if(c == command){
commandWritten(username, channel, text);
}
else {
newChannelMessage(username, channel, text);
}
}
}
}