Git Product home page Git Product logo

java's People

Contributors

chowz avatar dependabot[bot] avatar helloworld521 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java's Issues

Java code

Hey guys

I have been trying to create an inheritance class where it extends on place but does not know how to go about.

Below is my PlaceApp class

package ass;
import java.util.*;
import java.util.Scanner;
public class PlaceApp {

public static void main (String [] args) {
	
	saywelcome(); 

	int num, i;

	Scanner sc = new Scanner (System.in);
	
	 // Display the menu
    System.out.println("1\t Enter a Place");
    System.out.println("2\t Display Places");
    System.out.println("3\t Quit");

    System.out.println("Please enter your choice:");
    
    //Get user's choice
    int choice = sc.nextInt();
     
    //Display the contents of the chosen option
    switch (choice) {
    
        case 1: 
        	
        	  System.out.println("Welcome!");
        	    System.out.println("\nEnter the number of places to be added: ");
        	    num = sc.nextInt();
        	    sc.nextLine();

        	    Place add[] = new Place[num];
        	    ArrayList<Place> address = new ArrayList<>(); 
        	    
        	   
        	    for(i = 0; i<add.length; i++)
        	    {
        	    	add[i] = new Place();
        	    	
        	        System.out.println("\nEnter Place Name: ");
        	        add[i].setplacename(sc.nextLine());
        	       
        	        System.out.println("Enter Street Name: ");
        	        add[i].setplacestreetname(sc.nextLine());
        	        System.out.println("Enter City: ");
        	        add[i].setcity(sc.nextLine());
        	        System.out.println("Enter Country: ");
        	        add[i].setcountry(sc.nextLine());

        	        address.add(new Place(add[i].getname(), add[i].getstreetname(), add[i].getcity(), add[i].getcountry()));
        	        System.out.println(address.get(0));


        	        System.out.println("\nYou have successfully added a new Place!");
        	    }

        	    for (i = 0; i < add.length; i++)
        	    {
        	        System.out.println("\nAddress " + (i+1) + " Information");
        	        System.out.println("===================================");
        	        
        	        add[i].toString();
        	        System.out.println("PLACE ADDED" +"\nName:"+ add[i].getname()+"\nStreet Name:"+ add[i].getstreetname()+"\nCity: "
    			    		+ add[i].getcity()+"\nCountry: "+ add[i].getcountry());
        	      
        	    }
        	    
        	    sc.close();
        	
		
		  
   break;
        case 2:  
        	
                break;
                
        case 3: System.exit(0); 
                break;
        
        default: System.out.println("Invalid choice");
    }//end of switch
	

}
public static void saywelcome( ) {
	System.out.println("Welcome Admin");
}

}

class placeGroup{
Place places[];
int classsize;
public placeGroup() {
classsize=0;
}
public placeGroup(int capacity) {
classsize = 0;
places = new Place[capacity];
}
public void enrol(String placename) {
places[classsize++] = new Place();
}

}

class museum extends Place {
String _type;
public museum(String placename, String placestreetname, String city, String country) {
super(placename, placestreetname, city, country);
_type = "Art";
}
public museum(String placename, String placestreetname, String city, String country, String type) {
super(placename, placestreetname, city, country);
_type = type;
}
public String getType() {
return _type;
}
@OverRide
public String toString() {
return super.toString() + ", Type = " + _type;
}
}

class restaurants extends Place {
String _food;
public restaurants(String placename, String placestreetname, String city, String country) {
super(placename, placestreetname, city, country);
_food = "French";
}
public restaurants(String placename, String placestreetname, String city, String country, String food) {
super(placename, placestreetname, city, country);
_food = food;
}
public String getFood() {
return _food;
}
@OverRide
public String toString() {
return super.toString() + ", Type of Food = " + _food;
}
}

Below is my place class

package ass;
import java.text.*;

public class Place {

 String name;
 String streetname;
 private String city;
 private String country;
 private static int placescount = 0; 
 
//Default constructor
 public Place ()
 {
     name = "Null";
     streetname = "Null";
     city = "Null";
     country = "Null";
     placescount = 0;
 }
 
//Parameterized Constructor
 public Place (String placename, String placestreetname, String city, String country) {
	 name = placename;
	 streetname = placestreetname;
	 this.setcity(city);
	 this.setcountry(country); 
	 placescount++;
	 System.out.println("Place Count: " + placescount);
 }
 
 //Getters
 public String getname ()
 {
     return name;
 }
 public String getstreetname ()
 {
     return streetname;
 }
 
 
//Setters
public void setplacename (String placename)
{
   name = placename;
}
public void setplacestreetname (String placestreetname)
{
   streetname = placestreetname;
}


 public int getplacescount() {
	 return placescount;
 }
		public void setcity(String city) {
			if (city.equals("chester") || city.equals("liverpool")) {
				this.city = city;
				
		} else {
			this.city = "NIL";
		}

		}
		
		public String getcity() {
			return city;
		} 
		
		public void setcountry(String country) {
			if (country.equals("United Kingdom") ) {
				this.country = country;
				
		} else {
			this.country = "NIL";
		}

		}
		
		public String getcountry() {
			return country;
		} 
		
		//To string method
		public String toString ()
		{
			
		    return "PLACE ADDED" +"\nName:"+ getname()+"\nStreet Name:"+ getstreetname()+"\nCity: "
		    		+ getcity()+"\nCountry: "+ getcountry();
		}
}

I want to make my museum and restaurant class inherit the place class, I have been trying to display my array also but to no avail

Opinion

I going to start to learn Java, some tips ?

Translate to English

--It is necessary to understand the files by everyone
--So, translation is useful.

thinking

我感觉你这个秒杀业务在高并发下会出现超卖的情况

Fix this pls

import java.util.Scanner;
interface Volume
{
double pi=3.14;
void readdata();
void dispvolume();
}
class Sphere implements Volume
{
double r=0,vol;
public void readdata()
{

Scanner input=new Scanner(System.in);
System.out.print("Enter the radius of the Sphere :");
r=input.nextDouble();

}
public void dispvolume()
{
vol=(4/33.14rrr);
System.out.println("Volume of Sphere : "+vol);
}
}
class Cylinder implements Volume
{
double R,h,vol;
public void readdata()
{
Scanner input=new Scanner(System.in);
System.out.print("Enter the radius of the Cylinder :");
R=input.nextDouble();
System.out.print("Enter the height of the Cylinder :");
h=input.nextDouble();
}
public void dispvolume()
{
vol=piRR*h;
System.out.println("Volume of the Cylinder: "+vol);

}
}
public class VolumeMain
{
public static void main(String args[])
{
Sphere obj=new Sphere();
obj.readdata();
obj.dispvolume();
Cylinder obj1=new Cylinder();
obj1.readdata();
obj1.dispvolume();
}
}

1

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;

public class MyGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture ballTexture;
    Vector2 ballPosition;
    Vector2 ballVelocity;

    @Override
    public void create() {
        batch = new SpriteBatch();
        ballTexture = new Texture("ball.png");
        ballPosition = new Vector2(100, 100);
        ballVelocity = new Vector2(3, 3);
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        
        updateBallPosition();
        
        batch.begin();
        batch.draw(ballTexture, ballPosition.x, ballPosition.y);
        batch.end();
    }
    
    private void updateBallPosition() {
        ballPosition.x += ballVelocity.x;
        ballPosition.y += ballVelocity.y;
        
        if (ballPosition.x < 0 || ballPosition.x > Gdx.graphics.getWidth() - ballTexture.getWidth()) {
            ballVelocity.x *= -1;
        }
        
        if (ballPosition.y < 0 || ballPosition.y > Gdx.graphics.getHeight() - ballTexture.getHeight()) {
            ballVelocity.y *= -1;
        }
    }
    
    @Override
    public void dispose() {
        batch.dispose();
        ballTexture.dispose();
    }
}

IMOOCSpider's issues

看了您的代码,我受益匪浅,如沐春风

在这里我也想给您反馈一个问题
  • 问题:
    您使用result字符串变量存储页面源码,问题在于您使用了定长字符串String类型,我也看了您爬取的页面,该页面有近一千行,此处用n代替,根据您的写法,那么您将浪费n-1个内存空间。注:不乏几千行的网页源码。
  • 解决方案:
    1、直接将定常字符串改为变长字符串,这样就避免了以上的内存浪费(但是:如果坚持用字符串存储,还存在一个问题,如果页面的数据足够多,那将超出字符串的容量上界);
    2、第二个方案就是,引进文件操作,使用本地文件作为页面源码的临时存取站,虽然麻烦了一些,但是更安全、保险。

略表拙见,不知所言

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.