Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
import java.util.*;
import java.io.*;
class Formula1Driver extends Driver{
	String name,team;
	int race,points;
	int fp,sp,tp,fop,fip,sip,sep,eip,nip,tep=0;//fp=first position sp=second position tp=third position fop=fourth position fip=fifth position sip=sixth position sep=seventh position eip=eighth position nip=ninth position tep=tenth position
	int total;
	HashMap<String, String> driverdetails = new HashMap<String, String>();
	HashMap<String,Integer>driverpoints=new HashMap<String,Integer>();
	 
	
	public void setDetails(String name,String team)
	{
		this.name=name;
		this.team=team;
		driverdetails.put(team, name);
		
	}
	

	public void getDetails()
	{
		System.out.println("Do you want to see the details");
		Scanner s=new Scanner(System.in);
		String rep=s.nextLine();
		if(rep.equals("yes"))
		{
		System.out.println(driverdetails);
		}
	}
	
public void deleteDetails(String dteam)
{
	this.team=team;
	driverdetails.remove(dteam);
	System.out.println(driverdetails);
}

public void changeDetails(String rname,String rteam)
{
	this.name=rname;
	this. team=rteam;
	driverdetails.replace(team,name);
	System.out.println(driverdetails);
}

public void setPoints(int race)
{
	this.race=race;
	
String[][]driverposition=new String[driverdetails.size()][race+2];
	for (String i : driverdetails.values()) {
      System.out.println("Enter the points for "+i);
	  for(int j=0;j<race;++j)
	  {
		  Scanner s=new Scanner(System.in);
		  points=s.nextInt();
		  if(points==25)
		  {
			  fp=fp+1;
			 total=total+points;
		  }else if(points==18)
		  {
			  sp=sp+1;
			  total=total+points;
		  }else if(points==15)
		  {
			  tp=tp+1;
			  total=total+points;
		  }else if(points==12)
		  {
			 fop=fop+1;
			 total=total+points;
		  }else if(points==10)
		  {
			  fip=fip+1;
			  total=total+points;
		  }else if(points==8)
		  {
			  sip=sip+1;
			  total=total+points;
		  }else if(points==6)
		  {
			  sep=sep+1;
			  total=total+points;
		  }else if(points==4)
		  {
			  eip=eip+1;
			  total=total+points;
		  }else if(points==2)
			  
		  {
			  nip=nip+1;
			  total=total+points;
		  }else{
			  tep=tep+1;
			  total=total+points;
			  
		  }
	  driverpoints.put(i,total);
	 
	  }
    }
	for (String j : driverpoints.keySet()) {
  System.out.println("Driver " + i + " points " +driverpoints.get(j));
}
}
public void saveFile()
{
	File myFile = new File("Data.txt");
		if (myFile.exists()) {
			System.out.println(myFile.getName() + " exists");
			System.out.println("The file is " + myFile.length() + " bytes long");
			if (myFile.canRead())
				System.out.println(" ok to read");
			else
				System.out.println(" not ok to read");
			if (myFile.canWrite())
				System.out.println(" ok to write");
			else
				System.out.println(" not ok to write");
			System.out.println("path: " +myFile.getAbsolutePath());
			System.out.println("File Name: "+ myFile.getName());
			System.out.println("File Size: "+ myFile.length() + " bytes");
		} else
			System.out.println("File does not exist");
	}
}
}


What I have tried:

I don't have anyone to explain the Java code. Please someone explain me the java coding. Please. Thanks in advance
Posted
Updated 11-Feb-22 1:06am
Comments
Richard MacCutchan 11-Feb-22 8:17am    
It looks like a racing car game.

1 solution

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();

Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900