| |

VerySource

 Forgot password?
 Register
Search
View: 831|Reply: 7

Still not sure about the concept, fainted and want to commit suicide!

[Copy link]

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-15 21:00:01
| Show all posts |Read mode
A simple program that implements the function of checking and adding books, but the newly added books cannot be found. I know what the problem is, but I do n’t know how to do it. I hope you heroes ctrl + c can help and appreciate it .
import java.io. *;
import java.util. *;
class stock {
String name;

String author;

int price;
public stock () {}
Ranch
stock (String a, String b, int c) {
name = a;
author = b;
price = c;
}

void print () {
System.out.println ("name is" + name);
System.out.println ("author is" + author);
System.out.println ("price is" + price);
}
stock [] get () {
int N = 100;
stock [] a = new stock [N];
a [0] = new stock ("Java", "PlayGrrrr ...", 12);
a [1] = new stock ("C #", "Bill Gates", 13);
a [2] = new stock ("Delphi", "Boxer", 14);
a [3] = new stock ("Oracle", "zy", 15);
Ranch
return a;
}
}

class process {
void step1 () {
System.out.println ("do what?");
System.out.println ("a.search b.add c.exit");
char ch = 0;
try {
ch = (char) System.in.read ();
System.in.skip (2);
} catch (IOException z) {
}
if (ch == 'a') {
System.out.println ("a.by name b.by author");

char ch2 = 0;
try {
ch2 = (char) System.in.read ();
System.in.skip (2);
} catch (IOException z) {
}
if (ch2 == 'a') {
System.out.print ("plz input the book's name:");
InputDate fuck = new InputDate ();
fuck.findbookname ();
}

if (ch2 == 'b') {
System.out.print ("plz input the author's name:");
InputDate fuck2 = new InputDate ();
fuck2.findauthorname ();
}
}
if (ch == 'b') {
InputDate fuck3 = new InputDate ();
fuck3.add ();
}
if (ch == 'c') {
System.out.println ("c u");
}
}
}

class InputDate {
static private String s;

static public void input () {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
try {
s = br.readLine ();
} catch (IOException e) {
}

}

static public String getString () {
input ();
return s;

}

static public int getInt () {
input ();
return Integer.parseInt (s);
}

public void findbookname () {

stock mis = new stock ();
stock a [] = mis.get (); // Here we use the modified get method
s = InputDate.getString ();
Vector names = new Vector ();
for (int i = 0; i <a.length&&a [i + 1]! = null; i ++) {
names.add (a [i] .name);
}
if (names.indexOf (s)! = -1) {
System.out.println ("u can fint it here!");
} else
System.out.println ("sorry, there is not such a book!");

}

public void findauthorname () {
s = InputDate.getString ();
stock mis = new stock ();
stock a [] = mis.get ();

Ranch
Vector authornames = new Vector ();
for (int i = 0; i <a.length&&a [i + 1]! = null; i ++) {
authornames.add (a [i] .author);
}
if (authornames.indexOf (s)! = -1) {

System.out.println ("there is such a book!");
} else
System.out.println ("i didn't hear that pl at all!");

}

public void add () {
Ranch
System.out.println ("plz input info:");
String ab, b;
int c;
ab = InputDate.getString ();
b = InputDate.getString ();
c = InputDate.getInt ();
int i = 0;
stock mis = new stock ();
stock a [] = mis.get ();
Ranch
while (a [i]! = null)
i ++;
a [i] = new stock (ab, b, c);
System.out.println ("successfully added");
process a1 = new process ();
a1.step1 ();
}
}
public class main {
public static void main (String args []) {
process a1 = new process ();
a1.step1 ();
}
}
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-19 15:00:02
| Show all posts
Thank you all. . .
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-1-20 09:18:01
| Show all posts
Fixed
======================================================= ===============================
import java.io. *;
import java.util. *;
class stock {
static stock [] a = new stock [100];
static {
a [0] = new stock ("Java", "PlayGrrrr ...", 12);
a [1] = new stock ("C #", "Bill Gates", 13);
a [2] = new stock ("Delphi", "Boxer", 14);
a [3] = new stock ("Oracle", "zy", 15);
      
}

String name;

String author;

int price;
public stock () {}
Ranch
stock (String a, String b, int c) {
name = a;
author = b;
price = c;
}

void print () {
System.out.println ("name is" + name);
System.out.println ("author is" + author);
System.out.println ("price is" + price);
}
stock [] get () {
return a;
}
}

class process {
void step1 () {
System.out.println ("do what?");
System.out.println ("a.search b.add c.exit");
char ch = 0;
try {
ch = (char) System.in.read ();
System.in.skip (2);
} catch (IOException z) {
}
if (ch == 'a') {
System.out.println ("a.by name b.by author");

char ch2 = 0;
try {
ch2 = (char) System.in.read ();
System.in.skip (2);
} catch (IOException z) {
}
if (ch2 == 'a') {
System.out.print ("plz input the book's name:");
InputDate fuck = new InputDate ();
fuck.findbookname ();
}

if (ch2 == 'b') {
System.out.print ("plz input the author's name:");
InputDate fuck2 = new InputDate ();
fuck2.findauthorname ();
}
}
if (ch == 'b') {
InputDate fuck3 = new InputDate ();
fuck3.add ();
}
if (ch == 'c') {
System.out.println ("c u");
}
}
}

class InputDate {
static private String s;

static public void input () {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
try {
s = br.readLine ();
} catch (IOException e) {
}

}

static public String getString () {
input ();
return s;

}

static public int getInt () {
input ();
return Integer.parseInt (s);
}

public void findbookname () {

stock mis = new stock ();
stock a [] = mis.get (); // Here we use the modified get method
s = InputDate.getString ();
Vector names = new Vector ();
for (int i = 0; a [i]! = null&&i <a.length; i ++) {
names.add (a [i] .name);
}
if (names.indexOf (s)! = -1) {
System.out.println ("u can fint it here!");
} else
System.out.println ("sorry, there is not such a book!");

}

public void findauthorname () {
s = InputDate.getString ();
stock mis = new stock ();
stock a [] = mis.get ();

Ranch
Vector authornames = new Vector ();
for (int i = 0; a [i]! = null&&i <a.length; i ++) {
authornames.add (a [i] .author);
}
if (authornames.indexOf (s)! = -1) {

System.out.println ("there is such a book!");
} else
System.out.println ("i didn't hear that pl at all!");

}

public void add () {
Ranch
System.out.println ("plz input info:");
String ab, b;
int c;
ab = InputDate.getString ();
b = InputDate.getString ();
c = InputDate.getInt ();
int i = 0;
stock mis = new stock ();
stock a [] = mis.get ();
Ranch
while (a [i ++]! = null);
stock.a [i-1] = new stock (ab, b, c);
System.out.println ("successfully added");
process a1 = new process ();
a1.step1 ();
}
}
public class main {
public static void main (String args []) {
process a1 = new process ();
a1.step1 ();
}
}
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-20 14:00:01
| Show all posts
搂 When adding, just put the new stock object you added in your local variable stock a [].

It is not stored in the stock class.

You should add a class member that stores data in the stock class.

Upstairs should be very good
Reply

Use magic Report

1

Threads

51

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-1-20 20:36:01
| Show all posts
The spirit is commendable -.-
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-21 00:18:01
| Show all posts
Oh, good people will have good rewards, and I will not always be a rookie, I hope that the level will improve over the winter vacation. Thank you very kind people.
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-21 12:09:01
| Show all posts
The program is generally well written.

It's just that the structure may change a bit.

For example: book, bookself, and then encapsulate some search, add and other operations in the entity class. Or you write another operation control class ...
Then combine them in the Main class.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-21 19:09:02
| Show all posts
Encouraging ...
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list