Java school Project
- hamin_aus
- Forum Moderator
- Posts: 18363
- Joined: 28 Aug 2003, 02:00
- Processor: Intel i7 3770K
- Motherboard: GA-Z77X-UP4 TH
- Graphics card: Galax GTX1080
- Memory: 32GB G.Skill Ripjaws
- Location: Where beer does flow and men chunder
- Contact:
Who, pray tell, is jammin_za?rustypup wrote:found this hiding on the server...Code: Select all
public class NooBScanner() implements Serializable { public static enum CONSTANT_NOOBS{ LAW("Law", "Master of the Pubic kNights"), BOB_MUGABE("Satan", "Raging Elton John fan"), AUSTIN_POWERS("jammin_za", "Brick-less"); . . . }
NOOB!!!1!1!!one
-
- I Bribed Ron With Foundry And All I Got Was This Lousy Title
- Posts: 9387
- Joined: 09 Aug 2002, 02:00
- Location: Locked Down
- Contact:
Grrrr, this program is so frustrating. I rally stuck on the classes
Want to support my creative work? Drop me a like and subscribe below. It will be greatly appreciated!
Clarke Media - YouTube Channel
Clarke Media - Facebook
Clarke Media - YouTube Channel
Clarke Media - Facebook
-
- Permanently Banned
- Posts: 1031
- Joined: 18 Aug 2005, 02:00
- Location: Travelling through the busy highway of life.
the problem is u have and integer "cos" declared on the leftamdretard wrote:public String getCost ()
{
return int cos = min * 1.1;
}
what is wrong with this
yet u have made it equal to variable multiplied by 1.1.
1.1 is not an integer it is a double precision variable.
you cannot have a int * double.
a solution would be this:
return double cos = min * 1.1;
or
int c1 = min*11;
return double cos = c1 / 10;
P4 3.0E LGA 775 1mb L2
Chaintech v915p
MSI Geforce 6600 Diamond Edition(425/1200)
512 Mb Dual DDR 400
80 Gb ATA 100 Hd
SB Live 7.1
3Dmark 2005: 3012
CHECK OUT MY BAND @ www.the-zenith.com
Chaintech v915p
MSI Geforce 6600 Diamond Edition(425/1200)
512 Mb Dual DDR 400
80 Gb ATA 100 Hd
SB Live 7.1
3Dmark 2005: 3012
CHECK OUT MY BAND @ www.the-zenith.com
I am stuck with the follow set of code
what i want ot do is for it to randomly choose between a landline no and a cell no and then make the respective no and then display the anser as well as saving it in to the class
Code: Select all
{
int option = (int) ((Math.random () * 3));
if (option == 2)
{
String cellNo = "07" + (int) (Math.random () * 4 + 1) + "-";
for (int i = 1 ; i <= 7 ; i++)
{
int x = (int) (Math.random () * 10);
cellNo = cellNo + x; // (pin + char (x));
}
}
String call = cellNo;
else
{
//landline
String landLine = "021";
for (int i = 1 ; i < 7 ; i++)
{
int x = (int) (Math.random () * 10);
landLine = landLine + x; // (pin + char (x));
}
}
String call = landLine;
setOutNo (call);
System.out.println ("Dailing " + call);
My friends think i need a life. What do you think?
just tell us whats not working aswell makes life easier
were the b tags and <<<
thats 1 problem but your ide should of picked it up. The Landline and cell strings arn't visible were you set call
amdretard wrote:Code: Select all
{ int option = (int) ((Math.random () * 3)); if (option == 2) { String cellNo = "07" + (int) (Math.random () * 4 + 1) + "-"; for (int i = 1 ; i <= 7 ; i++) { int x = (int) (Math.random () * 10); cellNo = cellNo + x; // (pin + char (x)); } } String call = cellNo; else { //landline String landLine = "021"; for (int i = 1 ; i < 7 ; i++) { int x = (int) (Math.random () * 10); landLine = landLine + x; // (pin + char (x)); } } String call = landLine; setOutNo (call); System.out.println ("Dailing " + call);
Code: Select all
{
int option = (int) ((Math.random () * 3));
if (option == 2)
{
String cellNo = "07" + (int) (Math.random () * 4 + 1) + "-";<<<
for (int i = 1 ; i <= 7 ; i++)
{
int x = (int) (Math.random () * 10);
cellNo = cellNo + x; // (pin + char (x));
}
}
String [b]call [/b]= cellNo;<<<
else
{
//landline
String [b]landLine [/b]= "021"; <<<
for (int i = 1 ; i < 7 ; i++)
{
int x = (int) (Math.random () * 10);
landLine = landLine + x; // (pin + char (x));
}
}
String call = [b]landLine[/b]; <<<
setOutNo (call);
System.out.println ("Dailing " + call);
thats 1 problem but your ide should of picked it up. The Landline and cell strings arn't visible were you set call
Last edited by Law on 01 Sep 2005, 07:27, edited 2 times in total.
MAY THE CHEESE BE WITH YOU!
{PK} Law
Your method says your returning a string and your sending back an int multiplied by a float.Basipooh wrote:the problem is u have and integer "cos" declared on the leftamdretard wrote:public String getCost ()
{
return int cos = min * 1.1;
}
what is wrong with this
yet u have made it equal to variable multiplied by 1.1.
1.1 is not an integer it is a double precision variable.
you cannot have a int * double.
a solution would be this:
return double cos = min * 1.1;
or
int c1 = min*11;
return double cos = c1 / 10;
well spotted v1c.
OK now for that method asv1c said you aint returning a string. OK if it's a string you want to return use this
It's just i nice method for formatting double values into strings. the 1st value is the double to format. second is the characterlength of the string. third is the number of decimals you want so
OK now for that method asv1c said you aint returning a string. OK if it's a string you want to return use this
Code: Select all
public static String format(double d,int toWidth,int decWidth)
//--------------------------------------------------------------
// outputs a double in toWidth places, with decWidth decimal places
{
StringBuffer wholeString;
StringBuffer decString;
double scale = Math.pow(10,decWidth);
d = Math.round(d*scale)/scale;
long wholePart = (long)d;
double decimalPart = Math.abs(d - wholePart);
int wholeWidth = toWidth - decWidth - 1;
if (decWidth < 1) // 0 decimal places requested - round to long
{
long l = Math.round(d);
return format(l,toWidth);
}
// express whole part as a string
wholeString = new StringBuffer(format(wholePart,wholeWidth));
if (d<0 && d>-1) // force "-0"
if (wholeWidth>1)
wholeString.setCharAt(wholeWidth-2,'-');
else
wholeString.insert(0,'-');
decimalPart = decimalPart*scale; // express decimal part as a
long decPart = Math.round(decimalPart); // decWidth sized long
decimalPart = decPart/scale; // convert back to value <1
decString = new StringBuffer(Double.toString(decimalPart));
decString.delete(0,2); // delete 0 and .
if (decString.length() > decWidth) // ensure the right size
decString.setLength(decWidth);
else
while (decString.length() < decWidth)
decString.append('0');
return wholeString.toString() + '.' + decString.toString();
}
Code: Select all
double d = 123.4567;
double d2 = 456.123;
System.out.println(Formatter.format(d,6,2));
System.out.println(Formatter.format(d2,6,2));
System.out.println(Formatter.format(d2,8,2));
output:
123.46
456.12
456.12
MAY THE CHEESE BE WITH YOU!
{PK} Law
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
<noObs everywhere...>
Time encapsulation
Cost encapsulation
by breaking the problem down into manageable chunks you will find your life is made much easier and there will be fewer oppurtunities to code blapsies...
now... you should consider including some networking here... check out MulticastSocket, (UDP socket which is absolutely perfect for an SMS/Chat style session)... at the same time Timer/TimerTask will provide you the means to manage the various elements ...
who's doing the gui?
Time encapsulation
Code: Select all
public class CallTime{
private int days, hours, minutes, seconds, millis;
public CallTime(long durationInMillis)
{
super();
int days = (int)CallCost.CALL_UNIT.DAY.getRepetition(durationInMillis);
long rem = CallCost.CALL_UNIT.DAY.getRemainder(durationInMillis);
hours = (int)CallCost.CALL_UNIT.HOUR.getRepetition(rem);
rem = CallCost.CALL_UNIT.HOUR.getRemainder(rem);
minutes = (int)CallCost.CALL_UNIT.MINUTE.getRepetition(rem);
rem = CallCost.CALL_UNIT.MINUTE.getRemainder(rem);
seconds = (int)CallCost.CALL_UNIT.SECOND.getRepetition(rem);
millis = (int)CallCost.CALL_UNIT.SECOND.getRemainder(rem);
}
public int getDays()
{
return days;
}
public int getHours()
{
return hours;
}
public int getMinutes()
{
return minutes;
}
public int getSeconds()
{
return seconds;
}
public int getMilliseconds()
{
return millis;
}
public long getDuration()
{
long retval = days*CallCost.CALL_UNIT.DAY.getModifier();
retval+=hours*CallCost.CALL_UNIT.HOUR.getModifier();
retval+=minutes*CallCost.CALL_UNIT.MINUTE.getModifier();
retval+=seconds*CallCost.CALL_UNIT.SECOND.getModifier();
retval+=millis;
return retval;
}
public String toString()
{
return days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds, "+millis+" milliseconds";
}
Code: Select all
public class CallCost {
public static enum CALL_UNIT{
SECOND(1),
MINUTE(60),
HOUR(CALL_UNIT.MINUTE.getModifierEntry()*60),
DAY(CALL_UNIT.HOUR.getModifierEntry()*24);
private int modifier;
CALL_UNIT(int entry)
{
modifier = entry;
}
public int getModifierEntry()
{
return modifier;
}
public long getModifier()
{
return modifier*1000;
}
public long getRemainder(long input)
{
return input%this.getModifier();
}
public long getRepetition(long input)
{
return input/this.getModifier();
}
}
public static final java.text.NumberFormat COST_FORMAT = java.text.DecimalFormat.getCurrencyInstance();
private long duration;
private java.math.BigDecimal costPerUnit;
private CallTime time;
public CallCost(double costPerMinute, long callDurationInMillis)
{
time = new CallTime(callDurationInMillis);
costPerUnit = new java.math.BigDecimal(costPerMinute / CALL_UNIT.MINUTE.getModifier());
}
public CallTime getDuration()
{
return time;
}
public double getCost()
{
return time.getDuration() * costPerUnit.doubleValue();
}
public String formattedCost()
{
return COST_FORMAT.format(this.getCost());
}
public String toString()
{
return CallCost.COST_FORMAT.format(this.getCost());
}
}
now... you should consider including some networking here... check out MulticastSocket, (UDP socket which is absolutely perfect for an SMS/Chat style session)... at the same time Timer/TimerTask will provide you the means to manage the various elements ...
who's doing the gui?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
-
- Permanently Banned
- Posts: 1031
- Joined: 18 Aug 2005, 02:00
- Location: Travelling through the busy highway of life.
hes only in gr.10 i dont think the program has to go into that level of complexityrustypup wrote: now... you should consider including some networking here... check out MulticastSocket, (UDP socket which is absolutely perfect for an SMS/Chat style session)... at the same time Timer/TimerTask will provide you the means to manage the various elements ...
who's doing the gui?
P4 3.0E LGA 775 1mb L2
Chaintech v915p
MSI Geforce 6600 Diamond Edition(425/1200)
512 Mb Dual DDR 400
80 Gb ATA 100 Hd
SB Live 7.1
3Dmark 2005: 3012
CHECK OUT MY BAND @ www.the-zenith.com
Chaintech v915p
MSI Geforce 6600 Diamond Edition(425/1200)
512 Mb Dual DDR 400
80 Gb ATA 100 Hd
SB Live 7.1
3Dmark 2005: 3012
CHECK OUT MY BAND @ www.the-zenith.com
-
- Registered User
- Posts: 10962
- Joined: 03 Oct 2003, 02:00
- Processor: Intel 2500K
- Motherboard: Gigabyte B75M D3H
- Graphics card: inno3d Jericho 570GTX
- Memory: 8Gig DDR3 1333mhz
- Location: I'm so Goth, my wrists slit themselves.
- Contact:
But it will help with brownie points.....Basipooh wrote:hes only in gr.10 i dont think the program has to go into that level of complexityrustypup wrote: now... you should consider including some networking here... check out MulticastSocket, (UDP socket which is absolutely perfect for an SMS/Chat style session)... at the same time Timer/TimerTask will provide you the means to manage the various elements ...
who's doing the gui?
"In my weird politically incorrect hypothetically incoherent contradicting obscured world definitively maybe"
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
complexity schmexity.... nothing wrong with a little adventure... and fooling around with UDP is a lot of fun...Basipooh wrote:hes only in gr.10 i dont think the program has to go into that level of complexity
unless you are suggesting that there may never be a gui, in which case.... errg...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
When ever i type 1 or 2 it shows me the dailing and the last dialed number while 1 is supposed to display just dialing and 2 is supposed to display last called number but 3 does the 1 fuction
Code: Select all
while (choiceIn < 3)
{
System.out.println ("Menu 1]Make a call 2] List of numbers Dailed");
choiceIn = Integer.parseInt (reader.readLine ());
if (choiceIn < 1)
cellNo="";
landLine="";
{
{
cellNo = "07" + (int) (Math.random () * 4 + 1) + "-";
for (int i = 1 ; i <= 7 ; i++)
{
int x = (int) (Math.random () * 10);
cellNo = cellNo + x; // (pin + char (x));
}
landLine ="021";
for (int i = 1 ; i < 7 ; i++)
{
int x = (int) (Math.random () * 10);
landLine = landLine + x; //(pin + char (x));
}
}
int option = (int) ((Math.random () * 3));
if (option == 2)
cellphone.setOutNo (cellNo);
else
cellphone.setOutNo (landLine);
{System.out.println("Dailing " + cellphone.getOutGoing());
System.out.println("The time of that call was" + cellphone.getTime());}
}
if (choiceIn > 1)
{
System.out.println (" Last number dailed " + cellphone.getOutGoing ());
}
My friends think i need a life. What do you think?
I cant figure how the method for time will work is this right
Code: Select all
public void setTime (double time)
{
double TotSecs = (Math.random () * 5000 + 1);
time=TotSecs;
double minute = TotSecs % 60;
double mins = minute % 60;
}
My friends think i need a life. What do you think?
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
to finalise....
the call itself
a management system , doubles as the combo model in this case..
and on to the gui itself...
first a simple progress bar animation task..
and finally the gui itself..
note:
the first two classes are required.. if you use any version of jvm less than 1.5.0 you will encounter issues with both the generics tags , <>, as well as the usage of the enum types... these will need to be stripped out to encapsulating classes in order to function correctly...
amazing what can be achieved in ten minutes of free time... and the API docs
any questions shout....
the call itself
Code: Select all
public class CellCall {
private long duration;
private String targetNumber;
private int callCount;
private boolean inProgress;
private CallManager.CALL_TYPE type;
public CellCall(String dialed, CallManager.CALL_TYPE tipo)
{
super();
type = tipo;
duration = 0;
targetNumber = dialed;
callCount = 0;
}
public void setType(CallManager.CALL_TYPE tipo)
{
type = tipo;
}
public CallManager.CALL_TYPE getType()
{
return type;
}
public void dial()
{
callCount++;
duration = System.currentTimeMillis();
inProgress = true;
}
public void hangUp()
{
duration = System.currentTimeMillis() - duration;
inProgress = false;
}
public String getDialedNumber()
{
return targetNumber;
}
public synchronized CallCost getCost()
{
if(callCount==0)
return new CallCost(type.getPerMinuteRate(), 0);
if(inProgress)
return new CallCost(type.getPerMinuteRate(), System.currentTimeMillis()-duration);
return new CallCost(type.getPerMinuteRate(), duration);
}
}
Code: Select all
public class CallManager extends java.util.Observable implements javax.swing.ComboBoxModel{
public static enum UPDATE_TYPE{NUMBERADDED, CALLDIALED, CALLCANCELLED}
public static enum CALL_TYPE{
LANDLINE(2.15),
CELLPHONE(1.25),
ROAMING(4.18);
private double rate;
CALL_TYPE(double ratePerMinute)
{
rate = ratePerMinute;
}
public double getPerMinuteRate()
{
return rate;
}
}
private java.util.ArrayList<CellCall> completedCalls;
private java.util.ArrayList<javax.swing.event.ListDataListener> listListeners;
private CellCall current;
public CallManager()
{
super();
completedCalls = new java.util.ArrayList<CellCall>();
listListeners = new java.util.ArrayList<javax.swing.event.ListDataListener>();
}
public boolean numberExists(String nmbr)
{
if(this.seek(nmbr)>=0)
return true;
return false;
}
public int seek(String nmbr)
{
int pos=0;
for(CellCall cc:completedCalls)
if(cc.getDialedNumber().equals(nmbr))
return pos;
else
pos++;
return -1;
}
public void placeCall(String numberToDial, CALL_TYPE type)
{
if(this.numberExists(numberToDial))
current = completedCalls.get(this.seek(numberToDial));
else
{
current = new CellCall(numberToDial, type);
completedCalls.add(current);
this.setChanged();
this.notifyObservers(UPDATE_TYPE.NUMBERADDED);
}
current.dial();
this.setChanged();
this.notifyObservers(UPDATE_TYPE.CALLDIALED);
}
public CallCost hangUp()
{
if(current!=null)
current.hangUp();
this.setChanged();
this.notifyObservers(UPDATE_TYPE.CALLCANCELLED);
return current.getCost();
}
public CellCall getLastDialed()
{
return current;
}
public void fireUpdateEvent(String number)
{
javax.swing.event.ListDataEvent lde = new javax.swing.event.ListDataEvent(number, javax.swing.event.ListDataEvent.INTERVAL_ADDED, completedCalls.size()-1, completedCalls.size()-1);
for(javax.swing.event.ListDataListener ldl:listListeners)
ldl.intervalAdded(lde);
}
public Object getSelectedItem() {
if(current!=null)
return current.getDialedNumber();
return "";
}
public void setSelectedItem(Object obj) {
int pos = this.seek((String)obj);
if(pos>=0)
current = completedCalls.get(pos);
else
{
current = new CellCall((String)obj, CallManager.CALL_TYPE.CELLPHONE);
completedCalls.add(current);
}
}
public void addListDataListener(javax.swing.event.ListDataListener listener) {
listListeners.add(listener);
}
public Object getElementAt(int pos) {
return completedCalls.get(pos).getDialedNumber();
}
public int getSize() {
return completedCalls.size();
}
public void removeListDataListener(javax.swing.event.ListDataListener listener) {
listListeners.remove(listener);
}
}
first a simple progress bar animation task..
Code: Select all
public class SimpleAnimation extends java.util.TimerTask{
private CellCall callInProgress;
private int currentCap, tally;
private javax.swing.JProgressBar target;
public SimpleAnimation(javax.swing.JProgressBar bar, CellCall c)
{
super();
callInProgress = c;
currentCap = 100;
target = bar;
tally = 0;
target.setValue(0);
target.setMaximum(currentCap);
}
public void run()
{
tally++;
if(tally>(currentCap*0.8))
currentCap+=currentCap*.5;
target.setValue(tally);
target.setMaximum(currentCap);
target.setString(callInProgress.getCost().toString());
target.repaint();
}
}
Code: Select all
public class SimpleGUI extends javax.swing.JPanel implements java.util.Observer, java.awt.event.ActionListener{
private javax.swing.JPanel dialPad, screen, keyPad;
private javax.swing.JLabel screenL, dialL;
private javax.swing.JButton dial, disconnect;
private javax.swing.JComboBox input;
private javax.swing.JProgressBar bar;
private java.util.Timer animTask;
private CallManager cMan;
public SimpleGUI()
{
this(null);
}
public SimpleGUI(CallManager man)
{
super(new java.awt.BorderLayout(4,4));
this.initComponents();
if(man!=null)
{
man.addObserver(this);
cMan = man;
dial.addActionListener(this);
disconnect.addActionListener(this);
input.setModel(man);
input.addActionListener(this);
}
this.add(screen, java.awt.BorderLayout.NORTH);
this.add(dialPad, java.awt.BorderLayout.CENTER);
}
public void initComponents()
{
dialPad = new javax.swing.JPanel(new java.awt.GridLayout(3, 1, 4, 4));
screen = new javax.swing.JPanel(new java.awt.BorderLayout(2, 2));
keyPad = new javax.swing.JPanel(new java.awt.GridLayout(1, 2, 5, 5));
dial = new javax.swing.JButton(" Dial ");
disconnect = new javax.swing.JButton(" Disconnect ");
disconnect.setEnabled(false);
keyPad.add(dial);
keyPad.add(disconnect);
input = new javax.swing.JComboBox();
input.setEditable(true);
dial.setActionCommand("dal");
disconnect.setActionCommand("dsc");
input.setActionCommand("fld");
dialL = new javax.swing.JLabel("Dial Pad");
dialL.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
dialL.setForeground(java.awt.Color.BLUE);
dialL.setBorder(javax.swing.BorderFactory.createEtchedBorder(1));
dialPad.add(dialL, java.awt.BorderLayout.NORTH);
dialPad.add(input, java.awt.BorderLayout.CENTER);
dialPad.add(keyPad, java.awt.BorderLayout.SOUTH);
bar = new javax.swing.JProgressBar(javax.swing.JProgressBar.HORIZONTAL, 0, 100);
bar.setStringPainted(true);
screenL = new javax.swing.JLabel("Somenumber");
screenL.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
screenL.setForeground(java.awt.Color.YELLOW);
screenL.setBackground(java.awt.Color.DARK_GRAY);
screenL.setOpaque(true);
screenL.setBorder(javax.swing.BorderFactory.createLoweredBevelBorder());
screenL.setFont(new java.awt.Font("Tahoma", java.awt.Font.BOLD|java.awt.Font.TRUETYPE_FONT, 30));
screen.add(screenL, java.awt.BorderLayout.CENTER);
screen.add(bar, java.awt.BorderLayout.SOUTH);
}
public void update(java.util.Observable obs, Object obj) {
if(obj.equals(CallManager.UPDATE_TYPE.CALLDIALED))
{
screenL.setText(cMan.getLastDialed().getDialedNumber()+" {"+cMan.getLastDialed().getType()+"}");
animTask = new java.util.Timer("Animations");
animTask.schedule(new SimpleAnimation(bar, cMan.getLastDialed()), 50, 20);
dial.setEnabled(false);
input.setEnabled(false);
disconnect.setEnabled(true);
}
if(obj.equals(CallManager.UPDATE_TYPE.CALLCANCELLED))
{
animTask.cancel();
bar.setString("");
bar.setValue(0);
bar.setMaximum(10);
dial.setEnabled(true);
input.setEnabled(true);
disconnect.setEnabled(false);
}
this.repaint();
}
public void actionPerformed(java.awt.event.ActionEvent ae)
{
if(ae.getSource().equals(input)||ae.getSource().equals(dial)&&((String)input.getSelectedItem()).length()>0)
cMan.placeCall(((String)input.getSelectedItem()), CallManager.CALL_TYPE.CELLPHONE);
if(ae.getSource().equals(disconnect))
screenL.setText("Last Call :"+cMan.hangUp());
}
public static void main(String[] args)
{
javax.swing.JFrame frm = new javax.swing.JFrame("TFRAME");
frm.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frm.getContentPane().add(new SimpleGUI(new CallManager()), java.awt.BorderLayout.CENTER);
frm.setSize(500, 180);
frm.setLocationRelativeTo(null);
frm.setVisible(true);
}
}
the first two classes are required.. if you use any version of jvm less than 1.5.0 you will encounter issues with both the generics tags , <>, as well as the usage of the enum types... these will need to be stripped out to encapsulating classes in order to function correctly...
amazing what can be achieved in ten minutes of free time... and the API docs
any questions shout....
Most people would sooner die than think; in fact, they do so - Bertrand Russel
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
setTime(someVal) presumes that the object has a "time" ember that you wish to set.. therefore, the value passed should ideally be the new value contained within the object...amdretard wrote:I cant figure how the method for time will work is this rightCode: Select all
public void setTime (double time) { double TotSecs = (Math.random () * 5000 + 1); time=TotSecs; double minute = TotSecs % 60; double mins = minute % 60; }
Code: Select all
public class SomeClass{
private int time;
...
public void setTime(int t){
time =t;
}
}
Most people would sooner die than think; in fact, they do so - Bertrand Russel
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
hmmm ... as for you random letter generator, note that character literals can be treated as int values... soamdretard wrote:Is there a simple few lines fo code for reading the desktops time to your program
Code: Select all
if(val<'A'||val>'z')
//do it again
else
return val
Code: Select all
//Provides a specific format...
SimpleDateFormat SDF = new SimpleDateFormat("dd/mm/yyy hh:MM:ss");
//provides the currently specified locale's date format....
SimpleDateFormat sdf = SimpleDateFormat().getDateInstance();
//or.... for date&time
DateFormat sdf = SimpleDateFormat().getDateTimeInstance();
Code: Select all
String f = DateFormat.getDateTimeInstance().format(new java.util.Date(System.currentTimeMillis()))
check the API for DateFormat, Date and SimpleDateFormat for some other nifty uses....
Most people would sooner die than think; in fact, they do so - Bertrand Russel