股市项目。找到双星号开头和结尾的错误。试图修复我自己但无济于事。 我真的没有那么多的编程知识,所以我可能会遗漏一些关键符号,但我只是不知道他们要去哪里。
package Price;
import java.util.Scanner;
**public class Trade {**
public void StockMarket () {
Scanner keyboard = new Scanner(System.in);
double next = 0,
sum = 0;
}
public double openpricedow;
public double closepricedow;
public double currentpricedow;
public double lowpricedow;
public double openpricenas;
public double closepricenas;
public double currentpricenas;
public double lowpricenas;
public double openpricesp;
public double closepricesp;
public double currentpricesp;
public double lowpricesp;
String company, dow, nas, sp;
int NumberofShares = 0;
public void Trade()
{
System.out.println("Welcome to the Stock Market");
System.out.println("Please enter your stock company");
}
**public double findPrice();**
**findPrice();
company = keyboard.next();**
**Switch (company){**
**case "dow":**
System.out.println("Please enter your number of shares");
//Scanner keyboard = new Scanner (System.in);//
openpricedow = 11.50;
closepricedow = 18;
lowpricedow = 14.50;
currentpricedow = 12.50;
boolean areMore = true;
while (areMore = true) {
next = keyboard.nextInt();
if (next < 0) {
areMore = false;
} else {
sum = Numberofshares + next;
}
}
System.out.println(" You have bought " + sum + " shares at $ " + currentpricedow + " and your total is $ " + (sum * currentpricedow));
// if (Shares > 1000) {
// double returnedShares = (Shares * currentpricedow);
// System.out.println("You have bought " + Shares + " shares at $" + currentpricesp + " and your total is $" + returnedShares);
if (Shares < 1000) {
System.out.println("Your number of shares are insufficient");
}
case "sp":
System.out.println("Please enter your number of shares");
//Scanner keyboard = new Scanner (System.in);//
//Shares = keyboard.nextInt();
openpricesp = 13.50;
closepricesp = 16;
lowpricesp = 15.50;
currentpricesp = 8;
Shares = 0;
next = keyboard.nextDouble();
while (next > 0) {
sum = +sum + next;
Shares++;
next = keyboard.nextDouble();
}
if (next < 0) {
System.out.println(" You have bought " + sum + " shares at $ " + currentpricesp + " and your total is $ " + (sum * currentpricesp));
} // if (Shares > 1000) {
// double returnedShares = (Shares * currentpricesp);
// System.out.println("You have bought " + Shares + " shares at $" + currentpricesp + " and your total is $" + returnedShares);
else if (Shares < 1000) {
System.out.println("Your number of shares are insufficient");
}
case "nas":
System.out.println("Please enter your number of shares");
//Scanner keyboard = new Scanner (System.in);//
Shares = keyboard.nextInt();
openpricenas = 12.50;
closepricenas = 14;
lowpricenas = 17.50;
currentpricenas = 9.80;
if (closepricenas < lowpricenas) {
System.out.println("Your cannot buy shares at this moment");
} else {
Shares = 0;
next = keyboard.nextDouble();
while (next > 0) {
sum = sum + next;
Shares++;
next = keyboard.nextDouble();
}
if (next < 0) {
System.out.println(" You have bought " + sum + " shares at $ " + currentpricenas + " and your total is $ " + (sum * currentpricenas));
}
}
}
// if (Shares > 1000) {
// double returnedShares = (Shares * currentpricenas);
// System.out.println("You have bought " + Shares + " shares at $" + currentpricenas + " and your total is $" + returnedShares);}
**else if (Shares < 1000)
System.out.println("Your number of shares are insufficient");
return findPrice;}**
**}**
enter code here
public class Price {
public static void main (String [] args)
{Trade dow = new Trade(); //<=====buy is the object. stock is the class.
dow.openpricedow = 11.50;
dow.closepricedow = 18;
dow.currentpricedow = 14.50;
dow.lowpricedow = 12.50;
dow.Trade();
double result = dow.findPrice();
System.out.println("The higher Stock is " + result);
}
{Trade nas = new Trade(); //<=====buy is the object. stock is the class.
nas.openpricenas = 11.50;
nas.closepricenas = 18;
nas.currentpricenas = 14.50;
nas.lowpricenas = 12.50;
nas.Trade();
double result = nas.findPrice();
System.out.println("The higher Stock is " + result);
}
{Trade sp = new Trade(); //<=====buy is the object. stock is the class.
sp.openpricesp = 13.50;
sp.closepricesp = 16;
sp.currentpricesp = 15.50;
sp.lowpricesp = 8;
sp.Trade();
double result = sp.findPrice();
System.out.println("The higher Stock is " + result);
// }
}
}
答案 0 :(得分:0)
将此声明为全球。
Scanner keyboard = new Scanner(System.in);
语法不正确:
public double findPrice();
改变为:
public double findPrice(){
// your remain code..
}
在switch
案例中,您必须添加break
。如果没有保留的情况将执行..像这样..
switch(opt){
case "a":
// your remain code..
break;
case "b":
// your remain code..
break;
}