Answered step by step
Verified Expert Solution
Question
1 Approved Answer
// // Object, class and method demo // // import java.util.Scanner; public class TransformersBase { private String name; private int totalSpeedT = 0; // create
// // Object, class and method demo // //
import java.util.Scanner;
public class TransformersBase { private String name; private int totalSpeedT = 0;
// create a constructor public TransformersBase (String str) { name = str; System.out.println("NAME: " + name ); }
//create a method public void speedTest(int speed) { System.out.println("Current speed = " + totalSpeedT); } }
------------------------------------------------------
above is the base code and need to follow this
Week 2 Lab: Object Oriented Programming (15 points) In this lab you are going to do hands-on on the following topics: - How to create class, constructor and objects. - How to use method with different objects. No need to use Transformers class. Feel free to create your own class different from robot (e.g., Food class, Movie class etc). First, create a new folder (Lab02sp23_yourLastNamelnitial; e.g., 'Lab02sp23_LeeKJ'). Throughout the semester, you will create a separate folder for weekly assignments (e.g, Lab02_LeeKJ, Project_LeeKJ). Before the submission, please review your Java files only relevant to specific week. To create Java file, open any editor (e.g., Notepad++, Eclipse) Study the Base Program provided Download 'Lab2.zip'. Unzip and you can find the following files (TransformersBase.java and RobotDemoBase.java). To show your original implementation, you must change the file names by adding your last/family name and first name initial. files (e.g., TransformersBase_LeekJ. java and RobotDemoBase_LeekJ. java). If you don't follow file naming convention, you will receive ' 0 ' mark. After adding two files to a new project, you also need to change your class name in each file to match the file names (1. TransformersBase_LeeKJ and 2. RobotDemoBase_LeeKJ). Compile and run RobotDemoBase_LeekJ.java which contains main() method. NAME: Bumblebee current speed =0 Output of the base program provided Task: Add new member/attribute variables and modify member method/functions: 1) The base file (TransormerBase.java) only has two attribute variables (String name \& int totalSpeedT) representing TransformerBase class. To represent color and weight of the class, add two variables (private int weight \& private String color). These variables will reflect actual arguments shown in constructor. 2) A constructor is a special method that is used to set up an obiect when it is initially created. Rather than having one parameter showing object name, your constructor should include three parameters; name, weight and color. Inside the constructor, add one parameter/argument variable (int kg ) to set the initial weight value of each new TransformerBase object. Add another variable showing color information (String rgb) // create a constructor public TransformersBase (String str) \{ name = str; System.out.printIn("NAME: " + name ); \} NAME: Bumblebee After your implementation 3) Modify speedTest(int speed) method which enable your program (1) to display an initial speed of each object (robot) when a constructor is generated in RobotDemoBase. java, (2) design a conditional statement (e.g.. if - else) to test whether an object (robot) has enough speed (to compare, define another variable for a threshold such as 100km/hr ) for the battle, (3) if a robot not having enough speed, use Scanner iava class letting a user to add power of each object (robot) to speed up, (4) test an updated speed whether it is less than the threshold. Incorporate a loop mechanism to repeat adding more power until a robot gets enough power to pass the speed threshold. 4) Add/instantiate more objects representing different robots inside RobotDemoBase.java (name your own or review Transformers web site) and define each one's name, weight and color. 5) Add more class member variables (e.g., auto parts, weapons, etc.) as well as class member method (e.g., flying automobile, firing missile etc.). 6) Incorporate both if-else conditional statements and iteration (while or for loop). 7) Save all your files, recompile, and test your program. Your output could be similar to an example shown below. 8) For the submission, compress/zip your two java files as Page 3 of One example after your implementation Week 2 Lab: Object Oriented Programming (15 points) In this lab you are going to do hands-on on the following topics: - How to create class, constructor and objects. - How to use method with different objects. No need to use Transformers class. Feel free to create your own class different from robot (e.g., Food class, Movie class etc). First, create a new folder (Lab02sp23_yourLastNamelnitial; e.g., 'Lab02sp23_LeeKJ'). Throughout the semester, you will create a separate folder for weekly assignments (e.g, Lab02_LeeKJ, Project_LeeKJ). Before the submission, please review your Java files only relevant to specific week. To create Java file, open any editor (e.g., Notepad++, Eclipse) Study the Base Program provided Download 'Lab2.zip'. Unzip and you can find the following files (TransformersBase.java and RobotDemoBase.java). To show your original implementation, you must change the file names by adding your last/family name and first name initial. files (e.g., TransformersBase_LeekJ. java and RobotDemoBase_LeekJ. java). If you don't follow file naming convention, you will receive ' 0 ' mark. After adding two files to a new project, you also need to change your class name in each file to match the file names (1. TransformersBase_LeeKJ and 2. RobotDemoBase_LeeKJ). Compile and run RobotDemoBase_LeekJ.java which contains main() method. NAME: Bumblebee current speed =0 Output of the base program provided Task: Add new member/attribute variables and modify member method/functions: 1) The base file (TransormerBase.java) only has two attribute variables (String name \& int totalSpeedT) representing TransformerBase class. To represent color and weight of the class, add two variables (private int weight \& private String color). These variables will reflect actual arguments shown in constructor. 2) A constructor is a special method that is used to set up an obiect when it is initially created. Rather than having one parameter showing object name, your constructor should include three parameters; name, weight and color. Inside the constructor, add one parameter/argument variable (int kg ) to set the initial weight value of each new TransformerBase object. Add another variable showing color information (String rgb) // create a constructor public TransformersBase (String str) \{ name = str; System.out.printIn("NAME: " + name ); \} NAME: Bumblebee After your implementation 3) Modify speedTest(int speed) method which enable your program (1) to display an initial speed of each object (robot) when a constructor is generated in RobotDemoBase. java, (2) design a conditional statement (e.g.. if - else) to test whether an object (robot) has enough speed (to compare, define another variable for a threshold such as 100km/hr ) for the battle, (3) if a robot not having enough speed, use Scanner iava class letting a user to add power of each object (robot) to speed up, (4) test an updated speed whether it is less than the threshold. Incorporate a loop mechanism to repeat adding more power until a robot gets enough power to pass the speed threshold. 4) Add/instantiate more objects representing different robots inside RobotDemoBase.java (name your own or review Transformers web site) and define each one's name, weight and color. 5) Add more class member variables (e.g., auto parts, weapons, etc.) as well as class member method (e.g., flying automobile, firing missile etc.). 6) Incorporate both if-else conditional statements and iteration (while or for loop). 7) Save all your files, recompile, and test your program. Your output could be similar to an example shown below. 8) For the submission, compress/zip your two java files as Page 3 of One example after your implementationStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started