SRL Archive - General

My java program based off the SRL staff.


rj

2013-04-18 17:41:23

This program is based off the SRL staff, I was bored:


import java.util.Arrays;

public class Staff {
boolean active, developer, repanabled = false;
String Name;
String LeaderType;

public void Display() {
System.out.println("You chose " + Name);
System.out.println("Leader type:" + LeaderType);

if (developer == true) {
System.out.println(Name + " is a developer!");
} else {
System.out.println(Name + " is a not developer");

}
if (repanabled == true) {
System.out.println(Name + " has reputation enabled!");
} else {
System.out.println(Name + " does not have reputation enabled!");

}

}

public void CheckReputation() {
String[] EnabledRep = { "MasterBB", "Justin", "YoHoJo", "Zyt3x",
"Coh3n", "Flight", "Zyt3x", "Daniel", "BenLand100", "BraK" };
if (Arrays.asList(EnabledRep).contains(Name)) {
repanabled = true;
} else {
repanabled = false;
}

}

public void CheckActive() {
String[] Active = { "MasterBB", "Justin", "YoHoJo", "Zyt3x", "Coh3n",
"Flight", "Hobbit", "Zyt3x", "Daniel" };
if (Arrays.asList(Active).contains(Name)) {
active = true;
} else {
active = false;
}

}
public void CheckDeveloper ( ) {
String[] Developer = { "Coh3n", "Flight", "Hobbit", "n3ss3s", "NCDS",
"Wizzup?", "WT-Fakawi", "Zyt3x" };
if (Arrays.asList(Developer).contains(Name)) {
developer = true;
}
else {
developer = false;
}


}
public void CheckType() {
String[] MarketLeader = { "MasterBB" };
String[] SuperMod = { "Justin", "YoHoJo", "Zyt3x" };
String[] Admin = { "RAM", "nielsie95", "Hobbit", "Daniel", "Coh3n",
"BraK", "BenLand100" };
String[] Leader = { "Wizzup?", "WT-Fakawi" };
LeaderType = "None";

if (Arrays.asList(MarketLeader).contains(Name)) {
LeaderType = "MarketLeader";
}
if (Arrays.asList(SuperMod).contains(Name)) {
LeaderType = "SuperMod";
}

if (Arrays.asList(Admin).contains(Name)) {
LeaderType = "Admin";
}
if (Arrays.asList(Leader).contains(Name)) {
LeaderType = "SRL leader";
}
}


public void setName(String PName) {
Name = PName;
}

public static void main(String[] args) {
Staff SRLlist = new Staff();
SRLlist.developer = false;

SRLlist.setName("YoHoJo");
SRLlist.CheckType();
SRLlist.CheckDeveloper ();
SRLlist.CheckActive();
SRLlist.CheckReputation();
SRLlist.Display();
}
}

I am trying to make more and moe complicated programs to advance my knowlege
What should I make next?(Java people) [ @Brandon @J J @senrath @euphemism @cause @Sin @Justin @tealc @masterBB @Le Jingle] Nothing to hard though I am still a beginner

masterBB

2013-04-18 17:54:11

Wait you made an instance of the class inside the class? Does that even work?

rj

2013-04-18 17:55:09

From: masterBB
Wait you made an instance of the class inside the class? Does that even work?


Yea try to run it yourself works great if you want to over complicate checking to see if someone is a developer or not

masterBB

2013-04-18 18:07:52

Anyway remake this with java: http://ancientbb.com/

I made it in my lunchbreak yesterday. I challenge you to do it without any function like cos, sin etc.

rj

2013-04-18 18:11:25

From: masterBB
Anyway remake this with java: http://ancientbb.com/

I made it in my lunchbreak yesterday. I challenge you to do it without any function like cos, sin etc.


I said beginner lol aare those even written in java?

masterBB

2013-04-18 18:23:15

From: Officer Barbrady
I said beginner lol aare those even written in java?


No in as3(flash develop), but can be easily be rewritten in java.

Uhm, but easier you say, how about a game were circles(balls) fall horizontal through the screen and you try to evade them with the mouse?

rj

2013-04-18 18:23:55

From: masterBB
No in as3(flash develop), but can be easily be rewritten in java.

Uhm, but easier you say, how about a game were circles(balls) fall horizontal through the screen and you try to evade them with the mouse?


That's to hard I'm a complete beginner lol

tealc

2013-04-18 18:35:04

How about a simple turn based game like tic tac toe or connect4.

Sin

2013-04-18 18:46:33

Here:

C11 Cash Register Program
Write a program that takes in the amount that the customer’s purchases cost and the amount that the customer paid. It should return the amount of change and how many dollars, twoonies, loonies, quarters, dimes, nickels, pennies are needed to make up the change.
Remember to put comments before major sections of code and to add your title comments at the beginning.
Don't worry if the program gives you numbers to 10 decimal places. That is fine.
Remember comments: title comments and as titles before major sections of the program.

Three Examples of Output:

***************************
* CASH REGISTER *
***************************
Please enter the total cost: 15.00
Please enter the amount paid: 17.25
Total change: $2.25
You will need:
1 quarter(s)
1 toonie(s)
***************************
* CASH REGISTER *
***************************
Please enter the total cost: 10.00
Please enter the amount paid: 11.27
Total change: $1.27
You will need:
2 penny(pennies)
1 quarter(s)
1 loonie(s)
***************************
* CASH REGISTER *
***************************
Please enter the total cost: 1.00
Please enter the amount paid: 2.83
Total change: $1.83
You will need:
3 penny (pennies)
1 nickel(s)
3 quarter(s)
1 loonies(s)

A Starting Program:

public class HowManyCents
{
public static void main (String args [])
{
new HowManyCents ();
}
public HowManyCents ()
{//gets money from user with dollars and cents
double amt = IBIO.inputDouble ("Enter the amount in the form $xx.xx >> $");


//converts to cents and to int type
amt = amt * 100;
int cents = (int) amt;
System.out.println ("\n That is " + cents + " cents.");

//Finds the number of loonies in cents, stores it in dollar
int dollar = cents / 100;
//Adjusts the cents so it doesn't hold the dollars too, just the remaining cents
cents = cents % 100;
System.out.println ("Or, " + dollar + " dollars and " + cents + " cents.");
}
}

rj

2013-04-18 19:37:44

From: Sin
Here:

C11 Cash Register Program
Write a program that takes in the amount that the customer’s purchases cost and the amount that the customer paid. It should return the amount of change and how many dollars, twoonies, loonies, quarters, dimes, nickels, pennies are needed to make up the change.
Remember to put comments before major sections of code and to add your title comments at the beginning.
Don't worry if the program gives you numbers to 10 decimal places. That is fine.
Remember comments: title comments and as titles before major sections of the program.

Three Examples of Output:

***************************
* CASH REGISTER *
***************************
Please enter the total cost: 15.00
Please enter the amount paid: 17.25
Total change: $2.25
You will need:
1 quarter(s)
1 toonie(s)
***************************
* CASH REGISTER *
***************************
Please enter the total cost: 10.00
Please enter the amount paid: 11.27
Total change: $1.27
You will need:
2 penny(pennies)
1 quarter(s)
1 loonie(s)
***************************
* CASH REGISTER *
***************************
Please enter the total cost: 1.00
Please enter the amount paid: 2.83
Total change: $1.83
You will need:
3 penny (pennies)
1 nickel(s)
3 quarter(s)
1 loonies(s)

A Starting Program:

public class HowManyCents
{
public static void main (String args [])
{
new HowManyCents ();
}
public HowManyCents ()
{//gets money from user with dollars and cents
double amt = IBIO.inputDouble ("Enter the amount in the form $xx.xx >> $");


//converts to cents and to int type
amt = amt * 100;
int cents = (int) amt;
System.out.println ("\n That is " + cents + " cents.");

//Finds the number of loonies in cents, stores it in dollar
int dollar = cents / 100;
//Adjusts the cents so it doesn't hold the dollars too, just the remaining cents
cents = cents % 100;
System.out.println ("Or, " + dollar + " dollars and " + cents + " cents.");
}
}


That looks hard lol

Richard

2013-04-18 19:48:02

From: masterBB
Wait you made an instance of the class inside the class? Does that even work?


The main() method inside a class actually acts as though it's a separate entity, any method that holds the "static" modifier does this. It makes the class essentially a "holder" for that piece of code. When you refer to said method, you do it as [ClassName].[MethodName] instead of [Instance of ClassName].[MethodName].

For example, our class is this:

public class Test {

public static void staticMethod(){
System.out.println("Static method");
}

public void standardMethod(){
System.out.println("Non-static method");
}
}

To call the static method:


Test.staticMethod();

To call the standard method, you would need to create an instance of object to call the method within it:


Test t = new Test();
t.standardMethod();

masterBB

2013-04-19 04:37:20

From: Richard
The main() method inside a class actually acts as though it's a separate entity, any method that holds the "static" modifier does this. It makes the class essentially a "holder" for that piece of code. When you refer to said method, you do it as [ClassName].[MethodName] instead of [Instance of ClassName].[MethodName].


Thanks, but I know static methods ;)

I just didn't program java in a long time and was confused, thought it was the constructor. My last project was in as3, were the constructor of the main class was executed.

J J

2013-04-19 05:00:24

You should really try to use the proper java syntax so method names and variables names start with a lowercase letter.

Try converting the Admin, Super mod string arrays to actual types using enums.

package org.obduro.java;

public class Celebration {

private String name;
private Event event;

public Celebration(String name, Event event){
this.name = name;
this.event = event;
}

public void talk(){
System.out.println(event.getResponse() + ", " + name);
}

public static void main(String[] args){
Celebration birthday = new Celebration("Officer Barbrady", Event.BIRTHDAY);
birthday.talk();

Celebration promotion = new Celebration("Officer Barbrady", Event.PROMOTION);
promotion.talk();

Celebration winner = new Celebration("Officer Barbrady", Event.WINNER);
winner.talk();

for(Event event : Event.values()){
new Celebration("Officer Barbrady", event).talk();
}

}


}

package org.obduro.java;

public enum Event {

BIRTHDAY("Congratulations with your birthday"),
PROMOTION("Congratulations on your promotion"),
WINNER("Well done! You are the winner of the competion");

private final String response;

private Event(String response){
this.response = response;
}

public String getResponse(){
return response;
}

}

Output:
Congratulations with your birthday, Officer Barbrady
Congratulations on your promotion, Officer Barbrady
Well done! You are the winner of the competion, Officer Barbrady
Congratulations with your birthday, Officer Barbrady
Congratulations on your promotion, Officer Barbrady
Well done! You are the winner of the competion, Officer Barbrady


Example for the idea
package org.obduro.java;

public class Staff {

public void checkRank(String name, Rank rank){
if(rank.containsMember(name)){
System.out.println(name + " does indeed have the rank " + rank);
}else{
System.out.println(name + "does not have the rank " + rank);
}
}

public static void main(String[] args){
Staff staff = new Staff();
staff.checkRank("MasterBB", Rank.MarketLeader);
}


}

package org.obduro.java;

public enum Rank {

MarketLeader("MasterBB"),
SuperMod("Justin", "YoHoJo", "Zyt3x"),
Admin("RAM", "Nielsie95", "Hobbit", "Daniel", "Coh3n", "BraK", "Benland100"),
Leader("Wizzup?", "WT-Fakawi");

private final String[] members;

private Rank(String... members){
this.members = members;
}

public boolean containsMember(String name){
for(String member : members)
if(member.equals(name))
return true;
return false;
}


}

Output:
MasterBB does indeed have the rank MarketLeader

masterBB

2013-04-19 08:45:16

From: J J
Output:
MasterBB does indeed have the rank MarketLeader


Market Moderator, Markus is the leader.

cause

2013-04-19 18:32:47

From: masterBB
Anyway remake this with java: http://ancientbb.com/

I made it in my lunchbreak yesterday. I challenge you to do it without any function like cos, sin etc.


Yo…that is awesome…

Sorry though Officer, I am not java competent.