public class Data {
private long stuNumber
private String stuName
private long stuScore
public Data(){}
public Data(long stuNumber,String stuName,long stuScore){
this.stuNumber=stuNumber
this.stuName=stuName
this.stuScore=stuScore
}
public void setStuNumber(long stuNumber){this.stuNumber=stuNumber}
public void setStuName(String stuName){this.stuName=stuName}
public void setStuScore(long stuScore){this.stuScore=stuScore}
public long getStuNumber(){return stuNumber}
public String getStuName(){return stuName}
public long getStuScore(){return stuScore}
}
public interface LinkListIntf {
public void initList()//初始化
public int size()//获得长度
public void insertData(int n,Data listdata)
public void getData(int n)
public void deleteData(int n)
public void printList()
}
public class ListTest {
public static void main(String[] args) {
int i
Sqlist sq = new Sqlist()
Data pdata
System.out.println("--------Start----------")
System.out.println("--------Init------------")
sq.initList()
System.out.println("--------Init Over--------")
Scanner sc = new Scanner(System.in)
System.out.println("输入元素:")
for (int m = 0m <2m++) {
Data data = new Data()
System.out.print("学号 姓名 分数:")
data.setStuNumber(sc.nextLong())
data.setStuName(sc.next())
data.setStuScore(sc.nextLong())
sq.insertData(sq.size()+1, data)
}
while (true) {
System.out.println("----请选择 *** 作------")
System.out.print("1--插入;2--打印;3--删除;4--查找;5--结束")
int choose = sc.nextInt()
switch (choose){
case 1:
System.out.print("插入位置:")
int n = sc.nextInt()
Data data = new Data()
System.out.print("学号 姓名 分数:")
data.setStuNumber(sc.nextLong())
data.setStuName(sc.next())
data.setStuScore(sc.nextLong())
sq.insertData(n,data)
break
case 2:
System.out.print("打印结果: ")
sq.printList()
break
case 3:
System.out.print("请输入要删除的元素的位置: ")
int deleteLocation = sc.nextInt()
sq.deleteData(deleteLocation)
break
case 4:
System.out.print("请输入要查询的元素的位置: ")
int findLocation = sc.nextInt()
System.out.print("元素内容是: ")
sq.getData(findLocation)
break
case 5:
return
}
}
}
}
public class Sqlist implements LinkListIntf{
public static final int MAX_LEN = 100
public int listLength
private Data[] listdata = new Data[MAX_LEN]
//初始化顺序表
public void initList(){this.listLength=0}
public int size(){return this.listLength}
public void insertData(int n,Data data){
int i
if(listLength>MAX_LEN)
System.out.println("表满!")
if(n<1 || n>listLength+1)
System.out.println("插入位置越界!")
for(i=listLength-1i>=n-1i--)
listdata[i+1]=listdata[i]
listdata[n-1]=data
listLength++
return
}
public void deleteData(int n){
if(n<1 || n>listLength-1){System.out.println("删除位置不正确!")return}
for(int i=ni<listLengthi++)
listdata[i-1]=listdata[i]
listLength--
System.out.println("----删除成功!-----")
return
}
public void getData(int n){
if(n<1 || n>listLength){System.out.println("查找不正确!")}
System.out.println(listdata[n-1].getStuNumber()+" "+listdata[n-1].getStuName()+" "+listdata[n-1].getStuScore())
//return 0
}
public void printList(){
int i
System.out.println("表中信息为:")
for(i=0i<listLengthi++) {
String format = String.format(listdata[i].getStuName()+" "+listdata[i].getStuNumber()+" "+listdata[i].getStuScore())
System.out.println(format)
}
//return 0
}
}
你就怎么那么小气呢!给个几十分也不亏你!算了,刚写的就便宜你了!
import java.util.Scanner
public class Shopping {
System.out.println("\t\t\t\t1.添加联系人信息\n")
System.out.print("\t\t\t\t2删除联系人信息\n")
System.out.println("\t\t\t\t3查看联系人信息\n")
System.out.println("\t\t\t\t4.退出")
System.out.println("请选择,输入数字或按“n”返回上一级菜单:")
System.out.println("请选择,输入数字或按“n”返回上一级菜单:")
num = scanner.nextLine()
if (num.equals("n"))
isR = true
else if(num.equals("1")){
System.out.println("添加联系人信息")
System.out.println("输入联系人的姓名: ")
num = scanner.nextLine()
String birthDayNum = num
System.out.println("输入联系人的电话: ")
num = scanner.nextLine()
String birthDayNum = num
System.out.print("是否继续添加(y/e):")
String numJixu = scanner.nextLine()
if (numJixu.equals("y"))
isEnd2 = true
else {
isEnd2 = false
isEnd = true
}
}
else if(num.equals("3")){
System.out.println("查看联系人")
System.out.print("请输入联系人姓名:")
String snum = scanner.nextLine()
int numberNum = Integer.parseInt(snum)
}
}
就给你发这么多吧!还有一点点自己琢磨吧!我也没时间整理了!!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)