Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help with small java project
New Posts  All Forums:Forum Nav:

Help with small java project

post #1 of 3
Thread Starter 

I am trying to overwrite these variables that I set, but the class just keeps the same variables in place.

 

My tester is passing the right variables to it, but the method in the class isn't recognizing it, or the class itself isn't setting it. I'm not sure.

 

If anyone can help me with this problem I would really appreciate it.

 

CODE:

CODE (Click to show)

 

This is part of the class, as you can see I am trying to overwrite the start time with the NewTime method.  But it isnt working.

 

public class ElapsedTimeCalculator {

 

    private int startTime;

    private int endTime;

 

    public ElapsedTimeCalculator ( int startTime,  int endTime)    {

        this.startTime = startTime;

        this.endTime = endTime;         

    }

 

    public void Newtime (int newtime , int endtime)  {

        startTime = newtime;

        endTime = endtime;

    }

 

 

This is how i am setting the new time in the tester class. This works.

 

        String newSTime;

        String newETime;

   

        newSTime = JOptionPane.showInputDialog("What is the new start time?");

        newETime = JOptionPane.showInputDialog("What is the new end time?");

 

        one.Newtime(Integer.parseInt(newSTime), Integer.parseInt(newETime));

 

 

 


Edited by Intresting Enough - 2/19/12 at 7:48pm
Supra
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7-2600K 4.0GHz @ 1.160V MSI P67A-GD65 (B3) XFX Radeon HD 6950 2GB Unlocked @ 950/1450 XFX Radeon HD 6950 2GB Unlocked @ 950/1450 
RAMHard DriveHard DriveHard Drive
Mushkin Enhanced Silverline 8GB (2 x 4GB) Corsair Nova SSD 32GB 1TB Seagate 6.0GB/s SATA 1TB Seagate 6.0GB/s SATA 
Optical DriveCoolingOSMonitor
Lite-On DVD Burner Stock Windows 7 Ultimate x64 Acer S231HL LED Monitor 
MonitorMonitorKeyboardPower
Acer S231HL LED Monitor Acer A23IH LCD Monitor eMachines Generic Antec 750W Modular 
CaseMouseMouse Pad
Antec 1200 Gigabyte Ghost 6000 dpi Desk 
  hide details  
Reply
Supra
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7-2600K 4.0GHz @ 1.160V MSI P67A-GD65 (B3) XFX Radeon HD 6950 2GB Unlocked @ 950/1450 XFX Radeon HD 6950 2GB Unlocked @ 950/1450 
RAMHard DriveHard DriveHard Drive
Mushkin Enhanced Silverline 8GB (2 x 4GB) Corsair Nova SSD 32GB 1TB Seagate 6.0GB/s SATA 1TB Seagate 6.0GB/s SATA 
Optical DriveCoolingOSMonitor
Lite-On DVD Burner Stock Windows 7 Ultimate x64 Acer S231HL LED Monitor 
MonitorMonitorKeyboardPower
Acer S231HL LED Monitor Acer A23IH LCD Monitor eMachines Generic Antec 750W Modular 
CaseMouseMouse Pad
Antec 1200 Gigabyte Ghost 6000 dpi Desk 
  hide details  
Reply
post #2 of 3
Try this:
Code:
public void setNewtime (int startTime , int endTime)  {
        this.startTime = startTime;
        this.endTime = endTime;
    }

Also, how you are verifying if the variable did in fact change?
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #3 of 3
Thread Starter 
Quote:
Originally Posted by Barbaroti View Post

Try this:
Code:
public void setNewtime (int startTime , int endTime)  {
        this.startTime = startTime;
        this.endTime = endTime;
    }
Also, how you are verifying if the variable did in fact change?

Well it would pass different values later on in the program if it did change. but I fixed it by changing the method constructor in the tester file.

I added this.
ElapsedTimeCalculator two = new ElapsedTimeCalculator(Integer.parseInt(newSTime), Integer.parseInt(newETime));

before I was setting it but only in the tester because I wasnt calling the method from the class.
Supra
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7-2600K 4.0GHz @ 1.160V MSI P67A-GD65 (B3) XFX Radeon HD 6950 2GB Unlocked @ 950/1450 XFX Radeon HD 6950 2GB Unlocked @ 950/1450 
RAMHard DriveHard DriveHard Drive
Mushkin Enhanced Silverline 8GB (2 x 4GB) Corsair Nova SSD 32GB 1TB Seagate 6.0GB/s SATA 1TB Seagate 6.0GB/s SATA 
Optical DriveCoolingOSMonitor
Lite-On DVD Burner Stock Windows 7 Ultimate x64 Acer S231HL LED Monitor 
MonitorMonitorKeyboardPower
Acer S231HL LED Monitor Acer A23IH LCD Monitor eMachines Generic Antec 750W Modular 
CaseMouseMouse Pad
Antec 1200 Gigabyte Ghost 6000 dpi Desk 
  hide details  
Reply
Supra
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel Core i7-2600K 4.0GHz @ 1.160V MSI P67A-GD65 (B3) XFX Radeon HD 6950 2GB Unlocked @ 950/1450 XFX Radeon HD 6950 2GB Unlocked @ 950/1450 
RAMHard DriveHard DriveHard Drive
Mushkin Enhanced Silverline 8GB (2 x 4GB) Corsair Nova SSD 32GB 1TB Seagate 6.0GB/s SATA 1TB Seagate 6.0GB/s SATA 
Optical DriveCoolingOSMonitor
Lite-On DVD Burner Stock Windows 7 Ultimate x64 Acer S231HL LED Monitor 
MonitorMonitorKeyboardPower
Acer S231HL LED Monitor Acer A23IH LCD Monitor eMachines Generic Antec 750W Modular 
CaseMouseMouse Pad
Antec 1200 Gigabyte Ghost 6000 dpi Desk 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help with small java project