I'm really new to object/class concepts and already having difficulties with applying them. How to create and return an array of Exam objects? I need to get a data from a textfile which is passed to the method.
Java Code:
public Exam(String firstName, String lastName, int ID, String examType, int score) {
this.firstName = firstName;
this.lastName = lastName;
this.ID = ID;
this.examType = examType;
this.score = score;
I'm really new to object/class concepts and already having difficulties with applying them. how to create and return an array of Exam objects? I need to get a data from a textfile which is passed to the method.
public Exam(String firstName, String lastName, int ID, String examType, int score)
So I'm beginning to learn java with the book HeadFirst Java. The books says that all a tester class does is create objects of a new type and then use the dot operator...
I don't really understand what a tester class is and what it does ? and what is the Dot operator and how does it work ?
In this main class, create 5 objects of the class Menu, as defined in the table below.
Name amount of calories cooking time price per person number of drinks
Fufu and Groundnut Soup 564.65 2515.572 Red Red 345 12 9.980 Rice and Beef Stew 560.4 1512.651 Ga Kenkey and Fish 780 10 10.15 1 Banku and Tilapia 450.4 35 25.17 2
Exercise d In your main class create an array of length 5, and store the 5 objects (Exercise c) into the array. You can use any name for your array.
From the array, use a loop to: Print the details of all the objects using the method you defined in Exercise b.
Exercise e Use another loop to: -Print only the name and cooking time of all the dishes that take less than 30 minutes to cook. Hint: you may use the getter methods for the name and cooking time attributes, and then, print these values (name, cooking time).
Exercise f Use another loop to : -Calculate and print the total price of all the objects (in the array). -Calculate the total price of all the objects with VAT included for each dish (VAT rate is 17.5%).
Submission -Create a folder with your index number as its name. -Copy your Java Project folder into the created folder. -Print a hard copy of your classes. -Submit both soft copy and hard copy of your project
I'm new to Java and I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:
Java Code: public class Sphere { // instance variable (i.e., a field) private double radius; // constructor for the Sphere class public Sphere(double r) { radius = r;
in my progrm there are three diff array of objects...namely garments..gadgets and home app...now one who buys from each of these sections will have to make a bill at last...when he choses to make the bill he will be shown the list of products he bought and their details (like price...brand...etc)...so i thought that while he orders each product(which is done in a previous method called purchase()...)....(each product is stored as an object in there diif arrays namely garments...gadgets ...appliances)....each of those object will be copied in a new array in a diif class...then that array print will give me the desired result...
is this approach correct...?and if its correct then how can i pull out a specific obj frm a stored array of object and then save it in a new array....?
I have a school assignment that involves me sorting an array of objects based on one of the class String variables. I am using as the title says a simple selection sort method. The problem I'm having is that when I run the program in debug mode, it never seems to enter the if statement in the inner loop. I would like to say I've tried a number of things to figure it out, but honestly I'm just stumped as to why it's not working.
Here is the code:
public static void sortTransactions(Transaction[] oTransaction){// This is the sorting method, obviously it's not done so it currently just prints to screen. System.out.println("Successful call to sortTransaction()"); String min = ""; int curInd = 0; Transaction[] temp = new Transaction[1];
[Code] ....
The output when I check to see if the array is sorted verifies that the array never does get sorted.
How do you declare methods for a class within the class whilst objects of the class are declared else where?
Say for instance, I have a main class Wall, and another class called Clock, and because they are both GUI based, I want to put a Clock on the Wall, so I have declared an instance object of Clock in the Wall class (Wall extends JFrame, and Clock extends JPanel).
I now want to have methods such as setClock, resetClock in the Clock class, but im having trouble in being able to refer to the Clock object thats been declared in the Wall class.
Is this possible? Or am I trying to do something thats not possible? Or maybe I've missed something really obvious?
I am trying to clear all graphical objects of a certain type(all trees in particular). I have never had any issues doing so, and this method normally works well along with these variables:
Java Code:
public static ArrayList<GRect> historyT; public static ArrayList<GOval> historyL; public static GRect trunk; public static GOval leave; public void deleteTrees() { //clears all tree trunks and leaves
[Code]...
That is this normally worked until I started added more trees to the screen after they had all been erased. What happens is that it won't clear all of them unless the max has been reached, that is 6. It will remove all trees up till the last one if the max has not been reached. In other words here is my screen before the clear all if the max has not been reached(* is a tree, _ is erased): ****
Here is it after: _ _ _ _ *
So my question is, is why aren't all the trees deleted? Why does it leave one left behind?
The objective of the code is to add new records based on existing records with a partial change to the key. I'm getting "type of the expression must be an array type but it resolved to DstidArray" on dsTidRecTbl[i]
String stMajor = request.getParameter("stMajorVersion"); String stMinor = request.getParameter("stMinorVersion"); String stPatch = request.getParameter("stPatchVersion"); StringBuffer stKeySB = new StringBuffer(stMajor+stMinor+stPatch); String stKey = new String(stKeySB.toString()); DstidArray dsTidRecTbl = new DstidArray(stKey); request.setAttribute("dsTidRecTbl", dsTidRecTbl);
I am simulating a game. This involves creating two Player objects(either HumanPlayer or ComputerPlayer), a TheBoard object, a TheGame object and a TheGameManager object. In the TheGameManager, i am trying to get it so that i can save the two Player objects, the TheBoard object and the TheGame object in current use at some point in the game and then load them later at some point. However, after debugged, i have found that it doesnt like the writeObject() method and skips and sends an exception up.
My TheGameManager class has the following fields:
public class TheGameManager implements GameManager { private Player player1; private Player player2; private TheBoard currentBoard; private TheGame currentGame; //private String[] args; private int iterations = 1;
I'm having trouble creating two new die objects for the PairofDie class. I'm trying to run two separate die and print the face value and then add both numbers up and print those values as well.
public class Die { private final int MAX = 6; private int faceValue; //private int faceValue2; public Die(){ faceValue = 1;
[Code] .....
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method Die() is undefined for the type PairofDice The method Die() is undefined for the type PairofDice at PairofDice.main(PairofDice.java:6)
In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.
package com.scg.athrowaway; import java.util.Calendar; import java.util.Date; public class DateRange { private Date startDate; private Date endDate;
Is it possible to use a loop to create objects? I'm trying to put together a program (just as a way of learning) to run a horse race.
What I'd like to is have the user enter the number of horses they want in the race, and then create the objects as the user enters the various attributes of the horse (at least the horse's name), and then once all the instance variables have been set, create the first horse object and then move on to the second one, etc, until all the horse objects have been created.
I know I can't use something like a for loop to do it, so how would the code be writte
Our instructor gave us a list of steps to complete after creating a Balloon, but I can't get past just creating it. Search results have brought up other Balloon thread, however I couldn't find a topic about issues just creating the balloon.
package myprojects; ublic class BalloonTester { public static void main(String[] args) { Balloon redBalloon = new Balloon("Red Balloon", 100);
You have to create a very basic hangman type of game. Open Notepad and create a list of at least ten words in a text file. Save the file as a .txt file and use it to read words for the game. In this game you do not have to show pictures but you do need to keep track of the amount of times that the user has guessed wrong. When the game starts, show the amount of characters in the word represented as dashes and ask the user to type in a letter. if the user guesses correctly show the word again with the correct letter filled in the correct positions(s) and if the user correctly guessed the word, show a message. If the user guesses wrong, keep track of the body parts that needs to be reduced with every wrong guess and inform the user as well, also show a message.
I'm struggling with reading the file, showing the amount of parts left and asking the user to play again. Here is the code:
package hangman;
/** * * @author */ import java.nio.*; import java.io.*; import java.util.*; public class HangMan {
I have the following code in which I am looping through the rows of one array (composed of Strings) and copying it to another array. I am using .clone() to achieve this and it seems work as it changes the memory location of the rows themselves. I did notice that the String objects are still pointing to the same location in memory in both arrays but I won't worry about that for now, at the moment I just want to understand why the array I am cloning is not successfully assigning to the other array.
This is the incorrect line: ar[r] = maze[r].clone();
I want to create a program where I need to create an object of list type such as text file will contain nos like 1,2,3,4,5 and write into text file and delete the in FIFO order i.e 1,2,3,4,5...how i can achieve to write a program? I tried bt everytime got concurrent modification exception or Array out of bound exception.
public void randomCreate(ParentObject obj){ int x = random(0-4); //pseudo int y = random(0-4); //pseudo create new ParentObj(x,y); }
ParentObject is actually abstract, so you would only ever pass one of its children objects to it, and a child object of that type would be created. It seems like there should be a way to pass a type, rather than an object, and then create an instance later down, but I don't know if that is actually possible, or if it is poor programming style.
For class, we need to create a word game using classes and objects.
The game is played in rounds. The player is presented with a word that is missing letters. The player has to fill in the missing spaces with their letter guesses. The words presented are chosen with a random number generator which has been provided for us. At the end of the game, the player is shown their score.
In steps, I have to:
-Welcome the player. -Present the puzzle. -Allow the player to fill in the blanks. -Have the program check responses for correct/incorrect input. -End the game if they have three misses, or continue if they complete the puzzle.
Now, to start, I have a class for the number generator, a class to store the array of 25 words, and a class for the game itself.
I want to clarify it whether this below code, when running this loop, will it create separate string objects as strings are immutable or else, will it keep the same reference(as each time inside loop, we use the same name 'rslt') and assign new string value for this?