Results 1 to 3 of 3
  1. #1
    SkumScott's Avatar
    Join Date
    Aug 2015
    Gender
    male
    Location
    Land of Beautiful Girls
    Posts
    12
    Reputation
    34
    Thanks
    65
    My Mood
    Flirty

    Can anyone help me with Java code?

    Hello everyone, I am having problem with one question. Can anyone please sort out code for me? I am so confused about it.


    Question: A computer system is needed to track horses in a race. The system must be able to register a horse (name and number), record race data (horse number and finish time), calculate race winner (fastest) and display list of times. Find the horse name by entering the number.


    It will be really appreciated, let's see now dudes skills

  2. #2
    Dogmatic's Avatar
    Join Date
    Dec 2016
    Gender
    male
    Posts
    110
    Reputation
    69
    Thanks
    62
    My Mood
    Amused
    You can make a Horse class that contains the instance variables name, number, and finish time. Create an array of these Horse objects of the size of however many horses are in the race. When you're trying to see who the winner is, just compare each horse's finish time and get the horse with the lowest one. And then you can display the horses' data in a tabular form.

    If you need further help, add me on Skype.

  3. #3
    babydark006's Avatar
    Join Date
    Sep 2016
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    0
    This code should work.

    This is the object Horse. I set the Time and the Number as string for convenience only.

    Code:
    import java****.PrintStream;
    import java.util.Scanner;
    
    
    public class Horse {
    
    	
    
    	public Horse(String name, String num, String time) {
    	
    		this.name = name;
    		this.num = num;
    		this.time = time;
    	}
    	
    	public static Horse read(Scanner sc){
    		String name, num, time;
    		
    		if(!sc.hasNext()) return null;
    		name = sc.nextLine();
    		
    		if(!sc.hasNext()) return null;
    		num = sc.nextLine();
    		
    		if(!sc.hasNext()) return null;
    		time = sc.nextLine();
    		
    		return new Horse(name, num, time);
    		
    	}
    	
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	public String getNum() {
    		return num;
    	}
    	public void setNum(String num) {
    		this.num = num;
    	}
    	public String getTime() {
    		return time;
    	}
    	public void setTime(String time) {
    		this.time = time;
    	}
    
    
    	public void print (PrintStream ps){
    		ps.println(name);
    		ps.println(num);
    		ps.println(time);
    	}
    
    	private String name;
    	private String num;
    	private String time;
    }
    this is the part that handles the functions. You can add a new horse or edit an existent one, find the name by the number, but there is not the faster because I do not want to implement it
    However, modify the Time in an int or you can use the java time class, your choice. To find the faster you have to save the first horse as the faster one, then compare with the second horse. If the second is faster the second is the new horse to compare with the other, else continue with the first.



    Code:
    import java****.File;
    import java****.FileNotFoundException;
    import java****.PrintStream;
    import java****.PrintWriter;
    import java.util.ArrayList;
    import java.util.Scanner;
    
    
    public class Gestore {
    
    
    	
    	public Gestore() throws FileNotFoundException{
    		Scanner in = new Scanner(HORSE);
    		horses = new ArrayList<Horse>();
    		Horse scan = Horse.read(in);
    		while(scan != null){
    			horses.add(scan);
    			scan = Horse.read(in);
    		}
    		in.close();
    	}
    	
    	
    	public void printAll(PrintStream ps){
    		for(Horse h: horses){
    			h.print(ps);
    			}
    		}	
    		
    	public void newHorse() throws FileNotFoundException{
    		Horse tempHorse = new Horse(null, null, null);
    		Scanner in = new Scanner(System.in);
    		
    		System.out.println("Put the name of the horse:");
    		tempHorse.setName(in.nextLine());
    		
    		System.out.println("Put the number of the horse:");
    		tempHorse.setNum(in.nextLine());
    		
    		System.out.println("Put the time of the horse:");
    		tempHorse.setTime(in.nextLine());
    		
    		horses.add(tempHorse);
    		updateHorse();
    		in.close();
    	}
    	
    	public void updateHorse() throws FileNotFoundException{
    		PrintWriter out = new PrintWriter(HORSE);
    		for (Horse h: horses){
    			out.println(h.getName());
    			out.println(h.getNum());
    			out.println(h.getTime());
    		}
    		out.close();
    	}
    	
    	public Horse returnNameByNumber(String num){
    		boolean find = false;
    		int i = 0;
    		while(horses !=null && i <horses.size() && find == false){
    			if (horses.get(i).getNum().equalsIgnoreCase(num)){
    				find = true;
    			} else
    				i++;
    			
    		}
    		if (find == true)
    			return horses.get(i);
    		else System.out.println("Not found");
    		return null;
    		
    		
    	}
    	
    
    
    		private ArrayList<Horse>horses;
    		private static final File HORSE = new File("Horse.dati");
    }
    This is just a tester.

    Code:
    import java****.FileNotFoundException;
    
    
    public class Tester {
    
    	public static void main(String[] args) throws FileNotFoundException {
    		// TODO Auto-generated method stub
    
    		
    		Gestore gest = new Gestore();
    		gest.newHorse();
    		
    		
    	}
    
    }
    Don't forget to create the text file. Of course there are a lot of bug and error, i know

Similar Threads

  1. Can anyone help me with my coded hack?
    By prolife200 in forum Crossfire Coding Help & Discussion
    Replies: 8
    Last Post: 09-07-2015, 10:25 AM
  2. [Help Request] Can anyone help me with code something
    By muddiswag321 in forum Garry's Mod Discussions & Help
    Replies: 4
    Last Post: 07-20-2015, 12:43 AM
  3. Can anyone Help me? with Rotmg Hack Coding?
    By theone40 in forum Realm of the Mad God Help & Requests
    Replies: 4
    Last Post: 04-04-2014, 01:06 AM
  4. [Request] Can anyone help me with an extra bf3 account or extra code or a keygen ? please ?
    By Abed_Haddad in forum Battlefield 3 (BF3) Hacks & Cheats
    Replies: 4
    Last Post: 01-04-2013, 12:27 PM
  5. [Help Request] Can someone help me with this code
    By L33tHaxorCod3r in forum Minecraft Help
    Replies: 3
    Last Post: 07-16-2012, 11:48 AM