Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

java problem

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
please help me whit this code, my program is working
please look at it.


The program has one super
class(vehcile) and 2 sub classes( MotorVehcile and car).

class vehcile:
variable: woner
metod: - print() and -newWoner

class MotorVehcile
variable:woner, power

metod:newpower,print

class car:
variable:woner,power,regNe
metod:new Register number, print
----------------------------------------------
class Test: is like this
public static void main(String[] arg) {
Car c= new Car("Alex", 500,"ABC 200");
c.print();
c.NewWoner();
c.print();
c.newPower();
c.print();
c.newRegNr();
c.print();


Here we have called 3 methods(newWoner, newPower,newRegNr)
and we(users) give new value to every
attribute(I have already written this). and the print methods print out an objects all
attributes.finally the program looks like this.
I have written the program,it is ok.but when I run the program the out put is different(not as same as the orignal):
the problem is here I must not change Class Test and the same time I must not add new methods.

The first time when the program asks user: write new woner(ex: peter)
The usre writes new owner and the program prints out first the old woner(Alex), power and regnNr and then new woner.
every time when we call a method the program should print out every thing from beginning.Like this:

//(The orignla print out after running the program looks like this
// How can I silove this problem.
woner : Alex
power : 500
regnbr:ABC 200
write new woner the user put in new woners name) eter

//After calling new Woner the program prints out every thig from beginning.
woner : Alex
power :500
regnbr:ABC 200
write new woner: peter
woner : peter
power :500
regnbr:ABC 200
write new Power the user put in new power ): 20000

//After calling new power the program prints out every thig from beginning.
woner : Alex
power :500
regnbr:ABC 200
write new woner: peter
woner : peter
power :500
regnbr:ABC 200
write new Power: 20000
woner : peter
power : 20000
regnbr:ABC 200
write new regNr the user put in new regNr):

//After calling new regNr the program prints out every thig from beginning.
woner : Alex
power :500
regnbr:ABC 200
..........
..........
 
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe someone else will answer that, but I have to confess that I'm entirely too lazy to read, decipher, and comprehend all that. If you post the area that's actually giving you problems, I promise to do what I can.
 
Morgan mor
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again!
I have problem whit print out methods.
After running the program I get this print out:

woner : Alex
power :500
regnbr:ABC 200
write new woner: peter
woner : peter
power :500
regnbr:ABC 200
write new Power: 20000
woner : peter
power : 20000
regnbr:ABC 200
write new regNr : ABG 265
woner peter
power :2000
regnbr: ABG 265�

but the print out must be like this after running the program.:
(I can not print out like this
woner : Alex
power : 500
regnbr:ABC 200
write new woner the user put in new woners name) eter
//After calling new Woner the program prints out every thig from beginning.
woner : Alex
power :500
regnbr:ABC 200
write new woner: peter
woner : peter
power :500
regnbr:ABC 200
write new Power the user put in new power ): 20000
//After calling new power the program prints out every thig from beginning.
woner : Alex
power :500
regnbr:ABC 200
write new woner: peter
woner : peter
power :500
regnbr:ABC 200
write new Power: 20000
woner : peter
power : 20000
regnbr:ABC 200
write new regNr the user put in new regNr):
//After calling new regNr the program prints out every thig from beginning.
woner : Alex
power :500
regnbr:ABC 200
..........
..........
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand what you are trying to achieve correctly. You will need to create an Array of Car instances, as on each user input, you are changing the attributes of the one created instance of class Car. I don't understand why you are not allowed to add more methods or change the Test class, as your design needs a bit of reworking.
 
Morgan mor
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again!
If I add new methods, I think I needs two methods:
1: saveCurrentObjectsState()
2 rintCarState()
I tryed but I could not get the same out put as the orignal one.
please healp me.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic