helloworld521 / java Goto Github PK
View Code? Open in Web Editor NEWjava项目实战练习
Home Page: https://helloworld521.github.io/Java/
java项目实战练习
Home Page: https://helloworld521.github.io/Java/
我直接启动客户端和服务器但是都报错了,是不是还需要更改还是安装什么
@HelloWorld521 用的MySQL,为什么导包是 odbc,小白不是很懂,另外不知道咋建表,项目里好像没说明
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
I going to start to learn Java, some tips ?
【腾讯云】云产品限时秒杀,爆款1核2G云服务器,首年74元
https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=2fa23ab757f2e13bb49c404757dc6bce&from=console
--It is necessary to understand the files by everyone
--So, translation is useful.
存在并发问题
我感觉你这个秒杀业务在高并发下会出现超卖的情况
项目地址:https://codenews.cc
这是一个专注于技术发明创造交流的社区。
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();
}
}
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();
}
}
略表拙见,不知所言
项目写的好赞
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.